mirror of
https://github.com/strapi/strapi.git
synced 2025-11-08 22:32:02 +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`.
|
// 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, {
|
exec(cmd, {
|
||||||
cwd: path.resolve(scope.rootPath, 'admin')
|
cwd: path.resolve(scope.rootPath, 'admin')
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const uuid = require('uuid/v4');
|
const uuid = require('uuid/v4');
|
||||||
|
const { packageManager } = require('strapi-utils');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expose main package JSON of the application
|
* Expose main package JSON of the application
|
||||||
@ -15,6 +16,8 @@ const uuid = require('uuid/v4');
|
|||||||
|
|
||||||
module.exports = scope => {
|
module.exports = scope => {
|
||||||
const cliPkg = scope.strapiPackageJSON || {};
|
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.
|
// Let us install additional dependencies on a specific version.
|
||||||
// Ex: it allows us to install the right version of knex.
|
// Ex: it allows us to install the right version of knex.
|
||||||
@ -68,6 +71,7 @@ module.exports = scope => {
|
|||||||
'url': scope.website || ''
|
'url': scope.website || ''
|
||||||
}],
|
}],
|
||||||
'strapi': {
|
'strapi': {
|
||||||
|
'packageManager': pckManager,
|
||||||
'uuid': uuid()
|
'uuid': uuid()
|
||||||
},
|
},
|
||||||
'engines': {
|
'engines': {
|
||||||
|
|||||||
@ -39,8 +39,9 @@ module.exports = (scope, cb) => {
|
|||||||
const dependencies = _.get(packageJSON, 'dependencies');
|
const dependencies = _.get(packageJSON, 'dependencies');
|
||||||
const strapiDependencies = Object.keys(dependencies).filter(key => key.indexOf('strapi') !== -1);
|
const strapiDependencies = Object.keys(dependencies).filter(key => key.indexOf('strapi') !== -1);
|
||||||
const othersDependencies = Object.keys(dependencies).filter(key => key.indexOf('strapi') === -1);
|
const othersDependencies = Object.keys(dependencies).filter(key => key.indexOf('strapi') === -1);
|
||||||
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM;
|
// Add this check to know if we are in development mode so the creation is faster.
|
||||||
const globalRootPath = execSync(packageManager.commands('root -g'));
|
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');
|
// const globalRootPath = execSync('npm root -g');
|
||||||
|
|
||||||
// Verify if the dependencies are available into the global
|
// Verify if the dependencies are available into the global
|
||||||
|
|||||||
@ -214,8 +214,8 @@ module.exports = (scope, cb) => {
|
|||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
new Promise(resolve => {
|
new Promise(resolve => {
|
||||||
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM;
|
const isStrapiInstalledWithNPM = process.argv.indexOf('new') !== -1 && process.argv.indexOf('--dev') !== -1 || packageManager.isStrapiInstalledWithNPM();
|
||||||
let packageCmd = packageManager.commands('install --prefix', scope.tmpPath);
|
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`;
|
// let cmd = `npm install --prefix "${scope.tmpPath}" ${scope.client.connector}@alpha`;
|
||||||
// Manually create the temp directory for yarn
|
// Manually create the temp directory for yarn
|
||||||
if (!isStrapiInstalledWithNPM) {
|
if (!isStrapiInstalledWithNPM) {
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
const shell = require('shelljs');
|
const shell = require('shelljs');
|
||||||
const { includes } = require('lodash');
|
const { includes } = require('lodash');
|
||||||
|
|
||||||
let isStrapiInstalledWithNPM;
|
// let isStrapiInstalledWithNPM = true;
|
||||||
let skipCheck = false;
|
// let skipCheck = false;
|
||||||
|
|
||||||
const watcher = (cmd) => {
|
const watcher = (cmd) => {
|
||||||
const data = shell.exec(cmd, {
|
const data = shell.exec(cmd, {
|
||||||
@ -10,13 +10,17 @@ const watcher = (cmd) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (includes(data.stderr, 'command not found') && data.code !== 0) {
|
if (includes(data.stderr, 'command not found') && data.code !== 0) {
|
||||||
console.log('ERRRRR');
|
|
||||||
throw new Error('Command not found');
|
throw new Error('Command not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
return data.stdout.toString();
|
return data.stdout.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
isStrapiInstalledWithNPM: () => {
|
||||||
|
let isNPM = true;
|
||||||
|
let skipCheck = false;
|
||||||
|
|
||||||
// Check if we are in development mode (working with the monorepo)
|
// Check if we are in development mode (working with the monorepo)
|
||||||
// So we don't run `npm -g ls` which takes time
|
// So we don't run `npm -g ls` which takes time
|
||||||
if (process.argv.indexOf('new') !== -1 && process.argv.indexOf('--dev') !== -1) {
|
if (process.argv.indexOf('new') !== -1 && process.argv.indexOf('--dev') !== -1) {
|
||||||
@ -28,26 +32,33 @@ if (!skipCheck) {
|
|||||||
// Retrieve all the packages installed with NPM
|
// Retrieve all the packages installed with NPM
|
||||||
const data = watcher('npm -g ls');
|
const data = watcher('npm -g ls');
|
||||||
// Check if strapi is installed with NPM
|
// 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) {
|
} catch(err) {
|
||||||
// If NPM is not installed strapi is installed with Yarn
|
// If NPM is not installed strapi is installed with Yarn
|
||||||
isStrapiInstalledWithNPM = false;
|
isNPM = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
return isNPM;
|
||||||
isStrapiInstalledWithNPM,
|
},
|
||||||
|
|
||||||
commands: (cmdType, path = '') => {
|
commands: (cmdType, path = '') => {
|
||||||
|
const isNPM = module.isStrapiInstalledWithNPM();
|
||||||
switch(cmdType) {
|
switch(cmdType) {
|
||||||
case 'install --prefix':
|
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':
|
case 'root -g':
|
||||||
return isStrapiInstalledWithNPM ? 'npm root -g' : 'yarn global dir';
|
return isNPM ? 'npm root -g' : 'yarn global dir';
|
||||||
case 'install global':
|
case 'install global':
|
||||||
return isStrapiInstalledWithNPM ? 'npm install' : 'yarn install';
|
return isNPM ? 'npm install' : 'yarn install';
|
||||||
case 'install package':
|
case 'install package':
|
||||||
return isStrapiInstalledWithNPM ? 'npm install' : 'yarn add';
|
return isNPM ? 'npm install' : 'yarn add';
|
||||||
default:
|
default:
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,6 @@ module.exports = function (plugin, cliArguments) {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error('An error occurred during plugin installation.');
|
logger.error('An error occurred during plugin installation.');
|
||||||
console.log('ERROR PLUGINS INSTALL', e);
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -57,7 +56,7 @@ module.exports = function (plugin, cliArguments) {
|
|||||||
logger.debug('Installing the plugin from npm registry.');
|
logger.debug('Installing the plugin from npm registry.');
|
||||||
|
|
||||||
// Install the plugin from the npm registry.
|
// Install the plugin from the npm registry.
|
||||||
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM;
|
const isStrapiInstalledWithNPM = packageManager.isStrapiInstalledWithNPM();
|
||||||
|
|
||||||
if (!isStrapiInstalledWithNPM) {
|
if (!isStrapiInstalledWithNPM) {
|
||||||
// Create the directory yarn doesn't do it it
|
// Create the directory yarn doesn't do it it
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user