strapi/packages/strapi/bin/strapi-new.js

55 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-03-18 11:12:50 +01:00
#!/usr/bin/env node
'use strict';
/**
* Module dependencies
*/
// Node.js core.
const path = require('path');
// Master of ceremonies for generators.
const generate = require('strapi-generate');
// Local Strapi dependencies.
const packageJSON = require('../package.json');
// Logger.
const logger = require('strapi-utils').logger;
/**
* `$ strapi new`
*
* Generate a new Strapi application.
*/
module.exports = function () {
logger.info('Creating your application... It might take a few seconds.');
2016-03-18 11:12:50 +01:00
2016-03-25 22:22:34 +01:00
// Pass the original CLI arguments down to the generator
// (but first, remove commander's extra argument).
2016-03-18 11:12:50 +01:00
const cliArguments = Array.prototype.slice.call(arguments);
2016-03-25 22:22:34 +01:00
cliArguments.pop();
2016-03-18 11:12:50 +01:00
// Build initial scope.
const scope = {
rootPath: process.cwd(),
strapiRoot: path.resolve(__dirname, '..'),
generatorType: 'new',
2016-03-25 22:22:34 +01:00
name: cliArguments[0],
2016-03-18 11:12:50 +01:00
strapiPackageJSON: packageJSON
};
// Return the scope and the response (`error` or `success`).
return generate(scope, {
// Log and exit the REPL in case there is an error
// while we were trying to generate the new app.
error: function returnError(err) {
logger.error(err);
process.exit(1);
}
});
};