gaffer-generator 1.2.7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/cli.js +43 -37
- package/lib/argv.js +9 -0
- package/lib/create.js +40 -0
- package/{src → lib}/generate/directory.js +13 -14
- package/{src → lib}/generate/file.js +13 -13
- package/{src → lib}/generate/node.js +6 -9
- package/lib/generate/root.js +95 -0
- package/{src → lib}/templateArgs.js +1 -1
- package/lib/utils/contentsDiffer.js +20 -0
- package/lib/utils/log.js +26 -0
- package/lib/utils/logChange.js +16 -0
- package/lib/utils/logError.js +10 -0
- package/lib/utils/logRemoval.js +10 -0
- package/lib/utils/lowerCaseFirst.js +11 -0
- package/lib/utils/normalizeLineEndings.js +8 -0
- package/lib/utils/normalizePath.js +10 -0
- package/lib/utils/parameterizeString.js +19 -0
- package/lib/utils/safeRead.js +17 -0
- package/lib/utils/safeWrite.js +23 -0
- package/lib/utils.js +16 -0
- package/package.json +39 -11
- package/.github/dependabot.yml +0 -8
- package/.github/workflows/codeql-analysis.yml +0 -67
- package/SECURITY.md +0 -15
- package/example/sample.json +0 -431
- package/example/sample.templateroot/date-parser.ts +0 -10
- package/example/sample.templateroot/is-set.ts +0 -3
- package/example/sample.templateroot/models/_eachEnum.fileName_.ts +0 -13
- package/example/sample.templateroot/models/_eachModel.fileName_.ts +0 -73
- package/example/sample.templateroot/models/index.ts +0 -14
- package/example/sample.templateroot/services/_eachController.fileName_.ts +0 -82
- package/example/sample.templateroot/services/index.ts +0 -11
- package/example/sample.templateroot/template.js +0 -413
- package/jest.config.js +0 -185
- package/renovate.json +0 -6
- package/src/__mocks__/fs.js +0 -59
- package/src/create.js +0 -38
- package/src/create.test.js +0 -5
- package/src/generate/directory.test.js +0 -5
- package/src/generate/file.test.js +0 -5
- package/src/generate/node.test.js +0 -5
- package/src/generate/root.js +0 -86
- package/src/generate/root.test.js +0 -5
- package/src/lodash.js +0 -17205
- package/src/utils.js +0 -179
- package/src/utils.test.js +0 -146
package/src/__mocks__/fs.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
Testing utility API.
|
|
5
|
-
*/
|
|
6
|
-
const fs = jest.genMockFromModule('fs');
|
|
7
|
-
const responses = {};
|
|
8
|
-
let mockFiles = {};
|
|
9
|
-
fs.__setMockFiles = __setMockFiles;
|
|
10
|
-
fs.__setResponse = __setResponse;
|
|
11
|
-
fs.__spy = {};
|
|
12
|
-
const mockedMethods = [
|
|
13
|
-
'existsSync',
|
|
14
|
-
'readFileSync',
|
|
15
|
-
'writeFileSync',
|
|
16
|
-
'mkdirSync',
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
/*
|
|
20
|
-
Mocked API.
|
|
21
|
-
*/
|
|
22
|
-
fs.readdirSync = readdirSync;
|
|
23
|
-
for (const mockedMethod of mockedMethods) {
|
|
24
|
-
fs[mockedMethod] = respond(mockedMethod);
|
|
25
|
-
fs.__spy[mockedMethod] = jest.spyOn(fs, mockedMethod);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = fs;
|
|
29
|
-
|
|
30
|
-
/*
|
|
31
|
-
Implementation.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
function __setMockFiles(newMockFiles) {
|
|
35
|
-
mockFiles = {};
|
|
36
|
-
for (const file of newMockFiles) {
|
|
37
|
-
const dir = path.dirname(file);
|
|
38
|
-
if (!mockFiles[dir]) {
|
|
39
|
-
mockFiles[dir] = [];
|
|
40
|
-
}
|
|
41
|
-
mockFiles[dir].push(path.basename(file));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function __setResponse(method, val) {
|
|
46
|
-
responses[method] = val;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function readdirSync(directoryPath) {
|
|
50
|
-
return mockFiles[directoryPath] || [];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function respond(method) {
|
|
54
|
-
return () => {
|
|
55
|
-
if (responses[method] !== undefined) {
|
|
56
|
-
return responses[method];
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
package/src/create.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
require('colors');
|
|
2
|
-
const copy = require('recursive-copy');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const argv = require('yargs').argv;
|
|
5
|
-
|
|
6
|
-
const utils = require('./utils');
|
|
7
|
-
const dryRun = argv.dryRun || false;
|
|
8
|
-
|
|
9
|
-
/*
|
|
10
|
-
Public API.
|
|
11
|
-
*/
|
|
12
|
-
exports.run = run;
|
|
13
|
-
|
|
14
|
-
/*
|
|
15
|
-
Implementation.
|
|
16
|
-
*/
|
|
17
|
-
function run(directory) {
|
|
18
|
-
const from = path.join(__dirname, '..', 'example', 'sample.templateroot');
|
|
19
|
-
const to = directory;
|
|
20
|
-
const options = {
|
|
21
|
-
overwrite: argv.overwrite,
|
|
22
|
-
};
|
|
23
|
-
utils.logChange(to);
|
|
24
|
-
if (dryRun) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
copy(from, to, options)
|
|
28
|
-
.on(copy.events.ERROR, (error, copyOperation) => {
|
|
29
|
-
utils.logError('Unable to copy to '.red + copyOperation.dest.magenta);
|
|
30
|
-
})
|
|
31
|
-
.then(results => {
|
|
32
|
-
utils.log(results.length + ' file(s) copied');
|
|
33
|
-
})
|
|
34
|
-
.catch(function(error) {
|
|
35
|
-
utils.logError(String(error).red);
|
|
36
|
-
process.exit(1);
|
|
37
|
-
});
|
|
38
|
-
}
|
package/src/create.test.js
DELETED
package/src/generate/root.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
require('colors');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const globule = require('globule');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const argv = require('yargs').argv;
|
|
6
|
-
|
|
7
|
-
const utils = require('../utils');
|
|
8
|
-
const node = require('./node');
|
|
9
|
-
|
|
10
|
-
/*
|
|
11
|
-
Public API.
|
|
12
|
-
*/
|
|
13
|
-
exports.run = run;
|
|
14
|
-
exports.visit = visit;
|
|
15
|
-
|
|
16
|
-
/*
|
|
17
|
-
Implementation.
|
|
18
|
-
*/
|
|
19
|
-
function run(directory) {
|
|
20
|
-
const matches = globule.find({
|
|
21
|
-
src: path.join(directory, '**/*.templateroot'),
|
|
22
|
-
filter: match => match.indexOf('node_modules') === -1,
|
|
23
|
-
dot: true,
|
|
24
|
-
});
|
|
25
|
-
for (const match of matches) {
|
|
26
|
-
visit(path.resolve(match));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function visit(rootPath) {
|
|
31
|
-
const templateSettingsPath = determineTemplateFile(rootPath);
|
|
32
|
-
if (!templateSettingsPath) {
|
|
33
|
-
utils.logError(
|
|
34
|
-
'Found .templateroot without a template.cjs, template.js or template.ts file:\n'.red
|
|
35
|
-
+ rootPath.cyan);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const templateSettings = require(templateSettingsPath);
|
|
39
|
-
if (argv.into) {
|
|
40
|
-
templateSettings.into = argv.into;
|
|
41
|
-
}
|
|
42
|
-
if (!templateSettings.into) {
|
|
43
|
-
utils.logError(
|
|
44
|
-
'Found .templateroot that does not have a "into" export in template file:\n'.red
|
|
45
|
-
+ templateSettingsPath.cyan);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (!templateSettings.download) {
|
|
49
|
-
utils.logError(
|
|
50
|
-
'Found .templateroot that does not have a "download" export in template file:\n'.red
|
|
51
|
-
+ templateSettingsPath.cyan);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const toPath = templateSettings.into[0] === '/' ? templateSettings.into : path.join(rootPath, templateSettings.into);
|
|
55
|
-
utils.log('Running download from '.green + templateSettingsPath.magenta);
|
|
56
|
-
templateSettings.download(utils.fetch)
|
|
57
|
-
.catch(err => {
|
|
58
|
-
utils.logError(
|
|
59
|
-
'Hit error when downloading for .templateroot:\n'.red
|
|
60
|
-
+ templateSettingsPath.cyan,
|
|
61
|
-
err);
|
|
62
|
-
})
|
|
63
|
-
.then(json => json && node.visit(json, rootPath, toPath, templateSettings));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function determineTemplateFile(rootPath) {
|
|
67
|
-
const cjsTemplate = path.join(rootPath, 'template.cjs');
|
|
68
|
-
const jsTemplate = path.join(rootPath, 'template.js');
|
|
69
|
-
const tsTemplate = path.join(rootPath, 'template.ts');
|
|
70
|
-
if (fs.existsSync(cjsTemplate)) {
|
|
71
|
-
return cjsTemplate;
|
|
72
|
-
}
|
|
73
|
-
if (fs.existsSync(jsTemplate)) {
|
|
74
|
-
return jsTemplate;
|
|
75
|
-
}
|
|
76
|
-
if (fs.existsSync(tsTemplate)) {
|
|
77
|
-
try {
|
|
78
|
-
require('ts-node').register();
|
|
79
|
-
}
|
|
80
|
-
catch (err) {
|
|
81
|
-
console.warn('Detected template.ts, but ts-node failed to register:', err);
|
|
82
|
-
}
|
|
83
|
-
return tsTemplate;
|
|
84
|
-
}
|
|
85
|
-
return null;
|
|
86
|
-
}
|