@platformatic/generators 2.0.0-alpha.1 → 2.0.0-alpha.3
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/eslint.config.js +3 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.test-d.ts +4 -4
- package/lib/base-generator.d.ts +25 -25
- package/lib/base-generator.js +28 -28
- package/lib/create-gitignore.js +2 -2
- package/lib/create-plugin.d.ts +4 -4
- package/lib/create-plugin.js +9 -9
- package/lib/create-stackable-cli.js +7 -7
- package/lib/create-stackable-files.js +15 -15
- package/lib/create-stackable-plugin.js +3 -3
- package/lib/create-stackable-tests.js +15 -13
- package/lib/errors.js +1 -1
- package/lib/file-generator.d.ts +14 -14
- package/lib/file-generator.js +4 -4
- package/lib/stackable-generator.js +27 -27
- package/lib/utils.d.ts +8 -9
- package/lib/utils.js +18 -23
- package/package.json +9 -8
- package/test/base-generator.test.js +232 -210
- package/test/file-generator.test.js +20 -20
- package/test/fixtures/sample-runtime/platformatic.json +2 -2
- package/test/fixtures/sample-runtime/services/no-plugin/platformatic.json +1 -1
- package/test/fixtures/sample-runtime/services/rival/platformatic.json +1 -1
- package/test/helpers.js +9 -14
- package/test/stackable-generator.test.js +9 -8
- package/test/utils.test.js +27 -27
package/eslint.config.js
ADDED
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/index.test-d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { expectAssignable } from 'tsd'
|
|
2
|
-
import { BaseGenerator } from './lib/base-generator'
|
|
2
|
+
import { BaseGenerator } from './lib/base-generator'
|
|
3
3
|
import { generatePlugins, generateTests } from './index'
|
|
4
|
-
import { FileGenerator } from './lib/file-generator'
|
|
4
|
+
import { FileGenerator } from './lib/file-generator'
|
|
5
5
|
|
|
6
6
|
expectAssignable<BaseGenerator.ConfigFieldDefinition>({
|
|
7
7
|
label: 'PLT_TESTING',
|
|
8
8
|
var: 'testing',
|
|
9
9
|
default: 'hello world',
|
|
10
10
|
type: 'string',
|
|
11
|
-
configValue: 'someConfigValue'
|
|
11
|
+
configValue: 'someConfigValue',
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
expectAssignable<BaseGenerator.ConfigField>({
|
|
15
15
|
var: 'testing',
|
|
16
16
|
configValue: 'someConfigValue',
|
|
17
|
-
value: 'asd123'
|
|
17
|
+
value: 'asd123',
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
expectAssignable<FileGenerator.FileObject[]>(generatePlugins(true))
|
package/lib/base-generator.d.ts
CHANGED
|
@@ -81,42 +81,42 @@ export namespace BaseGenerator {
|
|
|
81
81
|
questions: Array<object>
|
|
82
82
|
|
|
83
83
|
packages: PackageConfiguration[]
|
|
84
|
-
constructor(opts?: BaseGeneratorOptions)
|
|
84
|
+
constructor (opts?: BaseGeneratorOptions)
|
|
85
|
+
|
|
86
|
+
setConfig (config?: BaseGeneratorConfig): void
|
|
85
87
|
|
|
86
|
-
setConfig(config?: BaseGeneratorConfig): void
|
|
87
|
-
|
|
88
88
|
getEnvVarName (envVarName: string): string
|
|
89
89
|
addEnvVars (envVars: Env, opts: AddEnvVarOptions): void
|
|
90
90
|
addEnvVar (envVarName: string, envVarValue: EnvVarValue, opts: AddEnvVarOptions): void
|
|
91
91
|
getEnvVar (envVarName: string): EnvVarValue
|
|
92
|
-
setEnvVars(env?: Env): void
|
|
92
|
+
setEnvVars (env?: Env): void
|
|
93
93
|
|
|
94
|
-
getDefaultConfig(): { [x: string]: JSONValue }
|
|
94
|
+
getDefaultConfig (): { [x: string]: JSONValue }
|
|
95
95
|
|
|
96
|
-
getFastifyVersion(): Promise<string>
|
|
97
|
-
getPlatformaticVersion(): Promise<string>
|
|
96
|
+
getFastifyVersion (): Promise<string>
|
|
97
|
+
getPlatformaticVersion (): Promise<string>
|
|
98
98
|
|
|
99
|
-
addPackage(pkg: PackageDefinition): Promise<void>
|
|
99
|
+
addPackage (pkg: PackageDefinition): Promise<void>
|
|
100
100
|
|
|
101
|
-
loadFromDir(dir: string): Promise<void>
|
|
102
|
-
prepare(): Promise<GeneratorMetadata>
|
|
103
|
-
run(): Promise<GeneratorMetadata>
|
|
104
|
-
addQuestion(question: any, where?: WhereClause): Promise<void>
|
|
105
|
-
removeQuestion(variableName: string): void
|
|
106
|
-
getTSConfig(): { [x: string]: JSONValue }
|
|
101
|
+
loadFromDir (dir: string): Promise<void>
|
|
102
|
+
prepare (): Promise<GeneratorMetadata>
|
|
103
|
+
run (): Promise<GeneratorMetadata>
|
|
104
|
+
addQuestion (question: any, where?: WhereClause): Promise<void>
|
|
105
|
+
removeQuestion (variableName: string): void
|
|
106
|
+
getTSConfig (): { [x: string]: JSONValue }
|
|
107
107
|
|
|
108
|
-
getConfigFieldsDefinitions(): ConfigFieldDefinition[]
|
|
109
|
-
setConfigFields(fields: ConfigField[]): void
|
|
108
|
+
getConfigFieldsDefinitions (): ConfigFieldDefinition[]
|
|
109
|
+
setConfigFields (fields: ConfigField[]): void
|
|
110
110
|
|
|
111
|
-
generateConfigFile(): Promise<void>
|
|
112
|
-
readPackageJsonFile(): Promise<JSONValue>
|
|
113
|
-
generatePackageJson(): Promise<{ [x: string]: JSONValue }>
|
|
114
|
-
getConfigFileName(): string
|
|
115
|
-
checkEnvVariablesInConfigFile(): boolean
|
|
116
|
-
_beforePrepare(): Promise<void>
|
|
117
|
-
_afterPrepare(): Promise<void | JSONValue>
|
|
118
|
-
_getConfigFileContents(): Promise<{ [x: string]: BaseGenerator.JSONValue }>
|
|
111
|
+
generateConfigFile (): Promise<void>
|
|
112
|
+
readPackageJsonFile (): Promise<JSONValue>
|
|
113
|
+
generatePackageJson (): Promise<{ [x: string]: JSONValue }>
|
|
114
|
+
getConfigFileName (): string
|
|
115
|
+
checkEnvVariablesInConfigFile (): boolean
|
|
116
|
+
_beforePrepare (): Promise<void>
|
|
117
|
+
_afterPrepare (): Promise<void | JSONValue>
|
|
118
|
+
_getConfigFileContents (): Promise<{ [x: string]: BaseGenerator.JSONValue }>
|
|
119
119
|
|
|
120
|
-
postInstallActions(): Promise<void>
|
|
120
|
+
postInstallActions (): Promise<void>
|
|
121
121
|
}
|
|
122
122
|
}
|
package/lib/base-generator.js
CHANGED
|
@@ -7,7 +7,7 @@ const {
|
|
|
7
7
|
extractEnvVariablesFromText,
|
|
8
8
|
getPackageConfigurationObject,
|
|
9
9
|
PLT_ROOT,
|
|
10
|
-
getLatestNpmVersion
|
|
10
|
+
getLatestNpmVersion,
|
|
11
11
|
} = require('./utils')
|
|
12
12
|
const { join } = require('node:path')
|
|
13
13
|
const { FileGenerator } = require('./file-generator')
|
|
@@ -24,7 +24,7 @@ const fakeLogger = {
|
|
|
24
24
|
warn: () => {},
|
|
25
25
|
debug: () => {},
|
|
26
26
|
trace: () => {},
|
|
27
|
-
error: () => {}
|
|
27
|
+
error: () => {},
|
|
28
28
|
}
|
|
29
29
|
/* c8 ignore start */
|
|
30
30
|
|
|
@@ -60,7 +60,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
60
60
|
envPrefix: '',
|
|
61
61
|
env: {},
|
|
62
62
|
defaultEnv: {},
|
|
63
|
-
isUpdating: false
|
|
63
|
+
isUpdating: false,
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -137,7 +137,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
137
137
|
this.config = {
|
|
138
138
|
...this.getDefaultConfig(),
|
|
139
139
|
...oldConfig,
|
|
140
|
-
...config
|
|
140
|
+
...config,
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
if (this.config.isRuntimeContext) {
|
|
@@ -163,7 +163,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
163
163
|
const newConfig = await this.inquirer.prompt(this.questions)
|
|
164
164
|
this.setConfig({
|
|
165
165
|
...this.config,
|
|
166
|
-
...newConfig
|
|
166
|
+
...newConfig,
|
|
167
167
|
})
|
|
168
168
|
}
|
|
169
169
|
}
|
|
@@ -190,7 +190,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
190
190
|
this.addFile({
|
|
191
191
|
path: '',
|
|
192
192
|
file: 'platformatic.json',
|
|
193
|
-
contents: JSON.stringify(currentConfigFile, null, 2)
|
|
193
|
+
contents: JSON.stringify(currentConfigFile, null, 2),
|
|
194
194
|
})
|
|
195
195
|
} else {
|
|
196
196
|
await this.getFastifyVersion()
|
|
@@ -203,7 +203,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
203
203
|
this.addFile({
|
|
204
204
|
path: '',
|
|
205
205
|
file: 'package.json',
|
|
206
|
-
contents: JSON.stringify(template, null, 2)
|
|
206
|
+
contents: JSON.stringify(template, null, 2),
|
|
207
207
|
})
|
|
208
208
|
|
|
209
209
|
await this.generateConfigFile()
|
|
@@ -215,7 +215,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
215
215
|
this.addFile({
|
|
216
216
|
path: '',
|
|
217
217
|
file: 'tsconfig.json',
|
|
218
|
-
contents: JSON.stringify(this.getTsConfig(), null, 2)
|
|
218
|
+
contents: JSON.stringify(this.getTsConfig(), null, 2),
|
|
219
219
|
})
|
|
220
220
|
}
|
|
221
221
|
|
|
@@ -236,7 +236,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
236
236
|
}
|
|
237
237
|
return {
|
|
238
238
|
targetDirectory: this.targetDirectory,
|
|
239
|
-
env: this.config.env
|
|
239
|
+
env: this.config.env,
|
|
240
240
|
}
|
|
241
241
|
} catch (err) {
|
|
242
242
|
if (err.code?.startsWith('PLT_GEN')) {
|
|
@@ -280,15 +280,15 @@ class BaseGenerator extends FileGenerator {
|
|
|
280
280
|
noEmitOnError: true,
|
|
281
281
|
incremental: true,
|
|
282
282
|
strict: true,
|
|
283
|
-
outDir: 'dist'
|
|
283
|
+
outDir: 'dist',
|
|
284
284
|
},
|
|
285
285
|
watchOptions: {
|
|
286
286
|
watchFile: 'fixedPollingInterval',
|
|
287
287
|
watchDirectory: 'fixedPollingInterval',
|
|
288
288
|
fallbackPolling: 'dynamicPriority',
|
|
289
289
|
synchronousWatchDirectory: true,
|
|
290
|
-
excludeDirectories: ['**/node_modules', 'dist']
|
|
291
|
-
}
|
|
290
|
+
excludeDirectories: ['**/node_modules', 'dist'],
|
|
291
|
+
},
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
|
|
@@ -299,7 +299,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
299
299
|
this.questions.push({
|
|
300
300
|
type: 'input',
|
|
301
301
|
name: 'targetDirectory',
|
|
302
|
-
message: 'Where would you like to create your project?'
|
|
302
|
+
message: 'Where would you like to create your project?',
|
|
303
303
|
})
|
|
304
304
|
}
|
|
305
305
|
|
|
@@ -309,14 +309,14 @@ class BaseGenerator extends FileGenerator {
|
|
|
309
309
|
name: 'typescript',
|
|
310
310
|
message: 'Do you want to use TypeScript?',
|
|
311
311
|
default: false,
|
|
312
|
-
choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
|
|
312
|
+
choices: [{ name: 'yes', value: true }, { name: 'no', value: false }],
|
|
313
313
|
})
|
|
314
314
|
|
|
315
315
|
// port
|
|
316
316
|
this.questions.push({
|
|
317
317
|
type: 'input',
|
|
318
318
|
name: 'port',
|
|
319
|
-
message: 'What port do you want to use?'
|
|
319
|
+
message: 'What port do you want to use?',
|
|
320
320
|
})
|
|
321
321
|
}
|
|
322
322
|
}
|
|
@@ -340,7 +340,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
340
340
|
}
|
|
341
341
|
return {
|
|
342
342
|
name: packageDefinition.name,
|
|
343
|
-
options: packageConfigOutput.config
|
|
343
|
+
options: packageConfigOutput.config,
|
|
344
344
|
}
|
|
345
345
|
})
|
|
346
346
|
}
|
|
@@ -348,7 +348,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
348
348
|
this.addFile({
|
|
349
349
|
path: '',
|
|
350
350
|
file: configFileName,
|
|
351
|
-
contents: JSON.stringify(contents, null, 2)
|
|
351
|
+
contents: JSON.stringify(contents, null, 2),
|
|
352
352
|
})
|
|
353
353
|
}
|
|
354
354
|
|
|
@@ -380,19 +380,19 @@ class BaseGenerator extends FileGenerator {
|
|
|
380
380
|
name: `${this.config.serviceName}`,
|
|
381
381
|
scripts: {
|
|
382
382
|
start: 'platformatic start',
|
|
383
|
-
test: 'borp'
|
|
383
|
+
test: 'borp',
|
|
384
384
|
},
|
|
385
385
|
devDependencies: {
|
|
386
386
|
fastify: `^${this.fastifyVersion}`,
|
|
387
387
|
borp: `${this.pkgData.devDependencies.borp}`,
|
|
388
|
-
...this.config.devDependencies
|
|
388
|
+
...this.config.devDependencies,
|
|
389
389
|
},
|
|
390
390
|
dependencies: {
|
|
391
|
-
...this.config.dependencies
|
|
391
|
+
...this.config.dependencies,
|
|
392
392
|
},
|
|
393
393
|
engines: {
|
|
394
|
-
node: '^18.8.0 || >=20.6.0'
|
|
395
|
-
}
|
|
394
|
+
node: '^18.8.0 || >=20.6.0',
|
|
395
|
+
},
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
if (this.config.typescript) {
|
|
@@ -409,7 +409,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
409
409
|
this.addFile({
|
|
410
410
|
path: '',
|
|
411
411
|
file: '.env',
|
|
412
|
-
contents: serializeEnvVars(this.config.env)
|
|
412
|
+
contents: serializeEnvVars(this.config.env),
|
|
413
413
|
})
|
|
414
414
|
|
|
415
415
|
const emptyEnvVars = {}
|
|
@@ -424,8 +424,8 @@ class BaseGenerator extends FileGenerator {
|
|
|
424
424
|
file: '.env.sample',
|
|
425
425
|
contents: serializeEnvVars({
|
|
426
426
|
...this.config.defaultEnv,
|
|
427
|
-
...emptyEnvVars
|
|
428
|
-
})
|
|
427
|
+
...emptyEnvVars,
|
|
428
|
+
}),
|
|
429
429
|
})
|
|
430
430
|
}
|
|
431
431
|
}
|
|
@@ -461,7 +461,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
461
461
|
const flattened = flattenObject(pkg)
|
|
462
462
|
const output = {
|
|
463
463
|
name: flattened.name,
|
|
464
|
-
options: []
|
|
464
|
+
options: [],
|
|
465
465
|
}
|
|
466
466
|
if (pkg.options) {
|
|
467
467
|
Object.entries(flattened)
|
|
@@ -473,7 +473,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
473
473
|
name: serviceEnvVarKey,
|
|
474
474
|
path: key.replace('options.', ''),
|
|
475
475
|
type: 'string',
|
|
476
|
-
value: runtimeEnv[runtimeEnvVarKey]
|
|
476
|
+
value: runtimeEnv[runtimeEnvVarKey],
|
|
477
477
|
}
|
|
478
478
|
output.options.push(option)
|
|
479
479
|
})
|
|
@@ -487,7 +487,7 @@ class BaseGenerator extends FileGenerator {
|
|
|
487
487
|
name: serviceName,
|
|
488
488
|
template: getServiceTemplateFromSchemaUrl(servicePkgJsonFileData.$schema),
|
|
489
489
|
fields: [],
|
|
490
|
-
plugins
|
|
490
|
+
plugins,
|
|
491
491
|
}
|
|
492
492
|
}
|
|
493
493
|
|
package/lib/create-gitignore.js
CHANGED
package/lib/create-plugin.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ type HelperCustomization = {
|
|
|
7
7
|
requires: string
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function generatePluginWithTypesSupport(typescript: boolean): FileGenerator.FileObject
|
|
11
|
-
export function generateRouteWithTypesSupport(typescript: boolean): FileGenerator.FileObject
|
|
12
|
-
export function generateTests(typescript: boolean, type: string, customization?: HelperCustomization): Array<FileGenerator.FileObject>
|
|
13
|
-
export function generatePlugins(typescript: boolean): Array<FileGenerator.FileObject>
|
|
10
|
+
export function generatePluginWithTypesSupport (typescript: boolean): FileGenerator.FileObject
|
|
11
|
+
export function generateRouteWithTypesSupport (typescript: boolean): FileGenerator.FileObject
|
|
12
|
+
export function generateTests (typescript: boolean, type: string, customization?: HelperCustomization): Array<FileGenerator.FileObject>
|
|
13
|
+
export function generatePlugins (typescript: boolean): Array<FileGenerator.FileObject>
|
package/lib/create-plugin.js
CHANGED
|
@@ -184,7 +184,7 @@ function generatePluginWithTypesSupport (typescript) {
|
|
|
184
184
|
return {
|
|
185
185
|
path: 'plugins',
|
|
186
186
|
file: pluginName,
|
|
187
|
-
contents: pluginTemplate
|
|
187
|
+
contents: pluginTemplate,
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
|
|
@@ -198,7 +198,7 @@ function generateRouteWithTypesSupport (typescript) {
|
|
|
198
198
|
return {
|
|
199
199
|
path: 'routes',
|
|
200
200
|
file: routesName,
|
|
201
|
-
contents: routesTemplate
|
|
201
|
+
contents: routesTemplate,
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -208,33 +208,33 @@ function generateTests (typescript, mod, customizations) {
|
|
|
208
208
|
output.push({
|
|
209
209
|
path: 'test',
|
|
210
210
|
file: 'helper.ts',
|
|
211
|
-
contents: testHelperTS(mod, customizations)
|
|
211
|
+
contents: testHelperTS(mod, customizations),
|
|
212
212
|
})
|
|
213
213
|
output.push({
|
|
214
214
|
path: join('test', 'plugins'),
|
|
215
215
|
file: 'example.test.ts',
|
|
216
|
-
contents: TEST_PLUGIN_TS
|
|
216
|
+
contents: TEST_PLUGIN_TS,
|
|
217
217
|
})
|
|
218
218
|
output.push({
|
|
219
219
|
path: join('test', 'routes'),
|
|
220
220
|
file: 'root.test.ts',
|
|
221
|
-
contents: TEST_ROUTES_TS
|
|
221
|
+
contents: TEST_ROUTES_TS,
|
|
222
222
|
})
|
|
223
223
|
} else {
|
|
224
224
|
output.push({
|
|
225
225
|
path: 'test',
|
|
226
226
|
file: 'helper.js',
|
|
227
|
-
contents: testHelperJS(mod, customizations)
|
|
227
|
+
contents: testHelperJS(mod, customizations),
|
|
228
228
|
})
|
|
229
229
|
output.push({
|
|
230
230
|
path: join('test', 'plugins'),
|
|
231
231
|
file: 'example.test.js',
|
|
232
|
-
contents: TEST_PLUGIN_JS
|
|
232
|
+
contents: TEST_PLUGIN_JS,
|
|
233
233
|
})
|
|
234
234
|
output.push({
|
|
235
235
|
path: join('test', 'routes'),
|
|
236
236
|
file: 'root.test.js',
|
|
237
|
-
contents: TEST_ROUTES_JS
|
|
237
|
+
contents: TEST_ROUTES_JS,
|
|
238
238
|
})
|
|
239
239
|
}
|
|
240
240
|
return output
|
|
@@ -251,5 +251,5 @@ module.exports = {
|
|
|
251
251
|
generatePluginWithTypesSupport,
|
|
252
252
|
generateRouteWithTypesSupport,
|
|
253
253
|
generatePlugins,
|
|
254
|
-
generateTests
|
|
254
|
+
generateTests,
|
|
255
255
|
}
|
|
@@ -129,14 +129,14 @@ function generateStackableCli (typescript, stackableName) {
|
|
|
129
129
|
path: 'cli',
|
|
130
130
|
file: 'start.ts',
|
|
131
131
|
contents: getTsStackableStartCli(),
|
|
132
|
-
options: { mode: 0o755 }
|
|
132
|
+
options: { mode: 0o755 },
|
|
133
133
|
},
|
|
134
134
|
{
|
|
135
135
|
path: 'cli',
|
|
136
136
|
file: 'create.ts',
|
|
137
137
|
contents: getTsStackableCreateCli(stackableName),
|
|
138
|
-
options: { mode: 0o755 }
|
|
139
|
-
}
|
|
138
|
+
options: { mode: 0o755 },
|
|
139
|
+
},
|
|
140
140
|
]
|
|
141
141
|
}
|
|
142
142
|
|
|
@@ -145,17 +145,17 @@ function generateStackableCli (typescript, stackableName) {
|
|
|
145
145
|
path: 'cli',
|
|
146
146
|
file: 'start.js',
|
|
147
147
|
contents: getJsStackableStartCli(),
|
|
148
|
-
options: { mode: 0o755 }
|
|
148
|
+
options: { mode: 0o755 },
|
|
149
149
|
},
|
|
150
150
|
{
|
|
151
151
|
path: 'cli',
|
|
152
152
|
file: 'create.js',
|
|
153
153
|
contents: getJsStackableCreateCli(stackableName),
|
|
154
|
-
options: { mode: 0o755 }
|
|
155
|
-
}
|
|
154
|
+
options: { mode: 0o755 },
|
|
155
|
+
},
|
|
156
156
|
]
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
module.exports = {
|
|
160
|
-
generateStackableCli
|
|
160
|
+
generateStackableCli,
|
|
161
161
|
}
|
|
@@ -450,69 +450,69 @@ function generateStackableFiles (typescript, stackableName) {
|
|
|
450
450
|
{
|
|
451
451
|
path: '',
|
|
452
452
|
file: 'index.ts',
|
|
453
|
-
contents: getTsStackableIndexFile(stackableName)
|
|
453
|
+
contents: getTsStackableIndexFile(stackableName),
|
|
454
454
|
},
|
|
455
455
|
{
|
|
456
456
|
path: '',
|
|
457
457
|
file: 'index.d.ts',
|
|
458
|
-
contents: getStackableIndexTypesFile(stackableName)
|
|
458
|
+
contents: getStackableIndexTypesFile(stackableName),
|
|
459
459
|
},
|
|
460
460
|
{
|
|
461
461
|
path: '',
|
|
462
462
|
file: 'config.d.ts',
|
|
463
|
-
contents: getStackableConfigTypesFile(stackableName)
|
|
463
|
+
contents: getStackableConfigTypesFile(stackableName),
|
|
464
464
|
},
|
|
465
465
|
{
|
|
466
466
|
path: 'lib',
|
|
467
467
|
file: 'generator.ts',
|
|
468
|
-
contents: getTsStackableGeneratorFile(stackableName)
|
|
468
|
+
contents: getTsStackableGeneratorFile(stackableName),
|
|
469
469
|
},
|
|
470
470
|
{
|
|
471
471
|
path: 'lib/templates',
|
|
472
472
|
file: 'types.ts',
|
|
473
|
-
contents: getTsGlobalTypesTemplateFile(stackableName)
|
|
473
|
+
contents: getTsGlobalTypesTemplateFile(stackableName),
|
|
474
474
|
},
|
|
475
475
|
{
|
|
476
476
|
path: 'lib',
|
|
477
477
|
file: 'schema.ts',
|
|
478
|
-
contents: getTsStackableSchemaFile(stackableName)
|
|
479
|
-
}
|
|
478
|
+
contents: getTsStackableSchemaFile(stackableName),
|
|
479
|
+
},
|
|
480
480
|
]
|
|
481
481
|
}
|
|
482
482
|
return [
|
|
483
483
|
{
|
|
484
484
|
path: '',
|
|
485
485
|
file: 'index.js',
|
|
486
|
-
contents: getJsStackableIndexFile(stackableName)
|
|
486
|
+
contents: getJsStackableIndexFile(stackableName),
|
|
487
487
|
},
|
|
488
488
|
{
|
|
489
489
|
path: '',
|
|
490
490
|
file: 'index.d.ts',
|
|
491
|
-
contents: getStackableIndexTypesFile(stackableName)
|
|
491
|
+
contents: getStackableIndexTypesFile(stackableName),
|
|
492
492
|
},
|
|
493
493
|
{
|
|
494
494
|
path: '',
|
|
495
495
|
file: 'config.d.ts',
|
|
496
|
-
contents: getStackableConfigTypesFile(stackableName)
|
|
496
|
+
contents: getStackableConfigTypesFile(stackableName),
|
|
497
497
|
},
|
|
498
498
|
{
|
|
499
499
|
path: 'lib',
|
|
500
500
|
file: 'generator.js',
|
|
501
|
-
contents: getJsStackableGeneratorFile(stackableName)
|
|
501
|
+
contents: getJsStackableGeneratorFile(stackableName),
|
|
502
502
|
},
|
|
503
503
|
{
|
|
504
504
|
path: 'lib/templates',
|
|
505
505
|
file: 'types.js',
|
|
506
|
-
contents: getJsGlobalTypesTemplateFile(stackableName)
|
|
506
|
+
contents: getJsGlobalTypesTemplateFile(stackableName),
|
|
507
507
|
},
|
|
508
508
|
{
|
|
509
509
|
path: 'lib',
|
|
510
510
|
file: 'schema.js',
|
|
511
|
-
contents: getJsStackableSchemaFile(stackableName)
|
|
512
|
-
}
|
|
511
|
+
contents: getJsStackableSchemaFile(stackableName),
|
|
512
|
+
},
|
|
513
513
|
]
|
|
514
514
|
}
|
|
515
515
|
|
|
516
516
|
module.exports = {
|
|
517
|
-
generateStackableFiles
|
|
517
|
+
generateStackableFiles,
|
|
518
518
|
}
|
|
@@ -34,16 +34,16 @@ function generateStackablePlugins (typescript) {
|
|
|
34
34
|
return [{
|
|
35
35
|
path: 'plugins',
|
|
36
36
|
file: 'example.ts',
|
|
37
|
-
contents: getTsStackablePluginFile()
|
|
37
|
+
contents: getTsStackablePluginFile(),
|
|
38
38
|
}]
|
|
39
39
|
}
|
|
40
40
|
return [{
|
|
41
41
|
path: 'plugins',
|
|
42
42
|
file: 'example.js',
|
|
43
|
-
contents: getJsStackablePluginFile()
|
|
43
|
+
contents: getJsStackablePluginFile(),
|
|
44
44
|
}]
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
module.exports = {
|
|
48
|
-
generateStackablePlugins
|
|
48
|
+
generateStackablePlugins,
|
|
49
49
|
}
|
|
@@ -108,7 +108,8 @@ const test = require('node:test')
|
|
|
108
108
|
const assert = require('node:assert')
|
|
109
109
|
const { tmpdir } = require('node:os')
|
|
110
110
|
const { join } = require('node:path')
|
|
111
|
-
const { readFile, readdir, mkdtemp
|
|
111
|
+
const { readFile, readdir, mkdtemp } = require('node:fs/promises')
|
|
112
|
+
const { safeRemove } = require('@platformatic/utils')
|
|
112
113
|
const { Generator } = require('../index')
|
|
113
114
|
const stackablePackageJson = require('../package.json')
|
|
114
115
|
|
|
@@ -163,7 +164,7 @@ test('should return Generator config fields definitions', async () => {
|
|
|
163
164
|
|
|
164
165
|
test('should generate a stackable app', async (t) => {
|
|
165
166
|
const testDir = await mkdtemp(join(tmpdir(), 'stackable-'))
|
|
166
|
-
t.after(() =>
|
|
167
|
+
t.after(() => safeRemove(testDir))
|
|
167
168
|
|
|
168
169
|
const generator = new Generator()
|
|
169
170
|
|
|
@@ -231,9 +232,10 @@ import test from 'node:test'
|
|
|
231
232
|
import assert from 'node:assert'
|
|
232
233
|
import { tmpdir } from 'node:os'
|
|
233
234
|
import { join } from 'node:path'
|
|
234
|
-
import { readFile, readdir, mkdtemp
|
|
235
|
+
import { readFile, readdir, mkdtemp } from 'node:fs/promises'
|
|
235
236
|
import { readFileSync } from 'node:fs'
|
|
236
237
|
import { Generator } from '../index'
|
|
238
|
+
import { safeRemove } from '@platformatic/utils'
|
|
237
239
|
|
|
238
240
|
const stackablePackageJsonPath = require.resolve('../../package.json')
|
|
239
241
|
const stackablePackageJson = JSON.parse(readFileSync(stackablePackageJsonPath, 'utf8'))
|
|
@@ -289,7 +291,7 @@ test('should return Generator config fields definitions', async () => {
|
|
|
289
291
|
|
|
290
292
|
test('should generate a stackable app', async (t) => {
|
|
291
293
|
const testDir = await mkdtemp(join(tmpdir(), 'stackable-'))
|
|
292
|
-
t.after(() =>
|
|
294
|
+
t.after(() => safeRemove(testDir))
|
|
293
295
|
|
|
294
296
|
const generator = new Generator()
|
|
295
297
|
|
|
@@ -357,39 +359,39 @@ function generateStackableTests (typescript, stackableName) {
|
|
|
357
359
|
{
|
|
358
360
|
path: 'test',
|
|
359
361
|
file: 'index.test.ts',
|
|
360
|
-
contents: getTsStackableIndexTestFile(stackableName)
|
|
362
|
+
contents: getTsStackableIndexTestFile(stackableName),
|
|
361
363
|
},
|
|
362
364
|
{
|
|
363
365
|
path: 'test',
|
|
364
366
|
file: 'schema.test.ts',
|
|
365
|
-
contents: getTsStackableSchemaTestFile(stackableName)
|
|
367
|
+
contents: getTsStackableSchemaTestFile(stackableName),
|
|
366
368
|
},
|
|
367
369
|
{
|
|
368
370
|
path: 'test',
|
|
369
371
|
file: 'generator.test.ts',
|
|
370
|
-
contents: getTsStackableGeneratorTestFile()
|
|
371
|
-
}
|
|
372
|
+
contents: getTsStackableGeneratorTestFile(),
|
|
373
|
+
},
|
|
372
374
|
]
|
|
373
375
|
}
|
|
374
376
|
return [
|
|
375
377
|
{
|
|
376
378
|
path: 'test',
|
|
377
379
|
file: 'index.test.js',
|
|
378
|
-
contents: getJsStackableIndexTestFile(stackableName)
|
|
380
|
+
contents: getJsStackableIndexTestFile(stackableName),
|
|
379
381
|
},
|
|
380
382
|
{
|
|
381
383
|
path: 'test',
|
|
382
384
|
file: 'schema.test.js',
|
|
383
|
-
contents: getJsStackableSchemaTestFile(stackableName)
|
|
385
|
+
contents: getJsStackableSchemaTestFile(stackableName),
|
|
384
386
|
},
|
|
385
387
|
{
|
|
386
388
|
path: 'test',
|
|
387
389
|
file: 'generator.test.js',
|
|
388
|
-
contents: getJsStackableGeneratorTestFile()
|
|
389
|
-
}
|
|
390
|
+
contents: getJsStackableGeneratorTestFile(),
|
|
391
|
+
},
|
|
390
392
|
]
|
|
391
393
|
}
|
|
392
394
|
|
|
393
395
|
module.exports = {
|
|
394
|
-
generateStackableTests
|
|
396
|
+
generateStackableTests,
|
|
395
397
|
}
|
package/lib/errors.js
CHANGED
|
@@ -8,5 +8,5 @@ module.exports = {
|
|
|
8
8
|
ModuleNeeded: createError(`${ERROR_PREFIX}_PREPARE_ERROR`, 'The module which the package will be published to must be specified'),
|
|
9
9
|
PrepareError: createError(`${ERROR_PREFIX}_PREPARE_ERROR`, 'Error while generating the files: %s.'),
|
|
10
10
|
MissingEnvVariable: createError(`${ERROR_PREFIX}_MISSING_ENV_VAR`, 'Env variable %s is defined in config file %s, but not in config.env object.'),
|
|
11
|
-
WrongTypeError: createError(`${ERROR_PREFIX}_WRONG_TYPE`, 'Invalid value type. Accepted values are \'string\', \'number\' and \'boolean\', found \'%s\'.')
|
|
11
|
+
WrongTypeError: createError(`${ERROR_PREFIX}_WRONG_TYPE`, 'Invalid value type. Accepted values are \'string\', \'number\' and \'boolean\', found \'%s\'.'),
|
|
12
12
|
}
|