95 lines
2.0 KiB
JavaScript
Raw Normal View History

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');
2018-06-21 15:07:50 +02:00
const shell = require('shelljs');
2016-03-18 11:12:50 +01:00
// Logger.
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(
2019-04-30 14:47:49 +02:00
'npm install --production --no-optional',
2019-04-05 16:11:09 +02:00
{ 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(
2019-04-30 14:47:49 +02:00
'yarn install --production --no-optional',
2019-04-05 16:11:09 +02:00
{ 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:');
2019-04-17 11:24:22 +02:00
let loader = ora('Copying files').start();
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(
2019-04-17 11:24:22 +02:00
`\n👌 Your application was created at ${cyan(scope.rootPath)}.\n`
2019-04-05 16:11:09 +02:00
);
2018-06-21 15:07:50 +02:00
2019-04-05 16:11:09 +02:00
trackSuccess('didCreateProject', scope);
2019-04-30 14:47:49 +02:00
loader.start('Building the admin UI');
shell.exec('npm run build');
loader.succeed();
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-04-05 16:11:09 +02:00
console.log(`$ ${green('strapi start')}`);
2017-08-24 12:29:08 +02:00
}
2019-04-05 16:11:09 +02:00
cb();
};