mirror of
https://github.com/strapi/strapi.git
synced 2025-11-07 21:58:23 +00:00
Fix project création in dev mode
This commit is contained in:
parent
41ebaa36e8
commit
00f5af980e
@ -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) => {
|
||||
|
||||
@ -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': {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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,13 +10,17 @@ 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();
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
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) {
|
||||
@ -28,26 +32,33 @@ if (!skipCheck) {
|
||||
// Retrieve all the packages installed with NPM
|
||||
const data = watcher('npm -g ls');
|
||||
// Check if strapi is installed with NPM
|
||||
isStrapiInstalledWithNPM = includes(data, 'strapi');
|
||||
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
|
||||
isStrapiInstalledWithNPM = false;
|
||||
isNPM = false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isStrapiInstalledWithNPM,
|
||||
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 '';
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user