create-gasket-app 7.0.0-next.4 → 7.0.0-next.41
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 +34 -23
- package/lib/config/default-plugins.js +9 -1
- package/lib/index.d.ts +101 -48
- package/lib/index.js +3 -2
- package/lib/scaffold/action-wrapper.js +6 -4
- package/lib/scaffold/actions/create-hooks.js +3 -3
- package/lib/scaffold/actions/generate-files.js +1 -1
- package/lib/scaffold/actions/global-prompts.js +39 -42
- package/lib/scaffold/actions/index.js +3 -12
- package/lib/scaffold/actions/install-modules.js +1 -4
- package/lib/scaffold/actions/link-modules.js +1 -3
- package/lib/scaffold/actions/load-preset.js +35 -11
- package/lib/scaffold/actions/mkdir.js +1 -1
- package/lib/scaffold/actions/post-create-hooks.js +3 -3
- package/lib/scaffold/actions/preset-config-hooks.js +6 -6
- package/lib/scaffold/actions/preset-prompt-hooks.js +6 -2
- package/lib/scaffold/actions/print-report.js +1 -1
- package/lib/scaffold/actions/prompt-hooks.js +5 -48
- package/lib/scaffold/actions/setup-pkg.js +11 -22
- package/lib/scaffold/actions/write-gasket-config.js +37 -4
- package/lib/scaffold/actions/write-pkg.js +1 -4
- package/lib/scaffold/config-builder.js +58 -2
- package/lib/scaffold/create-context.js +10 -13
- package/lib/scaffold/dump-error-context.js +3 -3
- package/lib/scaffold/files.js +1 -1
- package/lib/scaffold/utils.js +2 -87
- package/lib/utils/index.js +1 -2
- package/lib/utils/process-command.js +3 -1
- package/package.json +19 -14
- package/lib/config/utils.js +0 -59
- package/lib/main.js +0 -19
- package/lib/scaffold/actions/apply-preset-config.js +0 -29
- package/lib/scaffold/actions/cli-version.js +0 -88
- 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/warn-if-outdated.js +0 -76
package/lib/commands/create.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
1
|
+
/* eslint-disable max-statements, no-unused-vars */
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { makeCreateContext } from '../scaffold/create-context.js';
|
|
4
4
|
import { dumpErrorContext } from '../scaffold/dump-error-context.js';
|
|
@@ -87,51 +87,62 @@ const createCommand = {
|
|
|
87
87
|
conflicts: ['config']
|
|
88
88
|
},
|
|
89
89
|
{
|
|
90
|
-
name: 'prompts',
|
|
90
|
+
name: 'no-prompts',
|
|
91
91
|
description: '(INTERNAL) Disable to skip the prompts',
|
|
92
|
-
default: true,
|
|
93
92
|
type: 'boolean',
|
|
94
93
|
hidden: true
|
|
95
94
|
}
|
|
96
95
|
]
|
|
97
96
|
};
|
|
98
97
|
|
|
98
|
+
/**
|
|
99
|
+
* createCommand action
|
|
100
|
+
* @param {string} appname Required cmd arg - name of the app to create
|
|
101
|
+
* @param {object} options cmd options
|
|
102
|
+
* @param {Command} command - the command instance
|
|
103
|
+
* @returns {Promise<void>} void
|
|
104
|
+
*/
|
|
99
105
|
createCommand.action = async function run(appname, options, command) {
|
|
106
|
+
process.env.GASKET_ENV = 'create';
|
|
100
107
|
const context = makeCreateContext([appname], options);
|
|
108
|
+
const { rawPresets, localPresets } = context;
|
|
101
109
|
|
|
102
110
|
try {
|
|
103
|
-
await
|
|
104
|
-
await globalPrompts(null, context);
|
|
111
|
+
await globalPrompts({ context });
|
|
105
112
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
});
|
|
113
|
+
if (rawPresets.length || localPresets.length) {
|
|
114
|
+
await loadPreset({ context });
|
|
109
115
|
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
const presetGasket = makeGasket({
|
|
117
|
+
plugins: context.presets
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
await presetPromptHooks({ gasket: presetGasket, context });
|
|
121
|
+
await presetConfigHooks({ gasket: presetGasket, context });
|
|
122
|
+
}
|
|
112
123
|
|
|
113
124
|
const pluginGasket = makeGasket({
|
|
114
125
|
...context.presetConfig,
|
|
115
126
|
plugins: context.presets.concat(context.presetConfig.plugins, defaultPlugins)
|
|
116
127
|
});
|
|
117
128
|
|
|
118
|
-
await promptHooks(pluginGasket, context);
|
|
119
|
-
await mkDir(
|
|
120
|
-
await setupPkg(
|
|
121
|
-
await createHooks(pluginGasket, context);
|
|
122
|
-
await writePkg(
|
|
123
|
-
await generateFiles(
|
|
124
|
-
await writeGasketConfig(
|
|
125
|
-
await installModules(
|
|
126
|
-
await linkModules(
|
|
127
|
-
await postCreateHooks(pluginGasket, context);
|
|
128
|
-
await rm(context.tmpDir, { recursive: true });
|
|
129
|
-
printReport(context);
|
|
129
|
+
await promptHooks({ gasket: pluginGasket, context });
|
|
130
|
+
await mkDir({ context });
|
|
131
|
+
await setupPkg({ context });
|
|
132
|
+
await createHooks({ gasket: pluginGasket, context });
|
|
133
|
+
await writePkg({ context });
|
|
134
|
+
await generateFiles({ context });
|
|
135
|
+
await writeGasketConfig({ context });
|
|
136
|
+
await installModules({ context });
|
|
137
|
+
await linkModules({ context });
|
|
138
|
+
await postCreateHooks({ gasket: pluginGasket, context });
|
|
139
|
+
if (context.tmpDir) await rm(context.tmpDir, { recursive: true });
|
|
140
|
+
printReport({ context });
|
|
130
141
|
} catch (err) {
|
|
131
142
|
console.error(chalk.red('Exiting with errors.'));
|
|
132
143
|
dumpErrorContext(context, err);
|
|
133
144
|
throw err;
|
|
134
145
|
}
|
|
135
|
-
}
|
|
146
|
+
};
|
|
136
147
|
|
|
137
148
|
export { createCommand };
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import pluginGit from '@gasket/plugin-git';
|
|
2
2
|
import pluginLogger from '@gasket/plugin-logger';
|
|
3
|
+
import pluginMetadata from '@gasket/plugin-metadata';
|
|
4
|
+
import pluginCommand from '@gasket/plugin-command';
|
|
5
|
+
import pluginDocs from '@gasket/plugin-docs';
|
|
6
|
+
import pluginDocusaurus from '@gasket/plugin-docusaurus';
|
|
3
7
|
|
|
4
8
|
export const defaultPlugins = [
|
|
5
9
|
pluginLogger,
|
|
6
|
-
pluginGit
|
|
10
|
+
pluginGit,
|
|
11
|
+
pluginMetadata,
|
|
12
|
+
pluginCommand,
|
|
13
|
+
pluginDocs,
|
|
14
|
+
pluginDocusaurus
|
|
7
15
|
];
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GasketConfigDefinition, MaybeAsync } from '@gasket/
|
|
1
|
+
import type { GasketConfigDefinition, MaybeAsync, Plugin, GasketEngine } from '@gasket/core';
|
|
2
2
|
import type { PackageManager } from '@gasket/utils';
|
|
3
3
|
|
|
4
4
|
export interface Dependencies {
|
|
@@ -9,17 +9,18 @@ export interface Dependencies {
|
|
|
9
9
|
|
|
10
10
|
export interface PackageJson extends Dependencies {
|
|
11
11
|
name: string;
|
|
12
|
-
version
|
|
12
|
+
version?: string;
|
|
13
13
|
description?: string;
|
|
14
14
|
license?: string;
|
|
15
15
|
repository?:
|
|
16
16
|
| string
|
|
17
17
|
| {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
type: 'git';
|
|
19
|
+
url: string;
|
|
20
|
+
};
|
|
21
21
|
scripts?: Record<string, string>;
|
|
22
22
|
optionalDependencies?: Record<string, string>;
|
|
23
|
+
homepage?: string;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export interface ModuleInfo {
|
|
@@ -30,11 +31,9 @@ export interface ModuleInfo {
|
|
|
30
31
|
version?: string;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export interface PresetInfo extends ModuleInfo {
|
|
34
|
-
}
|
|
34
|
+
export interface PresetInfo extends ModuleInfo {}
|
|
35
35
|
|
|
36
|
-
export interface PluginInfo extends ModuleInfo {
|
|
37
|
-
}
|
|
36
|
+
export interface PluginInfo extends ModuleInfo {}
|
|
38
37
|
|
|
39
38
|
export interface ConfigBuilder<Config> {
|
|
40
39
|
/**
|
|
@@ -63,25 +62,85 @@ export interface ConfigBuilder<Config> {
|
|
|
63
62
|
options?: { force?: boolean }
|
|
64
63
|
): void;
|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
/**
|
|
66
|
+
* addPlugin - Add plugin import to the gasket file and use the value in the plugins array
|
|
67
|
+
* @param {string} pluginImport - name of the import used as a value - `import pluginImport...`
|
|
68
|
+
* @param {string} pluginName - name of the plugin import/package - `from 'pluginName'`
|
|
69
|
+
* @example
|
|
70
|
+
* addPlugin('pluginA', '@gasket/plugin-a')
|
|
71
|
+
*
|
|
72
|
+
* // gasket.js
|
|
73
|
+
* import pluginA from '@gasket/plugin-a';
|
|
74
|
+
*
|
|
75
|
+
* export default makeGasket({
|
|
76
|
+
* plugins: [
|
|
77
|
+
* pluginA
|
|
78
|
+
* ]
|
|
79
|
+
* });
|
|
80
|
+
*/
|
|
67
81
|
addPlugin(pluginImport: string, pluginName: string): void;
|
|
68
|
-
addImport(importName: string, importPath: string, isDefault?: boolean): ConfigBuilder;
|
|
69
|
-
useImport(configPath: string, importName: string): void;
|
|
70
82
|
|
|
83
|
+
/**
|
|
84
|
+
* addImport - Add a non-plugin import to the gasket file
|
|
85
|
+
* @param {string} importName - name of the import used as a value - `import fs...`
|
|
86
|
+
* @param {string} importPath - path of the import - `from 'fs'`
|
|
87
|
+
* @returns {ConfigBuilder} - instance for chaining
|
|
88
|
+
* @example
|
|
89
|
+
* Can be default or named import
|
|
90
|
+
* addImport('{ readFileSync }', 'fs')
|
|
91
|
+
* addImport('fs', 'fs')
|
|
92
|
+
*
|
|
93
|
+
* // gasket.js
|
|
94
|
+
* import { readFileSync } from 'fs';
|
|
95
|
+
* import fs from 'fs';
|
|
96
|
+
*/
|
|
97
|
+
addImport(importName: string, importPath: string): ConfigBuilder<Config>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* addExpression - add programmatic expression to the gasket file
|
|
101
|
+
* @param {string} expression - expression to add after imports
|
|
102
|
+
* @returns {ConfigBuilder} - instance for chaining
|
|
103
|
+
* @example
|
|
104
|
+
*
|
|
105
|
+
* .addImport('fs', 'fs')
|
|
106
|
+
* .addExpression('const file = fs.readFileSync(\'./file.txt\')')
|
|
107
|
+
*
|
|
108
|
+
* // gasket.js
|
|
109
|
+
* import fs from 'fs';
|
|
110
|
+
* const file = fs.readFileSync('./file.txt');
|
|
111
|
+
*/
|
|
112
|
+
addExpression(expression: string): ConfigBuilder<Config>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* injectValue - Inject a value into the gasket config object
|
|
116
|
+
* @param {string} configKey - collapsed object path to inject value into - `express.config.routes`
|
|
117
|
+
* @param {string} injectedValue - string used as a value
|
|
118
|
+
* @example
|
|
119
|
+
* .addImport('{ routes }', './routes')
|
|
120
|
+
* .injectValue('express.routes', 'routes');
|
|
121
|
+
*
|
|
122
|
+
* // gasket.js
|
|
123
|
+
* export default makeGasket({
|
|
124
|
+
* express: {
|
|
125
|
+
* routes: routes
|
|
126
|
+
* }
|
|
127
|
+
* });
|
|
128
|
+
*/
|
|
129
|
+
injectValue(configKey: string, injectedValue: string): void;
|
|
71
130
|
}
|
|
72
131
|
|
|
73
132
|
export interface PackageJsonBuilder extends ConfigBuilder<PackageJson> {
|
|
74
133
|
/**
|
|
75
|
-
* Checks if a
|
|
76
|
-
* @param key -
|
|
77
|
-
* @param value -
|
|
78
|
-
* @returns True if the
|
|
134
|
+
* Checks if a property exists on the package.json fields.
|
|
135
|
+
* @param key - Field to search
|
|
136
|
+
* @param value - Value to search for
|
|
137
|
+
* @returns True if the property exists and matches the value
|
|
79
138
|
*/
|
|
80
|
-
has(key: keyof
|
|
139
|
+
has(key: keyof PackageJson, value: string): boolean;
|
|
81
140
|
}
|
|
82
141
|
|
|
83
142
|
export interface Files {
|
|
84
|
-
add(...args: string[]): void
|
|
143
|
+
add(...args: string[]): void;
|
|
85
144
|
}
|
|
86
145
|
|
|
87
146
|
export interface CreateContext {
|
|
@@ -107,12 +166,6 @@ export interface CreateContext {
|
|
|
107
166
|
* load-preset if using localPresets. */
|
|
108
167
|
rawPresets: Array<string>;
|
|
109
168
|
|
|
110
|
-
/** Raw plugin desc from flags, prompts, etc. Can include constraints. */
|
|
111
|
-
rawPlugins: Array<string>;
|
|
112
|
-
|
|
113
|
-
/** Short names of plugins */
|
|
114
|
-
plugins: Array<string>;
|
|
115
|
-
|
|
116
169
|
/** Local packages that should be linked */
|
|
117
170
|
pkgLinks: Array<string>;
|
|
118
171
|
|
|
@@ -131,6 +184,12 @@ export interface CreateContext {
|
|
|
131
184
|
/** any generated files to show in report */
|
|
132
185
|
generatedFiles: Set<string>;
|
|
133
186
|
|
|
187
|
+
/** Default empty array, populated by load-preset with actual imports */
|
|
188
|
+
presets: Array<Plugin>;
|
|
189
|
+
|
|
190
|
+
/** Default to object w/empty plugins array to be populated by `presetConfig` hook */
|
|
191
|
+
presetConfig: GasketConfigDefinition;
|
|
192
|
+
|
|
134
193
|
// Added by `global-prompts`
|
|
135
194
|
|
|
136
195
|
/** Description of app */
|
|
@@ -139,8 +198,8 @@ export interface CreateContext {
|
|
|
139
198
|
/** Should a git repo be initialized and first commit */
|
|
140
199
|
gitInit: boolean;
|
|
141
200
|
|
|
142
|
-
/**
|
|
143
|
-
|
|
201
|
+
/** Names of the plugins that add unit and integration tests */
|
|
202
|
+
testPlugins: Array<string>;
|
|
144
203
|
|
|
145
204
|
/** Which package manager to use (Default: 'npm') */
|
|
146
205
|
packageManager: string;
|
|
@@ -154,23 +213,6 @@ export interface CreateContext {
|
|
|
154
213
|
/** Whether or not the user wants to override an extant directory */
|
|
155
214
|
destOverride: boolean;
|
|
156
215
|
|
|
157
|
-
// Added by `load-preset`
|
|
158
|
-
|
|
159
|
-
/** Short name of presets */
|
|
160
|
-
presets: Array<string>;
|
|
161
|
-
|
|
162
|
-
/** Shallow load of presets with meta data */
|
|
163
|
-
presetInfos: Array<PresetInfo>;
|
|
164
|
-
|
|
165
|
-
// Added by `cli-version`
|
|
166
|
-
|
|
167
|
-
/** Version of current CLI used to issue `create` command */
|
|
168
|
-
cliVersion: string;
|
|
169
|
-
|
|
170
|
-
/** Version of CLI to install, either current or min compatible version
|
|
171
|
-
* required by preset(s) */
|
|
172
|
-
cliVersionRequired: string;
|
|
173
|
-
|
|
174
216
|
// Added by `setup-pkg`
|
|
175
217
|
|
|
176
218
|
/** package.json builder */
|
|
@@ -190,13 +232,23 @@ export interface CreateContext {
|
|
|
190
232
|
files: Files;
|
|
191
233
|
}
|
|
192
234
|
|
|
193
|
-
|
|
235
|
+
export interface ActionWrapperParams {
|
|
236
|
+
gasket: GasketEngine;
|
|
237
|
+
context: CreateContext;
|
|
238
|
+
spinner?: any;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
declare module '@gasket/core' {
|
|
194
242
|
export interface HookExecTypes {
|
|
243
|
+
presetPrompt(context: CreateContext): Promise<void>;
|
|
244
|
+
presetConfig(context: CreateContext): Promise<CreateContext['presetConfig']>;
|
|
195
245
|
prompt(
|
|
196
246
|
context: CreateContext,
|
|
197
247
|
utils: {
|
|
198
|
-
prompt: (
|
|
199
|
-
|
|
248
|
+
prompt: (
|
|
249
|
+
prompts: Array<Record<string, any>>
|
|
250
|
+
) => Promise<Record<string, any>>;
|
|
251
|
+
addPlugins: (plugins: Array<string>) => Promise<void>;
|
|
200
252
|
}
|
|
201
253
|
): MaybeAsync<CreateContext>;
|
|
202
254
|
|
|
@@ -205,7 +257,8 @@ declare module '@gasket/engine' {
|
|
|
205
257
|
postCreate(
|
|
206
258
|
context: CreateContext,
|
|
207
259
|
utils: {
|
|
208
|
-
runScript: (script: string) => Promise<void
|
|
209
|
-
}
|
|
260
|
+
runScript: (script: string) => Promise<void>;
|
|
261
|
+
}
|
|
262
|
+
): MaybeAsync<void>;
|
|
210
263
|
}
|
|
211
264
|
}
|
package/lib/index.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import { createRequire } from 'module';
|
|
4
4
|
import { createCommand } from './commands/create.js';
|
|
5
|
-
import { processCommand, logo
|
|
5
|
+
import { processCommand, logo } from './utils/index.js';
|
|
6
|
+
import { warnIfOutdated } from '@gasket/utils';
|
|
6
7
|
|
|
7
8
|
const require = createRequire(import.meta.url);
|
|
8
9
|
const pkg = require('../package.json');
|
|
@@ -19,7 +20,7 @@ const gasketBin = program
|
|
|
19
20
|
|
|
20
21
|
async function main() {
|
|
21
22
|
const { command, hidden, isDefault } = processCommand(createCommand);
|
|
22
|
-
|
|
23
|
+
await warnIfOutdated(pkg.name, pkg.version);
|
|
23
24
|
gasketBin.addCommand(command, { hidden, isDefault });
|
|
24
25
|
|
|
25
26
|
process.argv.splice(2, 0, 'create');
|
|
@@ -14,14 +14,16 @@ export default function withSpinner(label, fn, { startSpinner = true } = {}) {
|
|
|
14
14
|
/**
|
|
15
15
|
* Decorated function
|
|
16
16
|
*
|
|
17
|
-
* @param {
|
|
17
|
+
* @param {ActionWrapperParams} params - ActionWrapperParams
|
|
18
|
+
* @param {GasketEngine} params.gasket - Gasket config
|
|
19
|
+
* @param {CreateContext} params.context - Create context
|
|
18
20
|
* @returns {Promise} promise
|
|
19
21
|
*/
|
|
20
|
-
async function wrapper(gasket = {}, context) {
|
|
22
|
+
async function wrapper({ gasket = {}, context }) {
|
|
21
23
|
const spinner = ora(label);
|
|
22
24
|
if (startSpinner) spinner.start();
|
|
23
25
|
try {
|
|
24
|
-
await fn(gasket, context, spinner);
|
|
26
|
+
await fn({ gasket, context, spinner });
|
|
25
27
|
if (spinner.isSpinning) spinner.succeed();
|
|
26
28
|
} catch (err) {
|
|
27
29
|
spinner.fail();
|
|
@@ -32,4 +34,4 @@ export default function withSpinner(label, fn, { startSpinner = true } = {}) {
|
|
|
32
34
|
|
|
33
35
|
wrapper.wrapped = fn;
|
|
34
36
|
return wrapper;
|
|
35
|
-
}
|
|
37
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createEngine } from '../create-engine.js';
|
|
2
1
|
import action from '../action-wrapper.js';
|
|
3
2
|
import { ConfigBuilder } from '../config-builder.js';
|
|
4
3
|
import { Files } from '../files.js';
|
|
@@ -7,11 +6,12 @@ import { Files } from '../files.js';
|
|
|
7
6
|
* Executes the `create` hook for all registered plugins.
|
|
8
7
|
* Adds `files` to context for plugins to add their files and templates.
|
|
9
8
|
*
|
|
9
|
+
* @param {GasketEngine} gasket - Gasket API
|
|
10
10
|
* @param {CreateContext} context - Create context
|
|
11
11
|
* @returns {Promise} promise
|
|
12
12
|
*/
|
|
13
|
-
async function createHooks(gasket, context) {
|
|
14
|
-
const {
|
|
13
|
+
async function createHooks({ gasket, context }) {
|
|
14
|
+
const { plugins = [], warnings } = context;
|
|
15
15
|
|
|
16
16
|
const files = new Files();
|
|
17
17
|
const gasketConfig = ConfigBuilder.create({}, { orderBy: ['plugins'], warnings, plugins });
|
|
@@ -164,7 +164,7 @@ async function performGenerate(context, descriptors) {
|
|
|
164
164
|
* @param {Spinner} spinner - Spinner
|
|
165
165
|
* @returns {Promise} promise
|
|
166
166
|
*/
|
|
167
|
-
async function generateFiles(
|
|
167
|
+
async function generateFiles({ context, spinner }) {
|
|
168
168
|
const { files } = context;
|
|
169
169
|
|
|
170
170
|
if (!files.globSets.length) {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import inquirer from 'inquirer';
|
|
2
2
|
import action from '../action-wrapper.js';
|
|
3
3
|
|
|
4
|
-
import { pluginIdentifier, flattenPresets } from '@gasket/resolve';
|
|
5
|
-
import { addPluginsToContext } from '../utils.js';
|
|
6
|
-
|
|
7
4
|
/**
|
|
8
5
|
* What is your app description?
|
|
9
6
|
*
|
|
@@ -64,54 +61,54 @@ async function choosePackageManager(context, prompt) {
|
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
/**
|
|
67
|
-
* Choose your unit test suite
|
|
64
|
+
* Choose your unit test suite and integration test suite
|
|
68
65
|
*
|
|
69
66
|
* @param {CreateContext} context - Create context
|
|
70
67
|
* @param {function} prompt - function to prompt user
|
|
71
68
|
* @returns {Promise} promise
|
|
72
69
|
*/
|
|
73
|
-
async function
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// const allPlugins = flattenPresets(presetInfos)
|
|
79
|
-
// .map((presetInfo) => presetInfo.plugins || [])
|
|
80
|
-
// .reduce((acc, arr) => acc.concat(arr), [])
|
|
81
|
-
// .map((pluginInfo) => pluginIdentifier(pluginInfo.name).shortName)
|
|
82
|
-
// .concat(plugins);
|
|
83
|
-
|
|
84
|
-
const knownTestPlugins = { mocha: '@gasket/plugin-mocha', jest: '@gasket/plugin-jest', cypress: '@gasket/plugin-cypress' };
|
|
85
|
-
|
|
86
|
-
if (!('testPlugin' in context)) {
|
|
87
|
-
// let testPlugin = Object.values(knownTestPlugins).find((p) => allPlugins.includes(p));
|
|
88
|
-
let testPlugin;
|
|
70
|
+
async function chooseTestPlugins(context, prompt) {
|
|
71
|
+
const knownTestPlugins = {
|
|
72
|
+
unit: { mocha: '@gasket/plugin-mocha', jest: '@gasket/plugin-jest' },
|
|
73
|
+
integration: { cypress: '@gasket/plugin-cypress' }
|
|
74
|
+
};
|
|
89
75
|
|
|
90
|
-
|
|
91
|
-
|
|
76
|
+
const testTypes = ['unit', 'integration'];
|
|
77
|
+
const testPlugins = [];
|
|
78
|
+
|
|
79
|
+
if (!('testPlugins' in context)) {
|
|
80
|
+
for (const type of testTypes) {
|
|
81
|
+
if (type + 'TestSuite' in context) {
|
|
82
|
+
const testSuite = knownTestPlugins[type][context[type + 'TestSuite']];
|
|
83
|
+
if (testSuite) testPlugins.push(testSuite);
|
|
84
|
+
} else {
|
|
85
|
+
const plugin = await promptForTestPlugin(
|
|
86
|
+
prompt,
|
|
87
|
+
`Choose your ${type} test suite`,
|
|
88
|
+
Object.entries(knownTestPlugins[type]).map(([name, value]) => ({ name, value }))
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
if (plugin) testPlugins.push(plugin);
|
|
92
|
+
}
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
if (
|
|
95
|
-
({
|
|
96
|
-
{
|
|
97
|
-
name: 'testPlugin',
|
|
98
|
-
message: 'Choose your unit test suite',
|
|
99
|
-
type: 'list',
|
|
100
|
-
choices: [
|
|
101
|
-
{ name: 'none (not recommended)', value: 'none' },
|
|
102
|
-
{ name: 'mocha + nyc + sinon + chai', value: '@gasket/plugin-mocha' },
|
|
103
|
-
{ name: 'jest', value: '@gasket/plugin-jest' },
|
|
104
|
-
{ name: 'cypress', value: '@gasket/plugin-cypress' }
|
|
105
|
-
]
|
|
106
|
-
}
|
|
107
|
-
]));
|
|
95
|
+
if (testPlugins.length > 0) {
|
|
96
|
+
Object.assign(context, { testPlugins });
|
|
108
97
|
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
109
100
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
101
|
+
async function promptForTestPlugin(prompt, message, choices) {
|
|
102
|
+
const { testPlugin } = await prompt([
|
|
103
|
+
{
|
|
104
|
+
name: 'testPlugin',
|
|
105
|
+
message,
|
|
106
|
+
type: 'list',
|
|
107
|
+
choices: [{ name: 'none', value: 'none' }, ...choices]
|
|
113
108
|
}
|
|
114
|
-
|
|
109
|
+
]);
|
|
110
|
+
|
|
111
|
+
return testPlugin !== 'none' ? testPlugin : null;
|
|
115
112
|
}
|
|
116
113
|
|
|
117
114
|
/**
|
|
@@ -141,7 +138,7 @@ async function allowExtantOverwriting(context, prompt) {
|
|
|
141
138
|
export const questions = [
|
|
142
139
|
chooseAppDescription,
|
|
143
140
|
choosePackageManager,
|
|
144
|
-
|
|
141
|
+
chooseTestPlugins,
|
|
145
142
|
allowExtantOverwriting
|
|
146
143
|
];
|
|
147
144
|
|
|
@@ -151,7 +148,7 @@ export const questions = [
|
|
|
151
148
|
* @param {CreateContext} context - Create context
|
|
152
149
|
* @returns {Promise} promise
|
|
153
150
|
*/
|
|
154
|
-
async function globalPrompts(
|
|
151
|
+
async function globalPrompts({ context }) {
|
|
155
152
|
const prompt = context.prompts ? inquirer.prompt : () => ({});
|
|
156
153
|
for (var fn of questions) {
|
|
157
154
|
await fn(context, prompt);
|
|
@@ -1,42 +1,33 @@
|
|
|
1
1
|
import mkDir from './mkdir.js';
|
|
2
2
|
import loadPreset from './load-preset.js';
|
|
3
|
-
import cliVersion from './cli-version.js';
|
|
4
3
|
import globalPrompts from './global-prompts.js';
|
|
5
4
|
import setupPkg from './setup-pkg.js';
|
|
6
|
-
import writePkg
|
|
7
|
-
import installModules
|
|
8
|
-
import linkModules
|
|
5
|
+
import writePkg from './write-pkg.js';
|
|
6
|
+
import installModules from './install-modules.js';
|
|
7
|
+
import linkModules from './link-modules.js';
|
|
9
8
|
import writeGasketConfig from './write-gasket-config.js';
|
|
10
|
-
import loadPkgForDebug from './load-pkg-for-debug.js';
|
|
11
9
|
import presetPromptHooks from './preset-prompt-hooks.js';
|
|
12
10
|
import presetConfigHooks from './preset-config-hooks.js';
|
|
13
11
|
import promptHooks from './prompt-hooks.js';
|
|
14
12
|
import createHooks from './create-hooks.js';
|
|
15
13
|
import generateFiles from './generate-files.js';
|
|
16
14
|
import postCreateHooks from './post-create-hooks.js';
|
|
17
|
-
import applyPresetConfig from './apply-preset-config.js';
|
|
18
15
|
import printReport from './print-report.js';
|
|
19
16
|
|
|
20
17
|
export {
|
|
21
18
|
mkDir,
|
|
22
19
|
loadPreset,
|
|
23
|
-
cliVersion,
|
|
24
20
|
globalPrompts,
|
|
25
21
|
setupPkg,
|
|
26
22
|
writePkg,
|
|
27
|
-
writePkgUpdate,
|
|
28
23
|
installModules,
|
|
29
|
-
installModulesUpdate,
|
|
30
24
|
linkModules,
|
|
31
|
-
linkModulesUpdate,
|
|
32
25
|
writeGasketConfig,
|
|
33
|
-
loadPkgForDebug,
|
|
34
26
|
presetPromptHooks,
|
|
35
27
|
presetConfigHooks,
|
|
36
28
|
promptHooks,
|
|
37
29
|
createHooks,
|
|
38
30
|
postCreateHooks,
|
|
39
31
|
generateFiles,
|
|
40
|
-
applyPresetConfig,
|
|
41
32
|
printReport
|
|
42
33
|
};
|
|
@@ -6,13 +6,10 @@ import action from '../action-wrapper.js';
|
|
|
6
6
|
* @param {CreateContext} context - Create context
|
|
7
7
|
* @returns {Promise} promise
|
|
8
8
|
*/
|
|
9
|
-
async function installModules(
|
|
9
|
+
async function installModules({ context }) {
|
|
10
10
|
const { pkgManager } = context;
|
|
11
11
|
|
|
12
12
|
await pkgManager.install();
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
16
15
|
export default action('Install node modules', installModules);
|
|
17
|
-
|
|
18
|
-
export const installModulesUpdate = action('Update node modules', installModules);
|
|
@@ -7,7 +7,7 @@ import action from '../action-wrapper.js';
|
|
|
7
7
|
* @param {Spinner} spinner - Spinner
|
|
8
8
|
* @returns {Promise} promise
|
|
9
9
|
*/
|
|
10
|
-
async function linkModules(
|
|
10
|
+
async function linkModules({ context, spinner }) {
|
|
11
11
|
const { pkgLinks, pkgManager } = context;
|
|
12
12
|
|
|
13
13
|
if (pkgLinks && pkgLinks.length) {
|
|
@@ -17,5 +17,3 @@ async function linkModules(gasket, context, spinner) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export default action('Link node modules', linkModules, { startSpinner: false });
|
|
20
|
-
|
|
21
|
-
export const linkModulesUpdate = action('Relink node modules', linkModules, { startSpinner: false });
|