This commit is contained in:
Alexandre Bodin 2019-12-10 14:21:20 +01:00
parent 7c3f781081
commit 3446b7f577
11 changed files with 12 additions and 211 deletions

View File

@ -9,8 +9,8 @@ class DatabaseManager {
constructor(strapi) {
this.strapi = strapi;
// throw if connections and schemas aren't arrays
this.initialized = false;
this.queries = new Map();
this.connectors = new Map();
this.models = new Map();

View File

@ -1,21 +0,0 @@
'use strict';
function nameToUID({ name, isGroup, plugin, isAdmin }) {
if (isGroup) {
return `group::${name}`;
}
if (plugin) {
return `plugins::${plugin}.${name}`;
}
if (isAdmin) {
return `admin::${name}`;
}
return `app::${name}`;
}
module.exports = {
nameToUID,
};

View File

@ -1,23 +0,0 @@
'use strict';
/**
* Module dependencies
*/
// Public node modules.
const _ = require('lodash');
const program = require('commander');
/**
* Monkey-patch commander
*/
// Allow us to display `help()`, but omit the wildcard (`*`) command.
program.Command.prototype.usageMinusWildcard = program.usageMinusWildcard = () => {
program.commands = _.reject(program.commands, {
_name: '*'
});
program.help();
};
module.exports = program;

View File

@ -12,10 +12,7 @@ const parseType = require('./parse-type');
module.exports = {
cli: require('./cli'),
commander: require('./commander'),
finder: require('./finder'),
joijson: require('./joi-json'),
json: require('./json'),
knex: require('./knex'),
logger: require('./logger'),
models: require('./models'),

View File

@ -1,7 +0,0 @@
'use strict';
/**
* Creates Joi based object schemas from JSON
*/
module.exports = require('joi-json');

View File

@ -1,138 +0,0 @@
'use strict';
/**
* Module dependencies
*/
// Node.js core.
const fs = require('fs');
// Public node modules.
const _ = require('lodash');
/**
* `parseJSONFile()`
*
* Read a json file at the specified path.
* If an error occurs, call cb(err), and dont throw!
*
* @api private
*/
exports.parseJSONFile = (path, cb) => {
if (!cb) {
throw new Error('Callback required!');
}
if (cb === 'sync') {
let jsonString;
try {
jsonString = fs.readFileSync(path, 'utf-8');
} catch (e) {
return false;
}
return andThen(jsonString);
}
fs.readFile(path, 'utf-8', (err, file) => {
if (err) {
return cb(err);
}
andThen(file);
});
// Attempt to parse JSON, then return.
function andThen(json) {
let err;
try {
json = JSON.parse(json);
} catch (e) {
err = e;
json = false;
}
// Parse failed.
if (err) {
if (cb === 'sync') {
return false;
}
return cb(err);
}
// Success.
if (cb === 'sync') {
return json;
}
return cb(null, json);
}
};
/**
* `getJSONFileSync()`
*
* Synchronous version of `getJSONFile()`.
* Returns false if json file cannot be read or parsed.
*
* @api private
*/
exports.parseJSONFileSync = path => {
return exports.parseJSONFile(path, 'sync');
};
/**
* `getPackage()`
*
* Read `package.json` file in the directory at the specified
* path. If an error occurs, call `cb(err)`, and dont throw!
*
* @api private
*/
exports.getPackage = (path, cb) => {
path = _.trimEnd(path, '/');
path += '/package.json';
exports.parseJSONFile(path, (err, json) => {
if (err) {
return cb(err);
}
// Success: ensure dependencies are at least an empty object
json.dependencies = json.dependencies || {};
if (cb === 'sync') {
return json;
}
return cb(null, json);
});
};
/**
* `getPackageSync()`
*
* Synchronous version of `getPackage()`
* Returns `false` if `package.json` cannot be read or parsed.
*
* @api private
*/
exports.getPackageSync = path => {
path = _.trimEnd(path, '/');
path += '/package.json';
// Success: ensure dependencies are at least an empty object.
const json = exports.parseJSONFileSync(path, 'sync');
if (!json) {
return json;
}
json.dependencies = json.dependencies || {};
return json;
};

View File

@ -18,9 +18,7 @@
"test": "jest"
},
"dependencies": {
"commander": "^2.20.0",
"date-fns": "^2.8.1",
"joi-json": "^2.1.0",
"knex": "^0.16.5",
"lodash": "^4.17.11",
"pino": "^4.7.1",

View File

@ -4,10 +4,18 @@
const _ = require('lodash');
const resolveCwd = require('resolve-cwd');
const { yellow } = require('chalk');
const program = require('commander');
const program = require('strapi-utils').commander;
const packageJSON = require('../package.json');
// Allow us to display `help()`, but omit the wildcard (`*`) command.
program.Command.prototype.usageMinusWildcard = program.usageMinusWildcard = () => {
program.commands = _.reject(program.commands, {
_name: '*',
});
program.help();
};
const checkCwdIsStrapiApp = name => {
let logErrorAndExit = () => {
console.log(

View File

@ -8,9 +8,7 @@
const _ = require('lodash');
// Strapi utilities.
const finder = require('strapi-utils').finder;
const regex = require('strapi-utils').regex;
const policyUtils = require('strapi-utils').policy;
const { finder, regex, policy: policyUtils } = require('strapi-utils');
module.exports = strapi =>
function routerChecker(value, endpoint, plugin) {

View File

@ -18,6 +18,7 @@
"chalk": "^2.4.1",
"chokidar": "^2.1.2",
"cli-table3": "^0.5.1",
"commander": "^2.20.0",
"cross-spawn": "^6.0.5",
"delegates": "^1.0.0",
"execa": "^1.0.0",

View File

@ -10534,13 +10534,6 @@ jmespath@0.15.0:
resolved "https://registry.yarnpkg.com/jmespath/-/jmespath-0.15.0.tgz#a3f222a9aae9f966f5d27c796510e28091764217"
integrity sha1-o/Iiqarp+Wb10nx5ZRDigJF2Qhc=
joi-json@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/joi-json/-/joi-json-2.1.0.tgz#4829cca91e531d19c4cad1205a08d61549a0c051"
integrity sha512-0NKQSqMeBzzU5FLoIPnmTNV3ZwA7TeN1itCpiYnumq9WIQGFAgIuEyEuBJ4xHhxa57E980zKU2596E9pODcYAg==
dependencies:
vandium-utils "^1.1.0"
js-beautify@^1.6.12:
version "1.10.2"
resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.10.2.tgz#88c9099cd6559402b124cfab18754936f8a7b178"
@ -18348,11 +18341,6 @@ value-equal@^1.0.1:
resolved "https://registry.yarnpkg.com/value-equal/-/value-equal-1.0.1.tgz#1e0b794c734c5c0cade179c437d356d931a34d6c"
integrity sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw==
vandium-utils@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/vandium-utils/-/vandium-utils-1.2.0.tgz#44735de4b7641a05de59ebe945f174e582db4f59"
integrity sha1-RHNd5LdkGgXeWevpRfF05YLbT1k=
vary@^1.1.2, vary@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"