2016-03-18 11:12:50 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Node.js core.
|
2019-01-18 16:08:15 +01:00
|
|
|
const path = require('path');
|
2016-03-18 11:12:50 +01:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
const { green, cyan } = require('chalk');
|
2016-03-18 11:12:50 +01:00
|
|
|
const fs = require('fs-extra');
|
2018-06-22 15:25:15 +02:00
|
|
|
const ora = require('ora');
|
2019-04-30 16:15:12 +02:00
|
|
|
const execa = require('execa');
|
2016-03-18 11:12:50 +01:00
|
|
|
|
|
|
|
// Logger.
|
2019-01-28 15:50:13 +01:00
|
|
|
const trackSuccess = require('./success');
|
2016-03-18 11:12:50 +01:00
|
|
|
|
2019-04-30 16:15:12 +02:00
|
|
|
const installArguments = ['install', '--production', '--no-optional'];
|
2019-05-14 15:48:13 +02:00
|
|
|
const runInstall = ({ rootPath, hasYarn }) => {
|
|
|
|
if (hasYarn) {
|
|
|
|
return execa('yarnpkg', installArguments, { cwd: rootPath });
|
2019-04-05 16:11:09 +02:00
|
|
|
}
|
2019-05-14 15:48:13 +02:00
|
|
|
return execa('npm', installArguments, { cwd: rootPath });
|
2019-04-05 16:11:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = async (scope, cb) => {
|
2018-06-22 15:25:15 +02:00
|
|
|
console.log('🏗 Application generation:');
|
|
|
|
|
2019-04-30 16:15:12 +02:00
|
|
|
let loader = ora('Copying files ...').start();
|
2016-03-18 11:12:50 +01:00
|
|
|
|
|
|
|
// Copy the default files.
|
2019-04-05 16:11:09 +02:00
|
|
|
fs.copySync(
|
|
|
|
path.resolve(__dirname, '..', 'files'),
|
|
|
|
path.resolve(scope.rootPath)
|
|
|
|
);
|
2016-03-18 11:12:50 +01:00
|
|
|
|
2018-06-22 15:25:15 +02:00
|
|
|
loader.succeed();
|
|
|
|
|
2019-04-30 16:15:12 +02:00
|
|
|
loader.start('Installing dependencies ...');
|
2018-06-21 15:07:50 +02:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
try {
|
2019-05-14 15:48:13 +02:00
|
|
|
await runInstall(scope);
|
2019-04-05 16:11:09 +02:00
|
|
|
loader.succeed();
|
|
|
|
} catch (err) {
|
|
|
|
loader.fail();
|
|
|
|
trackSuccess('didNotInstallProjectDependencies', scope);
|
|
|
|
cb(err);
|
|
|
|
}
|
2018-06-21 15:07:50 +02:00
|
|
|
|
2019-04-30 16:15:12 +02:00
|
|
|
loader.start('Building your admin UI ...');
|
|
|
|
try {
|
|
|
|
await execa('npm', ['run', 'build'], {
|
|
|
|
cwd: scope.rootPath,
|
|
|
|
});
|
|
|
|
loader.succeed();
|
|
|
|
} catch (err) {
|
|
|
|
loader.fail();
|
|
|
|
trackSuccess('didNotBuildAdminUI', scope);
|
|
|
|
cb(err);
|
|
|
|
}
|
2018-06-21 15:07:50 +02:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
trackSuccess('didCreateProject', scope);
|
2019-02-08 18:13:40 +01:00
|
|
|
|
2019-04-30 16:15:12 +02:00
|
|
|
console.log();
|
|
|
|
console.log(`👌 Your application was created at ${cyan(scope.rootPath)}.\n`);
|
2019-04-30 14:47:49 +02:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
if (scope.quick) {
|
2019-04-17 11:24:22 +02:00
|
|
|
console.log('⚡️ Starting your application...');
|
2017-08-24 12:29:08 +02:00
|
|
|
} else {
|
2019-04-05 16:11:09 +02:00
|
|
|
console.log('⚡️ Change directory:');
|
|
|
|
console.log(`$ ${green(`cd ${scope.name}`)}`);
|
|
|
|
console.log();
|
2019-04-17 11:24:22 +02:00
|
|
|
console.log('⚡️ Start your application:');
|
2019-05-15 09:22:00 +02:00
|
|
|
console.log(`$ ${green('strapi develop')}`);
|
2017-08-24 12:29:08 +02:00
|
|
|
}
|
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
cb();
|
|
|
|
};
|