mirror of
https://github.com/strapi/strapi.git
synced 2025-10-21 04:51:33 +00:00
89 lines
1.9 KiB
JavaScript
89 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Module dependencies
|
|
*/
|
|
|
|
// Node.js core.
|
|
const path = require('path');
|
|
|
|
const { green, cyan } = require('chalk');
|
|
const fs = require('fs-extra');
|
|
const ora = require('ora');
|
|
const shell = require('shelljs');
|
|
|
|
// Logger.
|
|
const { packageManager } = require('strapi-utils');
|
|
const trackSuccess = require('./success');
|
|
|
|
const runInstall = () => {
|
|
if (packageManager.isStrapiInstalledWithNPM()) {
|
|
return new Promise((resolve, reject) => {
|
|
shell.exec(
|
|
'npm install',
|
|
{ silent: true },
|
|
(code, _, stderr) => {
|
|
if (stderr && code !== 0) return reject(new Error(stderr));
|
|
return resolve();
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
shell.exec(
|
|
'yarn install',
|
|
{ silent: true },
|
|
(code, _, stderr) => {
|
|
if (stderr && code !== 0) return reject(new Error(stderr));
|
|
return resolve();
|
|
}
|
|
);
|
|
});
|
|
};
|
|
|
|
module.exports = async (scope, cb) => {
|
|
console.log('🏗 Application generation:');
|
|
|
|
let loader = ora('Copying files').start();
|
|
|
|
process.chdir(scope.rootPath);
|
|
|
|
// Copy the default files.
|
|
fs.copySync(
|
|
path.resolve(__dirname, '..', 'files'),
|
|
path.resolve(scope.rootPath)
|
|
);
|
|
|
|
loader.succeed();
|
|
|
|
loader.start('Installing dependencies');
|
|
|
|
try {
|
|
await runInstall();
|
|
loader.succeed();
|
|
} catch (err) {
|
|
loader.fail();
|
|
trackSuccess('didNotInstallProjectDependencies', scope);
|
|
cb(err);
|
|
}
|
|
|
|
console.log(
|
|
`\n👌 Your application was created at ${cyan(scope.rootPath)}.\n`
|
|
);
|
|
|
|
trackSuccess('didCreateProject', scope);
|
|
|
|
if (scope.quick) {
|
|
console.log('⚡️ Starting your application...');
|
|
} else {
|
|
console.log('⚡️ Change directory:');
|
|
console.log(`$ ${green(`cd ${scope.name}`)}`);
|
|
console.log();
|
|
console.log('⚡️ Start your application:');
|
|
console.log(`$ ${green('strapi start')}`);
|
|
}
|
|
|
|
cb();
|
|
};
|