2017-06-08 17:16:20 +01:00

53 lines
1.2 KiB
JavaScript
Executable File

'use strict';
/**
* Module dependencies
*/
// Node.js core.
const path = require('path');
// Public node modules.
const _ = require('lodash');
const fs = require('fs-extra');
// Logger.
const logger = require('strapi-utils').logger;
/**
* This `before` function is run before generating targets.
* Validate, configure defaults, get extra dependencies, etc.
*
* @param {Object} scope
* @param {Function} cb
*/
module.exports = (scope, cb) => {
// App info.
_.defaults(scope, {
name: scope.name === '.' || !scope.name ? scope.name : path.basename(process.cwd()),
author: process.env.USER || 'A Strapi developer',
email: process.env.EMAIL || '',
year: (new Date()).getFullYear(),
license: 'MIT'
});
// Make changes to the rootPath where the Strapi project will be created.
scope.rootPath = path.resolve(process.cwd(), scope.name || '');
// Ensure we aren't going to inadvertently delete any files.
try {
const files = fs.readdirSync(scope.rootPath);
if (files.length) {
return logger.error('`$ strapi new` can only be called in an empty directory.');
}
} catch (err) {
// ...
}
logger.verbose('Copying the dashboard...');
// Trigger callback with no error to proceed.
return cb.success();
};