2020-05-27 20:47:53 +03:00
|
|
|
const config = require('./core/shared/config');
|
2019-02-11 15:26:06 +03:00
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
// Utility for outputting messages indicating that the admin is building, as it can take a while.
|
2022-05-17 11:05:44 +03:00
|
|
|
let hasBuiltAdmin = false;
|
|
|
|
const logBuildingAdmin = function (grunt) {
|
|
|
|
if (!hasBuiltAdmin) {
|
|
|
|
grunt.log.writeln('Building admin app... (can take ~1min)');
|
|
|
|
setTimeout(logBuildingAdmin, 5000, grunt);
|
2019-02-11 15:26:06 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
module.exports = function (grunt) {
|
|
|
|
// grunt dev - use yarn dev instead!
|
|
|
|
// - Start a server & build assets on the fly whilst developing
|
|
|
|
grunt.registerTask('dev', 'Dev Mode; watch files and restart server on changes', function () {
|
2022-05-17 11:05:44 +03:00
|
|
|
if (grunt.option('admin')) {
|
|
|
|
grunt.task.run(['clean:built', 'bgShell:admin']);
|
2021-07-05 22:02:22 +03:00
|
|
|
} else if (grunt.option('server')) {
|
|
|
|
grunt.task.run(['express:dev', 'watch']);
|
|
|
|
} else {
|
2022-05-17 11:05:44 +03:00
|
|
|
grunt.task.run(['clean:built', 'bgShell:admin', 'express:dev', 'watch']);
|
2021-07-05 22:02:22 +03:00
|
|
|
}
|
|
|
|
});
|
2019-02-11 15:26:06 +03:00
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
// grunt build -- use yarn build instead!
|
2022-05-17 11:05:44 +03:00
|
|
|
// - Builds the admin without a watch task
|
|
|
|
grunt.registerTask('build', 'Build admin app in development mode',
|
2022-08-03 18:05:57 +03:00
|
|
|
['clean:tmp', 'ember']);
|
2020-08-07 21:19:25 +03:00
|
|
|
|
2022-07-19 09:22:49 +03:00
|
|
|
// Runs the asset generation tasks for production and duplicates default-prod.html to default.html
|
2022-08-02 22:14:04 +03:00
|
|
|
grunt.registerTask('release', 'Release task - creates a final built zip', ['clean:built', 'prod']);
|
2022-07-19 09:22:49 +03:00
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
// --- Sub Commands
|
|
|
|
// Used to make other commands work
|
|
|
|
|
2022-05-17 11:05:44 +03:00
|
|
|
// Updates submodules, then installs and builds the admin for you
|
2022-08-03 18:05:57 +03:00
|
|
|
grunt.registerTask('init', 'Prepare the project for development', 'build');
|
2021-07-05 22:02:22 +03:00
|
|
|
|
|
|
|
// Runs ember dev
|
|
|
|
grunt.registerTask('ember', 'Build JS & templates for development',
|
|
|
|
['subgrunt:dev']);
|
|
|
|
|
|
|
|
// Production asset build
|
2022-08-02 21:23:24 +03:00
|
|
|
grunt.registerTask('prod', 'Build JS & templates for production', 'subgrunt:prod');
|
2020-08-07 21:19:25 +03:00
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
// --- Configuration
|
2020-04-29 18:44:27 +03:00
|
|
|
const cfg = {
|
2021-07-05 22:02:22 +03:00
|
|
|
// grunt-contrib-watch
|
2019-02-11 15:26:06 +03:00
|
|
|
// Watch files and livereload in the browser during development.
|
2021-07-05 22:02:22 +03:00
|
|
|
// See the grunt dev task for how this is used.
|
2019-02-11 15:26:06 +03:00
|
|
|
watch: grunt.option('no-server-watch') ? {files: []} : {
|
|
|
|
livereload: {
|
|
|
|
files: [
|
|
|
|
'content/themes/casper/assets/css/*.css',
|
|
|
|
'content/themes/casper/assets/js/*.js'
|
|
|
|
],
|
|
|
|
options: {
|
2019-04-01 13:59:48 +03:00
|
|
|
livereload: true,
|
|
|
|
interval: 500
|
2013-08-17 22:39:02 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
express: {
|
2019-02-11 15:26:06 +03:00
|
|
|
files: [
|
|
|
|
'core/server/**/*.js',
|
2020-04-25 22:53:58 +03:00
|
|
|
'core/shared/**/*.js',
|
2019-07-18 17:31:04 +03:00
|
|
|
'core/frontend/**/*.js',
|
2021-11-09 14:07:28 +03:00
|
|
|
'core/frontend/src/**/*.css',
|
2021-05-04 18:46:57 +03:00
|
|
|
'core/*.js',
|
2020-05-01 19:59:38 +03:00
|
|
|
'index.js',
|
2019-02-11 15:26:06 +03:00
|
|
|
'config.*.json',
|
|
|
|
'!config.testing.json'
|
|
|
|
],
|
|
|
|
tasks: ['express:dev'],
|
2013-08-17 22:39:02 +04:00
|
|
|
options: {
|
2019-02-11 15:26:06 +03:00
|
|
|
spawn: false,
|
2019-04-01 13:59:48 +03:00
|
|
|
livereload: true,
|
|
|
|
interval: 500
|
2013-08-17 22:39:02 +04:00
|
|
|
}
|
2019-02-11 15:26:06 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
// grunt-express-server
|
2019-02-11 15:26:06 +03:00
|
|
|
// Start a Ghost express server for use in development and testing
|
|
|
|
express: {
|
|
|
|
dev: {
|
2013-06-25 15:43:15 +04:00
|
|
|
options: {
|
2021-07-05 22:02:22 +03:00
|
|
|
script: 'index.js',
|
|
|
|
output: 'Ghost is running'
|
2015-04-18 15:20:03 +03:00
|
|
|
}
|
2019-02-11 15:26:06 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
// grunt-bg-shell
|
2022-05-17 11:05:44 +03:00
|
|
|
// Tools for building the admin
|
2019-02-11 15:26:06 +03:00
|
|
|
bgShell: {
|
2022-05-17 11:05:44 +03:00
|
|
|
admin: {
|
2019-02-11 15:26:06 +03:00
|
|
|
cmd: function () {
|
2022-05-17 11:05:44 +03:00
|
|
|
logBuildingAdmin(grunt);
|
2019-02-11 15:26:06 +03:00
|
|
|
return 'grunt subgrunt:watch';
|
|
|
|
},
|
2022-05-17 11:05:44 +03:00
|
|
|
bg: grunt.option('admin') ? false : true,
|
2019-02-11 15:26:06 +03:00
|
|
|
stdout: function (chunk) {
|
|
|
|
// hide certain output to prevent confusion when running alongside server
|
2022-05-17 11:05:44 +03:00
|
|
|
const filter = grunt.option('admin') ? false : [
|
2019-02-11 15:26:06 +03:00
|
|
|
/> ghost-admin/,
|
|
|
|
/^Livereload/,
|
|
|
|
/^Serving on/
|
|
|
|
].some(function (regexp) {
|
|
|
|
return regexp.test(chunk);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!filter) {
|
|
|
|
grunt.log.write(chunk);
|
2014-05-27 18:37:44 +04:00
|
|
|
}
|
2015-12-10 17:46:58 +03:00
|
|
|
|
2019-04-04 11:47:54 +03:00
|
|
|
if (chunk.indexOf('Slowest Nodes') !== -1) {
|
2022-05-17 11:05:44 +03:00
|
|
|
hasBuiltAdmin = true;
|
2015-12-10 17:46:58 +03:00
|
|
|
}
|
2019-02-11 15:26:06 +03:00
|
|
|
},
|
|
|
|
stderr: function (chunk) {
|
2022-05-17 11:05:44 +03:00
|
|
|
const skipFilter = grunt.option('admin') ? false : [
|
2020-01-20 12:42:50 +03:00
|
|
|
/- building/
|
|
|
|
].some(function (regexp) {
|
|
|
|
return regexp.test(chunk);
|
|
|
|
});
|
|
|
|
|
2022-05-17 11:05:44 +03:00
|
|
|
const errorFilter = grunt.option('admin') ? false : [
|
2020-01-20 12:42:50 +03:00
|
|
|
/^>>/
|
|
|
|
].some(function (regexp) {
|
|
|
|
return regexp.test(chunk);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!skipFilter) {
|
2022-05-17 11:05:44 +03:00
|
|
|
hasBuiltAdmin = errorFilter ? hasBuiltAdmin : true;
|
2020-01-20 12:42:50 +03:00
|
|
|
grunt.log.error(chunk);
|
|
|
|
}
|
2015-12-10 17:46:58 +03:00
|
|
|
}
|
2019-02-11 15:26:06 +03:00
|
|
|
}
|
|
|
|
},
|
2016-05-31 16:40:20 +03:00
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
// grunt-contrib-clean
|
2019-02-11 15:26:06 +03:00
|
|
|
// Clean up files as part of other tasks
|
|
|
|
clean: {
|
|
|
|
built: {
|
|
|
|
src: [
|
|
|
|
'core/built/**'
|
|
|
|
]
|
2017-04-10 12:30:21 +03:00
|
|
|
},
|
2019-02-11 15:26:06 +03:00
|
|
|
tmp: {
|
|
|
|
src: ['.tmp/**']
|
|
|
|
}
|
|
|
|
},
|
2017-04-10 12:30:21 +03:00
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
// grunt-subgrunt
|
2019-02-11 15:26:06 +03:00
|
|
|
// Run grunt tasks in submodule Gruntfiles
|
|
|
|
subgrunt: {
|
|
|
|
options: {
|
|
|
|
npmInstall: false,
|
|
|
|
npmPath: 'yarn'
|
2017-04-13 10:26:48 +03:00
|
|
|
},
|
|
|
|
|
2019-02-11 15:26:06 +03:00
|
|
|
dev: {
|
2022-08-03 16:59:51 +03:00
|
|
|
'../admin': 'shell:ember:dev'
|
2019-02-11 15:26:06 +03:00
|
|
|
},
|
2013-06-25 15:43:15 +04:00
|
|
|
|
2019-02-11 15:26:06 +03:00
|
|
|
prod: {
|
2022-08-03 16:59:51 +03:00
|
|
|
'../admin': 'shell:ember:prod'
|
2019-02-11 15:26:06 +03:00
|
|
|
},
|
2013-08-01 11:12:59 +04:00
|
|
|
|
2019-02-11 15:26:06 +03:00
|
|
|
watch: {
|
|
|
|
projects: {
|
2022-08-03 16:59:51 +03:00
|
|
|
'../admin': ['shell:ember:watch', '--live-reload-base-url="' + config.getSubdir() + '/ghost/"']
|
2015-05-28 18:16:09 +03:00
|
|
|
}
|
2019-02-11 15:26:06 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
// grunt-contrib-symlink
|
2019-02-11 15:26:06 +03:00
|
|
|
// Create symlink for git hooks
|
|
|
|
symlink: {
|
|
|
|
githooks: {
|
|
|
|
// Enable overwrite to delete symlinks before recreating them
|
|
|
|
overwrite: false,
|
|
|
|
// Enable force to overwrite symlinks outside the current working directory
|
|
|
|
force: false,
|
|
|
|
// Expand to all files in /hooks
|
|
|
|
expand: true,
|
|
|
|
cwd: '.github/hooks',
|
|
|
|
src: ['*'],
|
|
|
|
dest: '.git/hooks'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-05-28 18:16:09 +03:00
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
// --- Grunt Initialisation
|
2019-02-11 15:26:06 +03:00
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
// Load all grunt tasks
|
|
|
|
grunt.loadNpmTasks('grunt-bg-shell');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-clean');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-symlink');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
|
|
|
grunt.loadNpmTasks('grunt-express-server');
|
|
|
|
grunt.loadNpmTasks('grunt-subgrunt');
|
2019-02-11 15:26:06 +03:00
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
// This little bit of weirdness gives the express server chance to shutdown properly
|
|
|
|
const waitBeforeExit = () => {
|
|
|
|
setTimeout(() => {
|
|
|
|
process.exit(0);
|
|
|
|
}, 1000);
|
|
|
|
};
|
2019-02-11 15:26:06 +03:00
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
process.on('SIGINT', waitBeforeExit);
|
|
|
|
process.on('SIGTERM', waitBeforeExit);
|
2019-02-11 15:26:06 +03:00
|
|
|
|
2021-07-05 22:02:22 +03:00
|
|
|
// Load the configuration
|
|
|
|
grunt.initConfig(cfg);
|
2019-02-11 15:26:06 +03:00
|
|
|
};
|