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
|
|
|
|
|
|
|
// Public node modules.
|
2016-10-21 13:30:34 +02:00
|
|
|
const _ = require('lodash');
|
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');
|
2017-01-06 20:42:28 +01:00
|
|
|
const npm = require('enpeem');
|
2018-06-22 15:25:15 +02:00
|
|
|
const ora = require('ora');
|
2018-06-21 15:07:50 +02:00
|
|
|
const shell = require('shelljs');
|
2016-03-18 11:12:50 +01:00
|
|
|
|
|
|
|
// Logger.
|
2018-07-08 10:57:51 +02:00
|
|
|
const { packageManager } = require('strapi-utils');
|
2019-01-28 15:50:13 +01:00
|
|
|
const trackSuccess = require('./success');
|
2016-03-18 11:12:50 +01:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
const runInstall = () => {
|
|
|
|
if (packageManager.isStrapiInstalledWithNPM()) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
shell.exec(
|
|
|
|
'npm install --production',
|
|
|
|
{ silent: true },
|
|
|
|
(code, _, stderr) => {
|
|
|
|
if (stderr && code !== 0) return reject(new Error(stderr));
|
|
|
|
return resolve();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2016-03-18 11:12:50 +01:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
shell.exec(
|
|
|
|
'yarn install --production',
|
|
|
|
{ silent: true },
|
|
|
|
(code, _, stderr) => {
|
|
|
|
if (stderr && code !== 0) return reject(new Error(stderr));
|
|
|
|
return resolve();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = async (scope, cb) => {
|
2018-06-22 15:25:15 +02:00
|
|
|
console.log('🏗 Application generation:');
|
|
|
|
|
|
|
|
let loader = ora('Copy dashboard').start();
|
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
// const packageJSON = require(path.resolve(scope.rootPath, 'package.json'));
|
2018-05-04 17:50:39 +02:00
|
|
|
// const strapiRootPath = path.resolve(scope.strapiRoot, '..');
|
2016-10-21 13:30:34 +02:00
|
|
|
|
2016-03-18 11:12:50 +01:00
|
|
|
process.chdir(scope.rootPath);
|
|
|
|
|
|
|
|
// 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-16 18:05:12 +02:00
|
|
|
loader.start('Installing dependencies');
|
2018-06-21 15:07:50 +02:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
try {
|
|
|
|
await runInstall();
|
|
|
|
loader.succeed();
|
|
|
|
} catch (err) {
|
|
|
|
loader.fail();
|
|
|
|
trackSuccess('didNotInstallProjectDependencies', scope);
|
|
|
|
cb(err);
|
|
|
|
}
|
2018-06-21 15:07:50 +02:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
console.log();
|
|
|
|
console.log(
|
|
|
|
`👌 Your new application ${green(scope.name)} is ready at ${cyan(
|
|
|
|
scope.rootPath
|
|
|
|
)}.`
|
|
|
|
);
|
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-05 16:11:09 +02:00
|
|
|
if (scope.quick) {
|
|
|
|
console.log();
|
|
|
|
console.log('⚡️ Starting your application:');
|
|
|
|
console.log(`${green('strapi start')}`);
|
2017-08-24 12:29:08 +02:00
|
|
|
} else {
|
2019-04-05 16:11:09 +02:00
|
|
|
console.log();
|
|
|
|
console.log('⚡️ Change directory:');
|
|
|
|
console.log(`$ ${green(`cd ${scope.name}`)}`);
|
|
|
|
console.log();
|
|
|
|
console.log('⚡️ Start application:');
|
|
|
|
console.log(`$ ${green('strapi start')}`);
|
2017-08-24 12:29:08 +02:00
|
|
|
}
|
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
cb();
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
};
|