Fix project création in dev mode

This commit is contained in:
cyril lopez 2018-06-22 16:46:48 +02:00
parent 41ebaa36e8
commit 00f5af980e
6 changed files with 48 additions and 33 deletions

View File

@ -25,7 +25,7 @@ module.exports = (scope, cb) => {
}
// Install back-end admin `node_modules`.
const cmd = packageManager.isStrapiInstalledWithNPM ? 'npm install --production --ignore-scripts' : 'yarn install --production --ignore-scripts';
const cmd = packageManager.isStrapiInstalledWithNPM() ? 'npm install --production --ignore-scripts' : 'yarn install --production --ignore-scripts';
exec(cmd, {
cwd: path.resolve(scope.rootPath, 'admin')
}, (err) => {

View File

@ -7,6 +7,7 @@
// Public node modules.
const _ = require('lodash');
const uuid = require('uuid/v4');
const { packageManager } = require('strapi-utils');
/**
* Expose main package JSON of the application
@ -15,6 +16,8 @@ const uuid = require('uuid/v4');
module.exports = scope => {
const cliPkg = scope.strapiPackageJSON || {};
// Store the package manager info into the package.json
const pckManager = packageManager.isStrapiInstalledWithNPM() ? 'npm' : 'yarn';
// Let us install additional dependencies on a specific version.
// Ex: it allows us to install the right version of knex.
@ -68,6 +71,7 @@ module.exports = scope => {
'url': scope.website || ''
}],
'strapi': {
'packageManager': pckManager,
'uuid': uuid()
},
'engines': {

View File

@ -39,8 +39,9 @@ module.exports = (scope, cb) => {
const dependencies = _.get(packageJSON, 'dependencies');
const strapiDependencies = Object.keys(dependencies).filter(key => key.indexOf('strapi') !== -1);
const othersDependencies = Object.keys(dependencies).filter(key => key.indexOf('strapi') === -1);
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM;
const globalRootPath = execSync(packageManager.commands('root -g'));
// Add this check to know if we are in development mode so the creation is faster.
const isStrapiInstalledWithNPM = process.argv.indexOf('new') !== -1 && process.argv.indexOf('--dev') !== -1 || packageManager.isStrapiInstalledWithNPM();
const globalRootPath = isStrapiInstalledWithNPM ? execSync('npm root -g') : execSync(packageManager.commands('root -g'));
// const globalRootPath = execSync('npm root -g');
// Verify if the dependencies are available into the global

View File

@ -214,8 +214,8 @@ module.exports = (scope, cb) => {
});
}),
new Promise(resolve => {
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM;
let packageCmd = packageManager.commands('install --prefix', scope.tmpPath);
const isStrapiInstalledWithNPM = process.argv.indexOf('new') !== -1 && process.argv.indexOf('--dev') !== -1 || packageManager.isStrapiInstalledWithNPM();
let packageCmd = isStrapiInstalledWithNPM ? `npm install --prefix "${scope.tmpPath}" ${scope.client.connector}@alpha` : packageManager.commands('install --prefix', scope.tmpPath);
// let cmd = `npm install --prefix "${scope.tmpPath}" ${scope.client.connector}@alpha`;
// Manually create the temp directory for yarn
if (!isStrapiInstalledWithNPM) {

View File

@ -1,8 +1,8 @@
const shell = require('shelljs');
const { includes } = require('lodash');
let isStrapiInstalledWithNPM;
let skipCheck = false;
// let isStrapiInstalledWithNPM = true;
// let skipCheck = false;
const watcher = (cmd) => {
const data = shell.exec(cmd, {
@ -10,44 +10,55 @@ const watcher = (cmd) => {
});
if (includes(data.stderr, 'command not found') && data.code !== 0) {
console.log('ERRRRR');
throw new Error('Command not found');
}
return data.stdout.toString();
};
// Check if we are in development mode (working with the monorepo)
// So we don't run `npm -g ls` which takes time
if (process.argv.indexOf('new') !== -1 && process.argv.indexOf('--dev') !== -1) {
skipCheck = true;
}
if (!skipCheck) {
try {
// Retrieve all the packages installed with NPM
const data = watcher('npm -g ls');
// Check if strapi is installed with NPM
isStrapiInstalledWithNPM = includes(data, 'strapi');
} catch(err) {
// If NPM is not installed strapi is installed with Yarn
isStrapiInstalledWithNPM = false;
}
}
module.exports = {
isStrapiInstalledWithNPM,
isStrapiInstalledWithNPM: () => {
let isNPM = true;
let skipCheck = false;
// Check if we are in development mode (working with the monorepo)
// So we don't run `npm -g ls` which takes time
if (process.argv.indexOf('new') !== -1 && process.argv.indexOf('--dev') !== -1) {
skipCheck = true;
}
if (!skipCheck) {
try {
// Retrieve all the packages installed with NPM
const data = watcher('npm -g ls');
// Check if strapi is installed with NPM
isNPM = includes(data, 'strapi');
try {
const yarnData = watcher('yarn global -ls');
isNPM = includes(yarnData, 'strapi');
} catch(err) {
isNPM = true;
}
} catch(err) {
// If NPM is not installed strapi is installed with Yarn
isNPM = false;
}
}
return isNPM;
},
commands: (cmdType, path = '') => {
const isNPM = module.isStrapiInstalledWithNPM();
switch(cmdType) {
case 'install --prefix':
return isStrapiInstalledWithNPM ? `npm install --prefix ${path}` : `yarn --cwd ${path} add`;
return isNPM ? `npm install --prefix ${path}` : `yarn --cwd ${path} add`;
case 'root -g':
return isStrapiInstalledWithNPM ? 'npm root -g' : 'yarn global dir';
return isNPM ? 'npm root -g' : 'yarn global dir';
case 'install global':
return isStrapiInstalledWithNPM ? 'npm install' : 'yarn install';
return isNPM ? 'npm install' : 'yarn install';
case 'install package':
return isStrapiInstalledWithNPM ? 'npm install' : 'yarn add';
return isNPM ? 'npm install' : 'yarn add';
default:
return '';
}

View File

@ -49,7 +49,6 @@ module.exports = function (plugin, cliArguments) {
process.exit(0);
} catch (e) {
logger.error('An error occurred during plugin installation.');
console.log('ERROR PLUGINS INSTALL', e);
process.exit(1);
}
} else {
@ -57,7 +56,7 @@ module.exports = function (plugin, cliArguments) {
logger.debug('Installing the plugin from npm registry.');
// Install the plugin from the npm registry.
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM;
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM();
if (!isStrapiInstalledWithNPM) {
// Create the directory yarn doesn't do it it