gaffer-generator 1.2.5 → 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.
Files changed (46) hide show
  1. package/README.md +7 -5
  2. package/cli.js +43 -37
  3. package/lib/argv.js +9 -0
  4. package/lib/create.js +40 -0
  5. package/{src → lib}/generate/directory.js +13 -14
  6. package/{src → lib}/generate/file.js +13 -13
  7. package/{src → lib}/generate/node.js +6 -9
  8. package/lib/generate/root.js +95 -0
  9. package/{src → lib}/templateArgs.js +1 -1
  10. package/lib/utils/contentsDiffer.js +20 -0
  11. package/lib/utils/log.js +26 -0
  12. package/lib/utils/logChange.js +16 -0
  13. package/lib/utils/logError.js +10 -0
  14. package/lib/utils/logRemoval.js +10 -0
  15. package/lib/utils/lowerCaseFirst.js +11 -0
  16. package/lib/utils/normalizeLineEndings.js +8 -0
  17. package/lib/utils/normalizePath.js +10 -0
  18. package/lib/utils/parameterizeString.js +19 -0
  19. package/lib/utils/safeRead.js +17 -0
  20. package/lib/utils/safeWrite.js +23 -0
  21. package/lib/utils.js +16 -0
  22. package/package.json +42 -14
  23. package/.github/dependabot.yml +0 -8
  24. package/.github/workflows/codeql-analysis.yml +0 -67
  25. package/SECURITY.md +0 -15
  26. package/example/sample.json +0 -431
  27. package/example/sample.templateroot/date-parser.ts +0 -10
  28. package/example/sample.templateroot/is-set.ts +0 -3
  29. package/example/sample.templateroot/models/_eachEnum.fileName_.ts +0 -13
  30. package/example/sample.templateroot/models/_eachModel.fileName_.ts +0 -73
  31. package/example/sample.templateroot/models/index.ts +0 -14
  32. package/example/sample.templateroot/services/_eachController.fileName_.ts +0 -82
  33. package/example/sample.templateroot/services/index.ts +0 -11
  34. package/example/sample.templateroot/template.js +0 -413
  35. package/jest.config.js +0 -185
  36. package/src/__mocks__/fs.js +0 -59
  37. package/src/create.js +0 -38
  38. package/src/create.test.js +0 -5
  39. package/src/generate/directory.test.js +0 -5
  40. package/src/generate/file.test.js +0 -5
  41. package/src/generate/node.test.js +0 -5
  42. package/src/generate/root.js +0 -82
  43. package/src/generate/root.test.js +0 -5
  44. package/src/lodash.js +0 -17205
  45. package/src/utils.js +0 -179
  46. package/src/utils.test.js +0 -146
package/jest.config.js DELETED
@@ -1,185 +0,0 @@
1
- // For a detailed explanation regarding each configuration property, visit:
2
- // https://jestjs.io/docs/en/configuration.html
3
-
4
- module.exports = {
5
- // All imported modules in your tests should be mocked automatically
6
- // automock: false,
7
-
8
- // Stop running tests after `n` failures
9
- // bail: 0,
10
-
11
- // Respect "browser" field in package.json when resolving modules
12
- // browser: false,
13
-
14
- // The directory where Jest should store its cached dependency information
15
- // cacheDirectory: "/private/var/folders/yc/f786tvfd68b247nsj0m_sj7w0000gn/T/jest_dx",
16
-
17
- // Automatically clear mock calls and instances between every test
18
- clearMocks: true,
19
-
20
- // Indicates whether the coverage information should be collected while executing the test
21
- // collectCoverage: false,
22
-
23
- // An array of glob patterns indicating a set of files for which coverage information should be collected
24
- // collectCoverageFrom: null,
25
-
26
- // The directory where Jest should output its coverage files
27
- coverageDirectory: 'coverage',
28
-
29
- // An array of regexp pattern strings used to skip coverage collection
30
- // coveragePathIgnorePatterns: [
31
- // "/node_modules/"
32
- // ],
33
-
34
- // A list of reporter names that Jest uses when writing coverage reports
35
- // coverageReporters: [
36
- // "json",
37
- // "text",
38
- // "lcov",
39
- // "clover"
40
- // ],
41
-
42
- // An object that configures minimum threshold enforcement for coverage results
43
- // coverageThreshold: null,
44
-
45
- // A path to a custom dependency extractor
46
- // dependencyExtractor: null,
47
-
48
- // Make calling deprecated APIs throw helpful error messages
49
- // errorOnDeprecated: false,
50
-
51
- // Force coverage collection from ignored files using an array of glob patterns
52
- // forceCoverageMatch: [],
53
-
54
- // A path to a module which exports an async function that is triggered once before all test suites
55
- // globalSetup: null,
56
-
57
- // A path to a module which exports an async function that is triggered once after all test suites
58
- // globalTeardown: null,
59
-
60
- // A set of global variables that need to be available in all test environments
61
- // globals: {},
62
-
63
- // An array of directory names to be searched recursively up from the requiring module's location
64
- // moduleDirectories: [
65
- // "node_modules"
66
- // ],
67
-
68
- // An array of file extensions your modules use
69
- // moduleFileExtensions: [
70
- // "js",
71
- // "json",
72
- // "jsx",
73
- // "ts",
74
- // "tsx",
75
- // "node"
76
- // ],
77
-
78
- // A map from regular expressions to module names that allow to stub out resources with a single module
79
- // moduleNameMapper: {},
80
-
81
- // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
82
- // modulePathIgnorePatterns: [],
83
-
84
- // Activates notifications for test results
85
- // notify: false,
86
-
87
- // An enum that specifies notification mode. Requires { notify: true }
88
- // notifyMode: "failure-change",
89
-
90
- // A preset that is used as a base for Jest's configuration
91
- // preset: null,
92
-
93
- // Run tests from one or more projects
94
- // projects: null,
95
-
96
- // Use this configuration option to add custom reporters to Jest
97
- // reporters: undefined,
98
-
99
- // Automatically reset mock state between every test
100
- // resetMocks: false,
101
-
102
- // Reset the module registry before running each individual test
103
- // resetModules: false,
104
-
105
- // A path to a custom resolver
106
- // resolver: null,
107
-
108
- // Automatically restore mock state between every test
109
- // restoreMocks: false,
110
-
111
- // The root directory that Jest should scan for tests and modules within
112
- // rootDir: null,
113
-
114
- // A list of paths to directories that Jest should use to search for files in
115
- // roots: [
116
- // "<rootDir>"
117
- // ],
118
-
119
- // Allows you to use a custom runner instead of Jest's default test runner
120
- // runner: "jest-runner",
121
-
122
- // The paths to modules that run some code to configure or set up the testing environment before each test
123
- // setupFiles: [],
124
-
125
- // A list of paths to modules that run some code to configure or set up the testing framework before each test
126
- // setupFilesAfterEnv: [],
127
-
128
- // A list of paths to snapshot serializer modules Jest should use for snapshot testing
129
- // snapshotSerializers: [],
130
-
131
- // The test environment that will be used for testing
132
- testEnvironment: 'node',
133
-
134
- // Options that will be passed to the testEnvironment
135
- // testEnvironmentOptions: {},
136
-
137
- // Adds a location field to test results
138
- // testLocationInResults: false,
139
-
140
- // The glob patterns Jest uses to detect test files
141
- // testMatch: [
142
- // "**/__tests__/**/*.[jt]s?(x)",
143
- // "**/?(*.)+(spec|test).[tj]s?(x)"
144
- // ],
145
-
146
- // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
147
- // testPathIgnorePatterns: [
148
- // "/node_modules/"
149
- // ],
150
-
151
- // The regexp pattern or array of patterns that Jest uses to detect test files
152
- // testRegex: [],
153
-
154
- // This option allows the use of a custom results processor
155
- // testResultsProcessor: null,
156
-
157
- // This option allows use of a custom test runner
158
- // testRunner: "jasmine2",
159
-
160
- // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
161
- // testURL: "http://localhost",
162
-
163
- // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
164
- // timers: "real",
165
-
166
- // A map from regular expressions to paths to transformers
167
- // transform: null,
168
-
169
- // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
170
- // transformIgnorePatterns: [
171
- // "/node_modules/"
172
- // ],
173
-
174
- // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
175
- // unmockedModulePathPatterns: undefined,
176
-
177
- // Indicates whether each individual test should be reported during the run
178
- // verbose: null,
179
-
180
- // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
181
- // watchPathIgnorePatterns: [],
182
-
183
- // Whether to use watchman for file crawling
184
- // watchman: true,
185
- };
@@ -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
- }
@@ -1,5 +0,0 @@
1
- const create = require('./create');
2
-
3
- test('should be tested', () => {
4
- throw new Error('create.js is not yet tested');
5
- });
@@ -1,5 +0,0 @@
1
- const directory = require('./directory');
2
-
3
- test('should be tested', () => {
4
- throw new Error('directory.js is not yet tested');
5
- });
@@ -1,5 +0,0 @@
1
- const file = require('./file');
2
-
3
- test('should be tested', () => {
4
- throw new Error('file.js is not yet tested');
5
- });
@@ -1,5 +0,0 @@
1
- const node = require('./node');
2
-
3
- test('should be tested', () => {
4
- throw new Error('node.js is not yet tested');
5
- });
@@ -1,82 +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.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 jsTemplate = path.join(rootPath, 'template.js');
68
- const tsTemplate = path.join(rootPath, 'template.ts');
69
- if (fs.existsSync(jsTemplate)) {
70
- return jsTemplate;
71
- }
72
- if (fs.existsSync(tsTemplate)) {
73
- try {
74
- require('ts-node').register();
75
- }
76
- catch (err) {
77
- console.warn('Detected template.ts, but ts-node failed to register:', err);
78
- }
79
- return tsTemplate;
80
- }
81
- return null;
82
- }
@@ -1,5 +0,0 @@
1
- const root = require('./root');
2
-
3
- test('should be tested', () => {
4
- throw new Error('root.js is not yet tested');
5
- });