mirror of
https://github.com/strapi/strapi.git
synced 2025-09-02 21:32:43 +00:00
Lint strapi-generate-new
This commit is contained in:
parent
0bfbdf8e72
commit
50598616f4
@ -24,9 +24,11 @@ const logger = require('strapi-utils').logger;
|
|||||||
* @param {Function} cb
|
* @param {Function} cb
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
/* eslint-disable prefer-template */
|
||||||
module.exports = (scope, cb) => {
|
module.exports = (scope, cb) => {
|
||||||
const packageJSON = require(path.resolve(scope.rootPath, 'package.json'));
|
const packageJSON = require(path.resolve(scope.rootPath, 'package.json'));
|
||||||
const strapiRootPath = path.resolve(scope.strapiRoot, '..');
|
// const strapiRootPath = path.resolve(scope.strapiRoot, '..');
|
||||||
|
|
||||||
process.chdir(scope.rootPath);
|
process.chdir(scope.rootPath);
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
// Node.js core.
|
// Node.js core.
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
const execSync = require('child_process').execSync;
|
|
||||||
|
|
||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
@ -26,6 +26,7 @@ const logger = require('strapi-utils').logger;
|
|||||||
* @param {Function} cb
|
* @param {Function} cb
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* eslint-disable no-useless-escape */
|
||||||
module.exports = (scope, cb) => {
|
module.exports = (scope, cb) => {
|
||||||
// App info.
|
// App info.
|
||||||
const hasDatabaseConfig = !!scope.database;
|
const hasDatabaseConfig = !!scope.database;
|
||||||
@ -102,173 +103,173 @@ module.exports = (scope, cb) => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
inquirer
|
inquirer
|
||||||
.prompt([
|
.prompt([
|
||||||
{
|
{
|
||||||
when: !hasDatabaseConfig,
|
when: !hasDatabaseConfig,
|
||||||
type: 'list',
|
type: 'list',
|
||||||
prefix: '',
|
prefix: '',
|
||||||
name: 'client',
|
name: 'client',
|
||||||
message: 'Choose your main database:',
|
message: 'Choose your main database:',
|
||||||
choices: databaseChoices,
|
choices: databaseChoices,
|
||||||
default: () => {
|
default: () => {
|
||||||
if (scope.client) {
|
if (scope.client) {
|
||||||
return _.findIndex(databaseChoices, { value: _.omit(scope.client, ['version'])});
|
return _.findIndex(databaseChoices, { value: _.omit(scope.client, ['version'])});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
])
|
||||||
])
|
.then(answers => {
|
||||||
.then(answers => {
|
if (hasDatabaseConfig) {
|
||||||
if (hasDatabaseConfig) {
|
const databaseChoice = _.find(databaseChoices, ['value.database', scope.database.settings.client]);
|
||||||
const databaseChoice = _.find(databaseChoices, ['value.database', scope.database.settings.client]);
|
scope.database.connector = databaseChoice.value.connector;
|
||||||
scope.database.connector = databaseChoice.value.connector;
|
answers.client = {
|
||||||
answers.client = {
|
...databaseChoice.value
|
||||||
...databaseChoice.value
|
};
|
||||||
};
|
} else {
|
||||||
} else {
|
_.assign(scope.database, {
|
||||||
_.assign(scope.database, {
|
connector: answers.client.connector,
|
||||||
connector: answers.client.connector,
|
settings: {
|
||||||
settings: {
|
client: answers.client.database
|
||||||
client: answers.client.database
|
},
|
||||||
},
|
options: {}
|
||||||
options: {}
|
});
|
||||||
});
|
}
|
||||||
}
|
scope.client = answers.client;
|
||||||
scope.client = answers.client;
|
|
||||||
|
|
||||||
const asyncFn = [
|
const asyncFn = [
|
||||||
new Promise(resolve => {
|
new Promise(resolve => {
|
||||||
inquirer
|
inquirer
|
||||||
.prompt([
|
.prompt([
|
||||||
{
|
{
|
||||||
when: !hasDatabaseConfig,
|
when: !hasDatabaseConfig,
|
||||||
type: 'input',
|
type: 'input',
|
||||||
prefix: '',
|
prefix: '',
|
||||||
name: 'database',
|
name: 'database',
|
||||||
message: 'Database name:',
|
message: 'Database name:',
|
||||||
default: _.get(scope.database, 'database', 'strapi')
|
default: _.get(scope.database, 'database', 'strapi')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
when: !hasDatabaseConfig,
|
when: !hasDatabaseConfig,
|
||||||
type: 'input',
|
type: 'input',
|
||||||
prefix: '',
|
prefix: '',
|
||||||
name: 'host',
|
name: 'host',
|
||||||
message: 'Host:',
|
message: 'Host:',
|
||||||
default: _.get(scope.database, 'host', '127.0.0.1')
|
default: _.get(scope.database, 'host', '127.0.0.1')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
when: !hasDatabaseConfig,
|
when: !hasDatabaseConfig,
|
||||||
type: 'input',
|
type: 'input',
|
||||||
prefix: '',
|
prefix: '',
|
||||||
name: 'port',
|
name: 'port',
|
||||||
message: 'Port:',
|
message: 'Port:',
|
||||||
default: (answers) => {
|
default: (answers) => { // eslint-disable-line no-unused-vars
|
||||||
if (_.get(scope.database, 'port')) {
|
if (_.get(scope.database, 'port')) {
|
||||||
return scope.database.port;
|
return scope.database.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ports = {
|
||||||
|
mongo: 27017,
|
||||||
|
postgres: 5432,
|
||||||
|
mysql: 3306,
|
||||||
|
sqlite3: 1433,
|
||||||
|
redis: 6379
|
||||||
|
};
|
||||||
|
|
||||||
|
return ports[scope.client.database];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
when: !hasDatabaseConfig,
|
||||||
|
type: 'input',
|
||||||
|
prefix: '',
|
||||||
|
name: 'username',
|
||||||
|
message: 'Username:',
|
||||||
|
default: _.get(scope.database, 'username', undefined)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
when: !hasDatabaseConfig,
|
||||||
|
type: 'password',
|
||||||
|
prefix: '',
|
||||||
|
name: 'password',
|
||||||
|
message: 'Password:',
|
||||||
|
mask: '*',
|
||||||
|
default: _.get(scope.database, 'password', undefined)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
when: !hasDatabaseConfig && scope.client.database === 'mongo',
|
||||||
|
type: 'input',
|
||||||
|
prefix: '',
|
||||||
|
name: 'authenticationDatabase',
|
||||||
|
message: 'Authentication database:',
|
||||||
|
default: _.get(scope.database, 'authenticationDatabase', undefined)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
when: !hasDatabaseConfig && scope.client.database === 'mongo',
|
||||||
|
type: 'boolean',
|
||||||
|
prefix: '',
|
||||||
|
name: 'ssl',
|
||||||
|
message: 'Enable SSL connection:',
|
||||||
|
default: _.get(scope.database, 'ssl', false)
|
||||||
|
}
|
||||||
|
])
|
||||||
|
.then(answers => {
|
||||||
|
if (hasDatabaseConfig) {
|
||||||
|
answers = _.omit(scope.database.settings, ['client']);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ports = {
|
scope.database.settings.host = answers.host;
|
||||||
mongo: 27017,
|
scope.database.settings.port = answers.port;
|
||||||
postgres: 5432,
|
scope.database.settings.database = answers.database;
|
||||||
mysql: 3306,
|
scope.database.settings.username = answers.username;
|
||||||
sqlite3: 1433,
|
scope.database.settings.password = answers.password;
|
||||||
redis: 6379
|
scope.database.options.authenticationDatabase = answers.authenticationDatabase;
|
||||||
};
|
scope.database.options.ssl = _.toString(answers.ssl) === 'true';
|
||||||
|
|
||||||
return ports[scope.client.database];
|
logger.info('Testing database connection...');
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
when: !hasDatabaseConfig,
|
|
||||||
type: 'input',
|
|
||||||
prefix: '',
|
|
||||||
name: 'username',
|
|
||||||
message: 'Username:',
|
|
||||||
default: _.get(scope.database, 'username', undefined)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
when: !hasDatabaseConfig,
|
|
||||||
type: 'password',
|
|
||||||
prefix: '',
|
|
||||||
name: 'password',
|
|
||||||
message: 'Password:',
|
|
||||||
mask: '*',
|
|
||||||
default: _.get(scope.database, 'password', undefined)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
when: !hasDatabaseConfig && scope.client.database === 'mongo',
|
|
||||||
type: 'input',
|
|
||||||
prefix: '',
|
|
||||||
name: 'authenticationDatabase',
|
|
||||||
message: 'Authentication database:',
|
|
||||||
default: _.get(scope.database, 'authenticationDatabase', undefined)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
when: !hasDatabaseConfig && scope.client.database === 'mongo',
|
|
||||||
type: 'boolean',
|
|
||||||
prefix: '',
|
|
||||||
name: 'ssl',
|
|
||||||
message: 'Enable SSL connection:',
|
|
||||||
default: _.get(scope.database, 'ssl', false)
|
|
||||||
}
|
|
||||||
])
|
|
||||||
.then(answers => {
|
|
||||||
if (hasDatabaseConfig) {
|
|
||||||
answers = _.omit(scope.database.settings, ['client'])
|
|
||||||
}
|
|
||||||
|
|
||||||
scope.database.settings.host = answers.host;
|
resolve();
|
||||||
scope.database.settings.port = answers.port;
|
});
|
||||||
scope.database.settings.database = answers.database;
|
}),
|
||||||
scope.database.settings.username = answers.username;
|
new Promise(resolve => {
|
||||||
scope.database.settings.password = answers.password;
|
let cmd = `npm install --prefix "${scope.tmpPath}" ${scope.client.connector}@alpha`;
|
||||||
scope.database.options.authenticationDatabase = answers.authenticationDatabase;
|
|
||||||
scope.database.options.ssl = _.toString(answers.ssl) === 'true';
|
|
||||||
|
|
||||||
logger.info('Testing database connection...');
|
|
||||||
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
new Promise(resolve => {
|
|
||||||
let cmd = `npm install --prefix "${scope.tmpPath}" ${scope.client.connector}@alpha`;
|
|
||||||
|
|
||||||
if (scope.client.module) {
|
|
||||||
cmd += ` ${scope.client.module}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scope.developerMode === true && scope.client.connector === 'strapi-bookshelf') {
|
|
||||||
cmd += ` strapi-knex@alpha`;
|
|
||||||
|
|
||||||
scope.additionalsDependencies = ['strapi-knex', 'knex'];
|
|
||||||
}
|
|
||||||
|
|
||||||
exec(cmd, () => {
|
|
||||||
if (scope.client.module) {
|
if (scope.client.module) {
|
||||||
const lock = require(path.join(`${scope.tmpPath}`,`/node_modules/`,`${scope.client.module}/package.json`));
|
cmd += ` ${scope.client.module}`;
|
||||||
scope.client.version = lock.version;
|
|
||||||
|
|
||||||
if (scope.developerMode === true && scope.client.connector === 'strapi-bookshelf') {
|
|
||||||
const knexVersion = require(path.join(`${scope.tmpPath}`,`/node_modules/`,`knex/package.json`));
|
|
||||||
scope.additionalsDependencies[1] = `knex@${knexVersion.version || 'latest'}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve();
|
if (scope.developerMode === true && scope.client.connector === 'strapi-bookshelf') {
|
||||||
});
|
cmd += ` strapi-knex@alpha`;
|
||||||
})
|
|
||||||
];
|
|
||||||
|
|
||||||
Promise.all(asyncFn)
|
scope.additionalsDependencies = ['strapi-knex', 'knex'];
|
||||||
.then(() => {
|
}
|
||||||
try {
|
|
||||||
require(path.join(`${scope.tmpPath}`,`/node_modules/`,`${scope.client.connector}/lib/utils/connectivity.js`))(scope, cb.success, connectionValidation);
|
exec(cmd, () => {
|
||||||
} catch(err) {
|
if (scope.client.module) {
|
||||||
shell.rm('-r', scope.tmpPath);
|
const lock = require(path.join(`${scope.tmpPath}`,`/node_modules/`,`${scope.client.module}/package.json`));
|
||||||
logger.info('Copying the dashboard...');
|
scope.client.version = lock.version;
|
||||||
cb.success();
|
|
||||||
}
|
if (scope.developerMode === true && scope.client.connector === 'strapi-bookshelf') {
|
||||||
|
const knexVersion = require(path.join(`${scope.tmpPath}`,`/node_modules/`,`knex/package.json`));
|
||||||
|
scope.additionalsDependencies[1] = `knex@${knexVersion.version || 'latest'}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
Promise.all(asyncFn)
|
||||||
|
.then(() => {
|
||||||
|
try {
|
||||||
|
require(path.join(`${scope.tmpPath}`,`/node_modules/`,`${scope.client.connector}/lib/utils/connectivity.js`))(scope, cb.success, connectionValidation);
|
||||||
|
} catch(err) {
|
||||||
|
shell.rm('-r', scope.tmpPath);
|
||||||
|
logger.info('Copying the dashboard...');
|
||||||
|
cb.success();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
connectionValidation();
|
connectionValidation();
|
||||||
|
@ -27,7 +27,7 @@ const watcher = (label, pckgName, type = 'front') => {
|
|||||||
const packagesPath = path.resolve(process.env.PWD, 'packages');
|
const packagesPath = path.resolve(process.env.PWD, 'packages');
|
||||||
shell.ls('* -d', packagesPath)
|
shell.ls('* -d', packagesPath)
|
||||||
// TODO temporary just for eslint
|
// TODO temporary just for eslint
|
||||||
.filter(package => package === 'strapi-generate-model')
|
.filter(package => package === 'strapi-generate-new')
|
||||||
// .filter(package => package !== 'README.md')
|
// .filter(package => package !== 'README.md')
|
||||||
.forEach(package => {
|
.forEach(package => {
|
||||||
watcher(`Testing ${package}`, package);
|
watcher(`Testing ${package}`, package);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user