2016-03-18 11:12:50 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Node.js core.
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
// Public node modules.
|
2016-10-21 13:30:34 +02:00
|
|
|
const _ = require('lodash');
|
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');
|
2016-03-18 11:12:50 +01:00
|
|
|
|
|
|
|
// Logger.
|
|
|
|
const logger = require('strapi-utils').logger;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs after this generator has finished
|
|
|
|
*
|
|
|
|
* @param {Object} scope
|
|
|
|
* @param {Function} cb
|
|
|
|
*/
|
|
|
|
|
2016-07-11 13:03:35 +02:00
|
|
|
module.exports = (scope, cb) => {
|
2016-10-21 13:30:34 +02:00
|
|
|
const packageJSON = require(path.resolve(scope.rootPath, 'package.json'));
|
|
|
|
const strapiRootPath = path.resolve(scope.strapiRoot, '..');
|
|
|
|
|
2016-03-18 11:12:50 +01:00
|
|
|
process.chdir(scope.rootPath);
|
|
|
|
|
|
|
|
// Copy the default files.
|
|
|
|
fs.copySync(path.resolve(__dirname, '..', 'files'), path.resolve(scope.rootPath));
|
|
|
|
|
2016-10-21 13:30:34 +02:00
|
|
|
const missingDependencies = [];
|
2016-03-18 11:12:50 +01:00
|
|
|
|
2016-10-21 13:30:34 +02:00
|
|
|
// Verify if the dependencies are available into the global
|
2017-01-04 19:57:45 +01:00
|
|
|
_.forEach(_.merge(_.get(packageJSON, 'dependencies'), _.get(packageJSON, 'devDependencies')), (value, key) => {
|
2016-10-21 13:30:34 +02:00
|
|
|
try {
|
|
|
|
fs.accessSync(path.resolve(strapiRootPath, key), fs.constants.R_OK | fs.constants.W_OK);
|
|
|
|
fs.symlinkSync(path.resolve(strapiRootPath, key), path.resolve(scope.rootPath, 'node_modules', key), 'dir');
|
2016-12-02 12:56:39 +01:00
|
|
|
} catch (e1) {
|
|
|
|
try {
|
|
|
|
fs.accessSync(path.resolve(scope.strapiRoot, 'node_modules', key), fs.constants.R_OK | fs.constants.W_OK);
|
|
|
|
fs.symlinkSync(path.resolve(scope.strapiRoot, 'node_modules', key), path.resolve(scope.rootPath, 'node_modules', key), 'dir');
|
|
|
|
} catch (e2) {
|
|
|
|
missingDependencies.push(key);
|
|
|
|
}
|
2016-03-18 11:12:50 +01:00
|
|
|
}
|
|
|
|
});
|
2016-10-21 13:30:34 +02:00
|
|
|
|
|
|
|
if (!_.isEmpty(missingDependencies)) {
|
2017-08-05 20:25:57 +02:00
|
|
|
logger.info('Installing dependencies...');
|
2017-01-06 20:42:28 +01:00
|
|
|
|
|
|
|
npm.install({
|
|
|
|
dependencies: missingDependencies,
|
|
|
|
loglevel: 'silent',
|
|
|
|
'cache-min': 999999999
|
|
|
|
}, err => {
|
2017-01-04 19:57:45 +01:00
|
|
|
if (err) {
|
|
|
|
console.log();
|
|
|
|
logger.warn('You should run `npm install` into your application before starting it.');
|
|
|
|
console.log();
|
|
|
|
logger.warn('Some dependencies could not be installed:');
|
|
|
|
_.forEach(missingDependencies, value => logger.warn('• ' + value));
|
|
|
|
console.log();
|
|
|
|
|
|
|
|
return cb();
|
|
|
|
}
|
|
|
|
|
2017-01-06 20:42:28 +01:00
|
|
|
logger.info('Your new application `' + scope.name + '` is ready at `' + scope.rootPath + '`.');
|
2017-01-04 19:57:45 +01:00
|
|
|
|
2017-01-06 20:42:28 +01:00
|
|
|
cb();
|
2017-01-04 19:57:45 +01:00
|
|
|
});
|
|
|
|
}
|
2016-03-18 11:12:50 +01:00
|
|
|
};
|