create-gasket-app 7.0.0-next.2 → 7.0.0-next.20
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/lib/commands/create.js +40 -85
- package/lib/config/default-plugins.js +6 -6
- package/lib/config/utils.js +32 -0
- package/lib/index.d.ts +74 -24
- package/lib/index.js +7 -6
- package/lib/main.js +5 -4
- package/lib/scaffold/action-wrapper.js +5 -6
- package/lib/scaffold/actions/create-hooks.js +7 -9
- package/lib/scaffold/actions/generate-files.js +17 -15
- package/lib/scaffold/actions/global-prompts.js +10 -25
- package/lib/scaffold/actions/index.js +18 -21
- package/lib/scaffold/actions/install-modules.js +3 -6
- package/lib/scaffold/actions/link-modules.js +3 -5
- package/lib/scaffold/actions/load-preset.js +50 -72
- package/lib/scaffold/actions/mkdir.js +4 -4
- package/lib/scaffold/actions/post-create-hooks.js +5 -8
- package/lib/scaffold/actions/preset-config-hooks.js +13 -0
- package/lib/scaffold/actions/preset-prompt-hooks.js +17 -0
- package/lib/scaffold/actions/print-report.js +8 -7
- package/lib/scaffold/actions/prompt-hooks.js +9 -57
- package/lib/scaffold/actions/setup-pkg.js +17 -29
- package/lib/scaffold/actions/write-gasket-config.js +102 -17
- package/lib/scaffold/actions/write-pkg.js +6 -7
- package/lib/scaffold/config-builder.js +82 -7
- package/lib/scaffold/create-context.js +15 -21
- package/lib/scaffold/dump-error-context.js +5 -5
- package/lib/scaffold/files.js +2 -2
- package/lib/scaffold/utils.js +4 -97
- package/lib/utils/create-option.js +2 -4
- package/lib/utils/index.js +6 -16
- package/lib/utils/logo.js +1 -3
- package/lib/utils/process-args.js +1 -3
- package/lib/utils/process-command.js +3 -7
- package/lib/utils/process-options.js +1 -3
- package/lib/utils/warn-if-outdated.js +11 -9
- package/package.json +13 -11
- package/lib/scaffold/actions/apply-preset-config.js +0 -29
- package/lib/scaffold/actions/cli-version.js +0 -84
- package/lib/scaffold/actions/load-pkg-for-debug.js +0 -24
- package/lib/scaffold/create-engine.js +0 -21
- package/lib/scaffold/fetcher.js +0 -194
- package/lib/utils/setup.js +0 -25
package/lib/commands/create.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/* eslint-disable max-statements, no-unused-vars */
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { makeCreateContext } from '../scaffold/create-context.js';
|
|
4
|
+
import { dumpErrorContext } from '../scaffold/dump-error-context.js';
|
|
5
|
+
import { rm } from 'fs/promises';
|
|
6
|
+
import { makeGasket } from '@gasket/core';
|
|
7
|
+
import { defaultPlugins } from '../config/default-plugins.js';
|
|
8
|
+
import {
|
|
9
9
|
createHooks,
|
|
10
10
|
generateFiles,
|
|
11
11
|
globalPrompts,
|
|
12
12
|
installModules,
|
|
13
13
|
linkModules,
|
|
14
|
-
loadPkgForDebug,
|
|
15
14
|
loadPreset,
|
|
16
15
|
mkDir,
|
|
17
16
|
postCreateHooks,
|
|
18
17
|
printReport,
|
|
18
|
+
presetPromptHooks,
|
|
19
|
+
presetConfigHooks,
|
|
19
20
|
promptHooks,
|
|
20
21
|
setupPkg,
|
|
21
22
|
writeGasketConfig,
|
|
22
23
|
writePkg
|
|
23
|
-
}
|
|
24
|
+
} from '../scaffold/actions/index.js';
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Parses comma separated option input to array
|
|
@@ -49,13 +50,6 @@ const createCommand = {
|
|
|
49
50
|
Or other (multiple) custom presets (e.g. --presets my-gasket-preset@1.0.0.beta-1,nextjs@^1.0.0)`,
|
|
50
51
|
parse: commasToArray
|
|
51
52
|
},
|
|
52
|
-
{
|
|
53
|
-
name: 'plugins',
|
|
54
|
-
description: `Additional plugin(s) to install. Can be set as
|
|
55
|
-
multiple flags (e.g. --plugins jest --plugins zkconfig@^1.0.0)
|
|
56
|
-
comma-separated values: --plugins=jest,zkconfig^1.0.0`,
|
|
57
|
-
parse: commasToArray
|
|
58
|
-
},
|
|
59
53
|
{
|
|
60
54
|
name: 'package-manager',
|
|
61
55
|
description: `Selects which package manager you would like to use during
|
|
@@ -67,18 +61,6 @@ const createCommand = {
|
|
|
67
61
|
description: 'Require module(s) before Gasket is initialized',
|
|
68
62
|
parse: commasToArray
|
|
69
63
|
},
|
|
70
|
-
{
|
|
71
|
-
name: 'no-bootstrap',
|
|
72
|
-
description: '(INTERNAL) If provided, skip the bootstrap phase',
|
|
73
|
-
type: 'boolean',
|
|
74
|
-
hidden: true
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
name: 'no-generate',
|
|
78
|
-
description: '(INTERNAL) If provided, skip the generate phase',
|
|
79
|
-
type: 'boolean',
|
|
80
|
-
hidden: true
|
|
81
|
-
},
|
|
82
64
|
{
|
|
83
65
|
name: 'npm-link',
|
|
84
66
|
description: `(INTERNAL) Local packages to be linked. Can be set as
|
|
@@ -105,46 +87,14 @@ const createCommand = {
|
|
|
105
87
|
conflicts: ['config']
|
|
106
88
|
},
|
|
107
89
|
{
|
|
108
|
-
name: 'prompts',
|
|
90
|
+
name: 'no-prompts',
|
|
109
91
|
description: '(INTERNAL) Disable to skip the prompts',
|
|
110
|
-
default: true,
|
|
111
92
|
type: 'boolean',
|
|
112
93
|
hidden: true
|
|
113
94
|
}
|
|
114
95
|
]
|
|
115
96
|
};
|
|
116
97
|
|
|
117
|
-
/**
|
|
118
|
-
* bootstrap - Bootstrap the application
|
|
119
|
-
* @param {CreateContext} context - Create context
|
|
120
|
-
*/
|
|
121
|
-
async function bootstrapHandler(context) {
|
|
122
|
-
await loadPreset(context);
|
|
123
|
-
cliVersion(context);
|
|
124
|
-
applyPresetConfig(context);
|
|
125
|
-
await globalPrompts(context);
|
|
126
|
-
await mkDir(context);
|
|
127
|
-
await setupPkg(context);
|
|
128
|
-
await writePkg(context);
|
|
129
|
-
await installModules(context);
|
|
130
|
-
await linkModules(context);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* generate - Generate the application
|
|
135
|
-
* @param {CreateContext} context - Create context
|
|
136
|
-
*/
|
|
137
|
-
async function generateHandler(context) {
|
|
138
|
-
await promptHooks(context);
|
|
139
|
-
await createHooks(context);
|
|
140
|
-
await generateFiles(context);
|
|
141
|
-
await writeGasketConfig(context);
|
|
142
|
-
await writePkg.update(context);
|
|
143
|
-
await installModules.update(context);
|
|
144
|
-
await linkModules.update(context); // relink any that were messed up by re-install
|
|
145
|
-
await postCreateHooks(context);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
98
|
/**
|
|
149
99
|
* createCommand action
|
|
150
100
|
* @param {string} appname Required cmd arg - name of the app to create
|
|
@@ -153,35 +103,40 @@ async function generateHandler(context) {
|
|
|
153
103
|
* @returns {Promise<void>} void
|
|
154
104
|
*/
|
|
155
105
|
createCommand.action = async function run(appname, options, command) {
|
|
156
|
-
const
|
|
157
|
-
const {
|
|
106
|
+
const context = makeCreateContext([appname], options);
|
|
107
|
+
const { rawPresets, localPresets } = context;
|
|
158
108
|
|
|
159
|
-
let context;
|
|
160
109
|
try {
|
|
161
|
-
|
|
162
|
-
} catch (error) {
|
|
163
|
-
console.error(chalk.red(error) + '\n');
|
|
164
|
-
command.help();
|
|
165
|
-
}
|
|
110
|
+
await globalPrompts(null, context);
|
|
166
111
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
await loadPkgForDebug(context);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
112
|
+
if (rawPresets.length || localPresets.length) {
|
|
113
|
+
await loadPreset(null, context);
|
|
114
|
+
|
|
115
|
+
const presetGasket = makeGasket({
|
|
116
|
+
plugins: context.presets
|
|
117
|
+
});
|
|
176
118
|
|
|
177
|
-
|
|
178
|
-
await
|
|
179
|
-
} else {
|
|
180
|
-
ora('Generate phase skipped.').warn();
|
|
119
|
+
await presetPromptHooks(presetGasket, context);
|
|
120
|
+
await presetConfigHooks(presetGasket, context);
|
|
181
121
|
}
|
|
182
122
|
|
|
183
|
-
|
|
123
|
+
const pluginGasket = makeGasket({
|
|
124
|
+
...context.presetConfig,
|
|
125
|
+
plugins: context.presets.concat(context.presetConfig.plugins, defaultPlugins)
|
|
126
|
+
});
|
|
184
127
|
|
|
128
|
+
await promptHooks(pluginGasket, context);
|
|
129
|
+
await mkDir(null, context);
|
|
130
|
+
await setupPkg(null, context);
|
|
131
|
+
await createHooks(pluginGasket, context);
|
|
132
|
+
await writePkg(null, context);
|
|
133
|
+
await generateFiles(null, context);
|
|
134
|
+
await writeGasketConfig(null, context);
|
|
135
|
+
await installModules(null, context);
|
|
136
|
+
await linkModules(null, context);
|
|
137
|
+
await postCreateHooks(pluginGasket, context);
|
|
138
|
+
if (context.tmpDir) await rm(context.tmpDir, { recursive: true });
|
|
139
|
+
printReport(null, context);
|
|
185
140
|
} catch (err) {
|
|
186
141
|
console.error(chalk.red('Exiting with errors.'));
|
|
187
142
|
dumpErrorContext(context, err);
|
|
@@ -189,4 +144,4 @@ createCommand.action = async function run(appname, options, command) {
|
|
|
189
144
|
}
|
|
190
145
|
};
|
|
191
146
|
|
|
192
|
-
|
|
147
|
+
export { createCommand };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import pluginGit from '@gasket/plugin-git';
|
|
2
|
+
import pluginLogger from '@gasket/plugin-logger';
|
|
3
|
+
|
|
4
|
+
export const defaultPlugins = [
|
|
5
|
+
pluginLogger,
|
|
6
|
+
pluginGit
|
|
7
7
|
];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { default as diagnostics } from 'diagnostics';
|
|
2
|
+
const debug = diagnostics('gasket:cli:config:utils');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns specified env option if set or appropriate fallback
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} options - CLI Option
|
|
8
|
+
* @param {string} commandId - Name of the command
|
|
9
|
+
* @param {function} warn - Warning logger
|
|
10
|
+
* @returns {string} environment
|
|
11
|
+
*/
|
|
12
|
+
export function getEnvironment(options, commandId, warn) {
|
|
13
|
+
if (options.env) {
|
|
14
|
+
debug('Environment was passed through command line options', options.env);
|
|
15
|
+
return options.env;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// special snowflake case to match up `local` env with command unless set
|
|
19
|
+
if (commandId === 'local') {
|
|
20
|
+
debug('Environment defaulting to `local` due to `local` command');
|
|
21
|
+
return 'local';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { NODE_ENV } = process.env;
|
|
25
|
+
if (NODE_ENV) {
|
|
26
|
+
warn(`No env specified, falling back to NODE_ENV: "${ NODE_ENV }".`);
|
|
27
|
+
return NODE_ENV;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
warn('No env specified, falling back to "development".');
|
|
31
|
+
return 'development';
|
|
32
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -62,6 +62,72 @@ export interface ConfigBuilder<Config> {
|
|
|
62
62
|
value: Config[Key],
|
|
63
63
|
options?: { force?: boolean }
|
|
64
64
|
): void;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* addPlugin - Add plugin import to the gasket file and use the value in the plugins array
|
|
68
|
+
* @param {string} pluginImport - name of the import used as a value - `import pluginImport...`
|
|
69
|
+
* @param {string} pluginName - name of the plugin import/package - `from 'pluginName'`
|
|
70
|
+
* @example
|
|
71
|
+
* addPlugin('pluginA', '@gasket/plugin-a')
|
|
72
|
+
*
|
|
73
|
+
* // gasket.js
|
|
74
|
+
* import pluginA from '@gasket/plugin-a';
|
|
75
|
+
*
|
|
76
|
+
* export default makeGasket({
|
|
77
|
+
* plugins: [
|
|
78
|
+
* pluginA
|
|
79
|
+
* ]
|
|
80
|
+
* });
|
|
81
|
+
*/
|
|
82
|
+
addPlugin(pluginImport: string, pluginName: string): void;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* addImport - Add a non-plugin import to the gasket file
|
|
86
|
+
* @param {string} importName - name of the import used as a value - `import fs...`
|
|
87
|
+
* @param {string} importPath - path of the import - `from 'fs'`
|
|
88
|
+
* @returns {ConfigBuilder} - instance for chaining
|
|
89
|
+
* @example
|
|
90
|
+
* Can be default or named import
|
|
91
|
+
* addImport('{ readFileSync }', 'fs')
|
|
92
|
+
* addImport('fs', 'fs')
|
|
93
|
+
*
|
|
94
|
+
* // gasket.js
|
|
95
|
+
* import { readFileSync } from 'fs';
|
|
96
|
+
* import fs from 'fs';
|
|
97
|
+
*/
|
|
98
|
+
addImport(importName: string, importPath: string): ConfigBuilder;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* addExpression - add programmatic expression to the gasket file
|
|
102
|
+
* @param {string} expression - expression to add after imports
|
|
103
|
+
* @returns {ConfigBuilder} - instance for chaining
|
|
104
|
+
* @example
|
|
105
|
+
*
|
|
106
|
+
* .addImport('fs', 'fs')
|
|
107
|
+
* .addExpression('const file = fs.readFileSync(\'./file.txt\')')
|
|
108
|
+
*
|
|
109
|
+
* // gasket.js
|
|
110
|
+
* import fs from 'fs';
|
|
111
|
+
* const file = fs.readFileSync('./file.txt');
|
|
112
|
+
*/
|
|
113
|
+
addExpression(expression: string): ConfigBuilder;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* injectValue - Inject a value into the gasket config object
|
|
117
|
+
* @param {string} configKey - collapsed object path to inject value into - `express.config.routes`
|
|
118
|
+
* @param {string} injectedValue - string used as a value
|
|
119
|
+
* @example
|
|
120
|
+
* .addImport('{ routes }', './routes')
|
|
121
|
+
* .injectValue('express.routes', 'routes');
|
|
122
|
+
*
|
|
123
|
+
* // gasket.js
|
|
124
|
+
* export default makeGasket({
|
|
125
|
+
* express: {
|
|
126
|
+
* routes: routes
|
|
127
|
+
* }
|
|
128
|
+
* });
|
|
129
|
+
*/
|
|
130
|
+
injectValue(configKey: string, injectedValue: any): void;
|
|
65
131
|
}
|
|
66
132
|
|
|
67
133
|
export interface PackageJsonBuilder extends ConfigBuilder<PackageJson> {
|
|
@@ -101,12 +167,6 @@ export interface CreateContext {
|
|
|
101
167
|
* load-preset if using localPresets. */
|
|
102
168
|
rawPresets: Array<string>;
|
|
103
169
|
|
|
104
|
-
/** Raw plugin desc from flags, prompts, etc. Can include constraints. */
|
|
105
|
-
rawPlugins: Array<string>;
|
|
106
|
-
|
|
107
|
-
/** Short names of plugins */
|
|
108
|
-
plugins: Array<string>;
|
|
109
|
-
|
|
110
170
|
/** Local packages that should be linked */
|
|
111
171
|
pkgLinks: Array<string>;
|
|
112
172
|
|
|
@@ -125,6 +185,12 @@ export interface CreateContext {
|
|
|
125
185
|
/** any generated files to show in report */
|
|
126
186
|
generatedFiles: Set<string>;
|
|
127
187
|
|
|
188
|
+
/** Default empty array, populated by load-preset with actual imports */
|
|
189
|
+
presets: Array<any>;
|
|
190
|
+
|
|
191
|
+
/** Default to object w/empty plugins array to be populated by `presetConfig` hook */
|
|
192
|
+
presetConfig: GasketConfigDefinition;
|
|
193
|
+
|
|
128
194
|
// Added by `global-prompts`
|
|
129
195
|
|
|
130
196
|
/** Description of app */
|
|
@@ -148,23 +214,6 @@ export interface CreateContext {
|
|
|
148
214
|
/** Whether or not the user wants to override an extant directory */
|
|
149
215
|
destOverride: boolean;
|
|
150
216
|
|
|
151
|
-
// Added by `load-preset`
|
|
152
|
-
|
|
153
|
-
/** Short name of presets */
|
|
154
|
-
presets: Array<string>;
|
|
155
|
-
|
|
156
|
-
/** Shallow load of presets with meta data */
|
|
157
|
-
presetInfos: Array<PresetInfo>;
|
|
158
|
-
|
|
159
|
-
// Added by `cli-version`
|
|
160
|
-
|
|
161
|
-
/** Version of current CLI used to issue `create` command */
|
|
162
|
-
cliVersion: string;
|
|
163
|
-
|
|
164
|
-
/** Version of CLI to install, either current or min compatible version
|
|
165
|
-
* required by preset(s) */
|
|
166
|
-
cliVersionRequired: string;
|
|
167
|
-
|
|
168
217
|
// Added by `setup-pkg`
|
|
169
218
|
|
|
170
219
|
/** package.json builder */
|
|
@@ -186,11 +235,12 @@ export interface CreateContext {
|
|
|
186
235
|
|
|
187
236
|
declare module '@gasket/engine' {
|
|
188
237
|
export interface HookExecTypes {
|
|
238
|
+
presetPrompt(context: CreateContext): Promise<void>;
|
|
239
|
+
presetConfig(context: CreateContext): Promise<void>;
|
|
189
240
|
prompt(
|
|
190
241
|
context: CreateContext,
|
|
191
242
|
utils: {
|
|
192
243
|
prompt: (prompts: Array<Record<string, any>>) => Promise<Record<string, any>>,
|
|
193
|
-
addPlugins: (plugins: Array<string>) => Promise<void>
|
|
194
244
|
}
|
|
195
245
|
): MaybeAsync<CreateContext>;
|
|
196
246
|
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import { createCommand } from './commands/create.js';
|
|
5
|
+
import { processCommand, logo, warnIfOutdated } from './utils/index.js';
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
3
8
|
const pkg = require('../package.json');
|
|
4
|
-
const { Command } = require('commander');
|
|
5
9
|
const program = new Command();
|
|
6
|
-
const CreateCommand = require('./commands/create');
|
|
7
|
-
|
|
8
|
-
const { processCommand, logo, warnIfOutdated } = require('./utils');
|
|
9
10
|
|
|
10
11
|
// Create Gasket CLI
|
|
11
12
|
const gasketBin = program
|
|
@@ -17,7 +18,7 @@ const gasketBin = program
|
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
async function main() {
|
|
20
|
-
const { command, hidden, isDefault } = processCommand(
|
|
21
|
+
const { command, hidden, isDefault } = processCommand(createCommand);
|
|
21
22
|
await warnIfOutdated(pkg.name, pkg.version);
|
|
22
23
|
gasketBin.addCommand(command, { hidden, isDefault });
|
|
23
24
|
|
package/lib/main.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { fork } from 'child_process';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Executes the @gasket/cli passing through the create command and any arguments.
|
|
@@ -6,7 +8,8 @@ const { fork } = require('child_process');
|
|
|
6
8
|
* @param {string[]} args - create command arguments
|
|
7
9
|
* @returns {ChildProcess} process
|
|
8
10
|
*/
|
|
9
|
-
function main(...args) {
|
|
11
|
+
export default function main(...args) {
|
|
12
|
+
// import.meta.resolve is not available in Jest without babel transform
|
|
10
13
|
const gasketBin = require.resolve('@gasket/cli/bin/run');
|
|
11
14
|
|
|
12
15
|
return fork(
|
|
@@ -15,5 +18,3 @@ function main(...args) {
|
|
|
15
18
|
{ stdio: 'inherit', stdin: 'inherit', stderr: 'inherit' }
|
|
16
19
|
);
|
|
17
20
|
}
|
|
18
|
-
|
|
19
|
-
module.exports = main;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import ora from 'ora';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Decorate a create action with spinner.
|
|
@@ -10,19 +10,18 @@ const ora = require('ora');
|
|
|
10
10
|
* @param {Boolean} startSpinner - Should the spinner start
|
|
11
11
|
* @returns {Function} decorated action
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
export default function withSpinner(label, fn, { startSpinner = true } = {}) {
|
|
15
14
|
/**
|
|
16
15
|
* Decorated function
|
|
17
16
|
*
|
|
18
17
|
* @param {CreateContext} context - Create context
|
|
19
18
|
* @returns {Promise} promise
|
|
20
19
|
*/
|
|
21
|
-
async function wrapper(context) {
|
|
20
|
+
async function wrapper(gasket = {}, context) {
|
|
22
21
|
const spinner = ora(label);
|
|
23
22
|
if (startSpinner) spinner.start();
|
|
24
23
|
try {
|
|
25
|
-
await fn(context, spinner);
|
|
24
|
+
await fn(gasket, context, spinner);
|
|
26
25
|
if (spinner.isSpinning) spinner.succeed();
|
|
27
26
|
} catch (err) {
|
|
28
27
|
spinner.fail();
|
|
@@ -33,4 +32,4 @@ module.exports = function withSpinner(label, fn, { startSpinner = true } = {}) {
|
|
|
33
32
|
|
|
34
33
|
wrapper.wrapped = fn;
|
|
35
34
|
return wrapper;
|
|
36
|
-
}
|
|
35
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const Files = require('../files');
|
|
1
|
+
import action from '../action-wrapper.js';
|
|
2
|
+
import { ConfigBuilder } from '../config-builder.js';
|
|
3
|
+
import { Files } from '../files.js';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Executes the `create` hook for all registered plugins.
|
|
@@ -10,17 +9,16 @@ const Files = require('../files');
|
|
|
10
9
|
* @param {CreateContext} context - Create context
|
|
11
10
|
* @returns {Promise} promise
|
|
12
11
|
*/
|
|
13
|
-
async function createHooks(context) {
|
|
14
|
-
const {
|
|
12
|
+
async function createHooks(gasket, context) {
|
|
13
|
+
const { plugins = [], warnings } = context;
|
|
15
14
|
|
|
16
15
|
const files = new Files();
|
|
17
|
-
const gasketConfig = ConfigBuilder.create({}, { orderBy: ['plugins'], warnings });
|
|
16
|
+
const gasketConfig = ConfigBuilder.create({}, { orderBy: ['plugins'], warnings, plugins });
|
|
18
17
|
Object.assign(context, { files, gasketConfig });
|
|
19
18
|
|
|
20
|
-
const gasket = await createEngine({ dest, presets, plugins });
|
|
21
19
|
await gasket.execApply('create', async function applyCreate(plugin, handler) {
|
|
22
20
|
await handler(context.runWith(plugin));
|
|
23
21
|
});
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
export default action('Execute create hooks', createHooks);
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
const debug =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { default as diagnostics } from 'diagnostics';
|
|
2
|
+
const debug = diagnostics('gasket:cli:generate-files');
|
|
3
|
+
import fs from 'fs/promises';
|
|
4
|
+
import { promisify } from 'util';
|
|
5
|
+
import Handlebars from 'handlebars';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import mkdirp from 'mkdirp';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
const { dim } = chalk;
|
|
10
|
+
import action from '../action-wrapper.js';
|
|
11
|
+
import * as syncGlob from 'glob';
|
|
12
|
+
const glob = promisify(syncGlob.default);
|
|
13
|
+
|
|
12
14
|
const flatten = (acc, values) => (acc || []).concat(values);
|
|
13
15
|
const reSep = /[/\\]+/;
|
|
14
16
|
const joinSep = pthArr => pthArr.join(path.sep);
|
|
@@ -162,7 +164,7 @@ async function performGenerate(context, descriptors) {
|
|
|
162
164
|
* @param {Spinner} spinner - Spinner
|
|
163
165
|
* @returns {Promise} promise
|
|
164
166
|
*/
|
|
165
|
-
async function generateFiles(context, spinner) {
|
|
167
|
+
async function generateFiles(_, context, spinner) {
|
|
166
168
|
const { files } = context;
|
|
167
169
|
|
|
168
170
|
if (!files.globSets.length) {
|
|
@@ -177,7 +179,7 @@ async function generateFiles(context, spinner) {
|
|
|
177
179
|
if (hasError) spinner.fail();
|
|
178
180
|
}
|
|
179
181
|
|
|
180
|
-
|
|
182
|
+
export default action('Generate app contents', generateFiles);
|
|
181
183
|
// exported for unit testing
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
export const _getDescriptors = getDescriptors;
|
|
185
|
+
export const _assembleDescriptors = assembleDescriptors;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const action = require('../action-wrapper');
|
|
4
|
-
const { addPluginsToContext } = require('../utils');
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import action from '../action-wrapper.js';
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* What is your app description?
|
|
@@ -70,20 +68,10 @@ async function choosePackageManager(context, prompt) {
|
|
|
70
68
|
* @returns {Promise} promise
|
|
71
69
|
*/
|
|
72
70
|
async function chooseTestPlugin(context, prompt) {
|
|
73
|
-
|
|
74
|
-
const { presetInfos = [], plugins = [] } = context;
|
|
75
|
-
|
|
76
|
-
// Flatten all plugins from presets and concat short names with cli plugins
|
|
77
|
-
const allPlugins = flattenPresets(presetInfos)
|
|
78
|
-
.map((presetInfo) => presetInfo.plugins || [])
|
|
79
|
-
.reduce((acc, arr) => acc.concat(arr), [])
|
|
80
|
-
.map((pluginInfo) => pluginIdentifier(pluginInfo.name).shortName)
|
|
81
|
-
.concat(plugins);
|
|
82
|
-
|
|
83
|
-
const knownTestPlugins = { mocha: '@gasket/mocha', jest: '@gasket/jest', cypress: '@gasket/cypress' };
|
|
71
|
+
const knownTestPlugins = { mocha: '@gasket/plugin-mocha', jest: '@gasket/plugin-jest', cypress: '@gasket/plugin-cypress' };
|
|
84
72
|
|
|
85
73
|
if (!('testPlugin' in context)) {
|
|
86
|
-
let testPlugin
|
|
74
|
+
let testPlugin;
|
|
87
75
|
|
|
88
76
|
if ('testSuite' in context) {
|
|
89
77
|
testPlugin = knownTestPlugins[context.testSuite];
|
|
@@ -97,16 +85,15 @@ async function chooseTestPlugin(context, prompt) {
|
|
|
97
85
|
type: 'list',
|
|
98
86
|
choices: [
|
|
99
87
|
{ name: 'none (not recommended)', value: 'none' },
|
|
100
|
-
{ name: 'mocha + nyc + sinon + chai', value: '@gasket/mocha' },
|
|
101
|
-
{ name: 'jest', value: '@gasket/jest' },
|
|
102
|
-
{ name: 'cypress', value: '@gasket/cypress' }
|
|
88
|
+
{ name: 'mocha + nyc + sinon + chai', value: '@gasket/plugin-mocha' },
|
|
89
|
+
{ name: 'jest', value: '@gasket/plugin-jest' },
|
|
90
|
+
{ name: 'cypress', value: '@gasket/plugin-cypress' }
|
|
103
91
|
]
|
|
104
92
|
}
|
|
105
93
|
]));
|
|
106
94
|
}
|
|
107
95
|
|
|
108
96
|
if (testPlugin && testPlugin !== 'none') {
|
|
109
|
-
addPluginsToContext([testPlugin], context);
|
|
110
97
|
Object.assign(context, { testPlugin });
|
|
111
98
|
}
|
|
112
99
|
}
|
|
@@ -136,7 +123,7 @@ async function allowExtantOverwriting(context, prompt) {
|
|
|
136
123
|
}
|
|
137
124
|
}
|
|
138
125
|
|
|
139
|
-
const questions = [
|
|
126
|
+
export const questions = [
|
|
140
127
|
chooseAppDescription,
|
|
141
128
|
choosePackageManager,
|
|
142
129
|
chooseTestPlugin,
|
|
@@ -149,13 +136,11 @@ const questions = [
|
|
|
149
136
|
* @param {CreateContext} context - Create context
|
|
150
137
|
* @returns {Promise} promise
|
|
151
138
|
*/
|
|
152
|
-
async function globalPrompts(context) {
|
|
139
|
+
async function globalPrompts(_, context) {
|
|
153
140
|
const prompt = context.prompts ? inquirer.prompt : () => ({});
|
|
154
141
|
for (var fn of questions) {
|
|
155
142
|
await fn(context, prompt);
|
|
156
143
|
}
|
|
157
144
|
}
|
|
158
145
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
module.exports.questions = questions;
|
|
146
|
+
export default action('Global prompts', globalPrompts, { startSpinner: false });
|
|
@@ -1,36 +1,33 @@
|
|
|
1
|
+
import mkDir from './mkdir.js';
|
|
2
|
+
import loadPreset from './load-preset.js';
|
|
3
|
+
import globalPrompts from './global-prompts.js';
|
|
4
|
+
import setupPkg from './setup-pkg.js';
|
|
5
|
+
import writePkg from './write-pkg.js';
|
|
6
|
+
import installModules from './install-modules.js';
|
|
7
|
+
import linkModules from './link-modules.js';
|
|
8
|
+
import writeGasketConfig from './write-gasket-config.js';
|
|
9
|
+
import presetPromptHooks from './preset-prompt-hooks.js';
|
|
10
|
+
import presetConfigHooks from './preset-config-hooks.js';
|
|
11
|
+
import promptHooks from './prompt-hooks.js';
|
|
12
|
+
import createHooks from './create-hooks.js';
|
|
13
|
+
import generateFiles from './generate-files.js';
|
|
14
|
+
import postCreateHooks from './post-create-hooks.js';
|
|
15
|
+
import printReport from './print-report.js';
|
|
1
16
|
|
|
2
|
-
|
|
3
|
-
const loadPreset = require('./load-preset');
|
|
4
|
-
const cliVersion = require('./cli-version');
|
|
5
|
-
const globalPrompts = require('./global-prompts');
|
|
6
|
-
const setupPkg = require('./setup-pkg');
|
|
7
|
-
const writePkg = require('./write-pkg');
|
|
8
|
-
const installModules = require('./install-modules');
|
|
9
|
-
const linkModules = require('./link-modules');
|
|
10
|
-
const writeGasketConfig = require('./write-gasket-config');
|
|
11
|
-
const loadPkgForDebug = require('./load-pkg-for-debug');
|
|
12
|
-
const promptHooks = require('./prompt-hooks');
|
|
13
|
-
const createHooks = require('./create-hooks');
|
|
14
|
-
const generateFiles = require('./generate-files');
|
|
15
|
-
const postCreateHooks = require('./post-create-hooks');
|
|
16
|
-
const applyPresetConfig = require('./apply-preset-config');
|
|
17
|
-
const printReport = require('./print-report');
|
|
18
|
-
|
|
19
|
-
module.exports = {
|
|
17
|
+
export {
|
|
20
18
|
mkDir,
|
|
21
19
|
loadPreset,
|
|
22
|
-
cliVersion,
|
|
23
20
|
globalPrompts,
|
|
24
21
|
setupPkg,
|
|
25
22
|
writePkg,
|
|
26
23
|
installModules,
|
|
27
24
|
linkModules,
|
|
28
25
|
writeGasketConfig,
|
|
29
|
-
|
|
26
|
+
presetPromptHooks,
|
|
27
|
+
presetConfigHooks,
|
|
30
28
|
promptHooks,
|
|
31
29
|
createHooks,
|
|
32
30
|
postCreateHooks,
|
|
33
31
|
generateFiles,
|
|
34
|
-
applyPresetConfig,
|
|
35
32
|
printReport
|
|
36
33
|
};
|