@platformatic/generators 1.26.0 → 1.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.test-d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { expectAssignable } from 'tsd'
|
|
2
|
+
import { BaseGenerator } from './lib/base-generator';
|
|
3
|
+
|
|
4
|
+
expectAssignable<BaseGenerator.ConfigFieldDefinition>({
|
|
5
|
+
label: 'PLT_TESTING',
|
|
6
|
+
var: 'testing',
|
|
7
|
+
default: 'hello world',
|
|
8
|
+
type: 'string',
|
|
9
|
+
configValue: 'someConfigValue'
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
expectAssignable<BaseGenerator.ConfigField>({
|
|
13
|
+
var: 'testing',
|
|
14
|
+
configValue: 'someConfigValue',
|
|
15
|
+
value: 'asd123'
|
|
16
|
+
})
|
package/lib/base-generator.d.ts
CHANGED
|
@@ -61,13 +61,13 @@ export namespace BaseGenerator {
|
|
|
61
61
|
var: string
|
|
62
62
|
default: string
|
|
63
63
|
type: 'number' | 'string' | 'boolean' | 'path'
|
|
64
|
-
configValue?:
|
|
64
|
+
configValue?: string
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
type ConfigField = {
|
|
68
68
|
var: string
|
|
69
|
-
configValue?:
|
|
70
|
-
value:
|
|
69
|
+
configValue?: string
|
|
70
|
+
value: string
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
type AddEnvVarOptions = {
|
package/lib/base-generator.js
CHANGED
|
@@ -364,12 +364,14 @@ class BaseGenerator extends FileGenerator {
|
|
|
364
364
|
|
|
365
365
|
async generatePackageJson () {
|
|
366
366
|
const template = {
|
|
367
|
+
name: `${this.config.serviceName}`,
|
|
367
368
|
scripts: {
|
|
368
369
|
start: 'platformatic start',
|
|
369
|
-
test: '
|
|
370
|
+
test: 'borp'
|
|
370
371
|
},
|
|
371
372
|
devDependencies: {
|
|
372
373
|
fastify: `^${this.fastifyVersion}`,
|
|
374
|
+
borp: `${this.pkgData.devDependencies.borp}`,
|
|
373
375
|
...this.config.devDependencies
|
|
374
376
|
},
|
|
375
377
|
dependencies: {
|
|
@@ -9,16 +9,17 @@ function getJsStackableIndexFile (stackableName) {
|
|
|
9
9
|
const { platformaticService } = require('@platformatic/service')
|
|
10
10
|
const { schema } = require('./lib/schema')
|
|
11
11
|
const { Generator } = require('./lib/generator')
|
|
12
|
+
const { version } = require('./package.json')
|
|
12
13
|
|
|
13
14
|
async function stackable (fastify, opts) {
|
|
14
15
|
await fastify.register(platformaticService, opts)
|
|
15
16
|
await fastify.register(require('./plugins/example'), opts)
|
|
16
17
|
}
|
|
17
|
-
|
|
18
18
|
stackable.configType = '${kebabCase(stackableName + '-app')}'
|
|
19
19
|
stackable.schema = schema
|
|
20
20
|
stackable.Generator = Generator
|
|
21
21
|
stackable.configManagerConfig = {
|
|
22
|
+
version,
|
|
22
23
|
schema,
|
|
23
24
|
envWhitelist: ['PORT', 'HOSTNAME'],
|
|
24
25
|
allowToWatch: ['.env'],
|
|
@@ -48,6 +49,9 @@ import { platformaticService, Stackable } from '@platformatic/service'
|
|
|
48
49
|
import { schema } from './lib/schema'
|
|
49
50
|
import { Generator } from './lib/generator'
|
|
50
51
|
import { ${stackableConfigType} } from './config'
|
|
52
|
+
import { readFileSync } from 'node:fs'
|
|
53
|
+
|
|
54
|
+
const { version } = JSON.parse(readFileSync('package.json', 'utf8'))
|
|
51
55
|
|
|
52
56
|
const stackable: Stackable<${stackableConfigType}> = async function (fastify, opts) {
|
|
53
57
|
await fastify.register(platformaticService, opts)
|
|
@@ -58,6 +62,7 @@ stackable.configType = '${kebabCase(stackableName + '-app')}'
|
|
|
58
62
|
stackable.schema = schema
|
|
59
63
|
stackable.Generator = Generator
|
|
60
64
|
stackable.configManagerConfig = {
|
|
65
|
+
version,
|
|
61
66
|
schema,
|
|
62
67
|
envWhitelist: ['PORT', 'HOSTNAME'],
|
|
63
68
|
allowToWatch: ['.env'],
|
|
@@ -179,7 +184,7 @@ class ${stackableGeneratorType} extends ServiceGenerator {
|
|
|
179
184
|
const packageJson = await this.getStackablePackageJson()
|
|
180
185
|
const config = {
|
|
181
186
|
$schema: './stackable.schema.json',
|
|
182
|
-
module: packageJson.name
|
|
187
|
+
module: \`\${packageJson.name}@\${packageJson.version}\`,
|
|
183
188
|
greeting: {
|
|
184
189
|
text: \`{\${this.getEnvVarName('PLT_GREETING_TEXT')}}\`
|
|
185
190
|
}
|
|
@@ -287,7 +292,7 @@ class ${stackableGeneratorType} extends ServiceGenerator {
|
|
|
287
292
|
const packageJson = await this.getStackablePackageJson()
|
|
288
293
|
const config = {
|
|
289
294
|
$schema: './stackable.schema.json',
|
|
290
|
-
module: packageJson.name
|
|
295
|
+
module: \`\${packageJson.name}@\${packageJson.version}\`,
|
|
291
296
|
greeting: {
|
|
292
297
|
text: \`{\${this.getEnvVarName('PLT_GREETING_TEXT')}}\`
|
|
293
298
|
}
|
|
@@ -359,11 +364,13 @@ function getJsStackableSchemaFile (stackableName) {
|
|
|
359
364
|
'use strict'
|
|
360
365
|
|
|
361
366
|
const { schema } = require('@platformatic/service')
|
|
367
|
+
const { version } = require('../package.json')
|
|
362
368
|
|
|
363
369
|
const ${schemaVarName} = {
|
|
364
370
|
...schema.schema,
|
|
365
371
|
$id: '${schemaId}',
|
|
366
372
|
title: '${schemaTitle}',
|
|
373
|
+
version,
|
|
367
374
|
properties: {
|
|
368
375
|
...schema.schema.properties,
|
|
369
376
|
module: { type: 'string' },
|
|
@@ -400,6 +407,7 @@ const ${schemaVarName} = {
|
|
|
400
407
|
...schema.schema,
|
|
401
408
|
$id: '${schemaId}',
|
|
402
409
|
title: '${schemaTitle}',
|
|
410
|
+
version,
|
|
403
411
|
properties: {
|
|
404
412
|
...schema.schema.properties,
|
|
405
413
|
module: { type: 'string' },
|
|
@@ -230,7 +230,9 @@ class StackableGenerator extends FileGenerator {
|
|
|
230
230
|
},
|
|
231
231
|
scripts: {
|
|
232
232
|
build: 'tsc --build',
|
|
233
|
-
'
|
|
233
|
+
'gen-schema': 'node lib/schema.js > schema.json',
|
|
234
|
+
'gen-types': 'json2ts > config.d.ts < schema.json',
|
|
235
|
+
'build:config': 'pnpm run gen-schema && pnpm run gen-types',
|
|
234
236
|
clean: 'rm -fr ./dist'
|
|
235
237
|
},
|
|
236
238
|
engines: {
|
|
@@ -261,7 +263,10 @@ class StackableGenerator extends FileGenerator {
|
|
|
261
263
|
[startStackableCommand]: './cli/start.js'
|
|
262
264
|
},
|
|
263
265
|
scripts: {
|
|
264
|
-
'
|
|
266
|
+
'gen-schema': 'node lib/schema.js > schema.json',
|
|
267
|
+
'gen-types': 'json2ts > config.d.ts < schema.json',
|
|
268
|
+
'build:config': 'pnpm run gen-schema && pnpm run gen-types',
|
|
269
|
+
prepublishOnly: 'pnpm run build:config',
|
|
265
270
|
lint: 'standard'
|
|
266
271
|
},
|
|
267
272
|
engines: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/generators",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
4
4
|
"description": "Main classes and utils for generators.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [],
|
|
@@ -10,20 +10,21 @@
|
|
|
10
10
|
"@fastify/error": "^3.4.1",
|
|
11
11
|
"boring-name-generator": "^1.0.3",
|
|
12
12
|
"change-case-all": "^2.1.0",
|
|
13
|
-
"fastify": "^4.26.
|
|
14
|
-
"pino": "^8.
|
|
15
|
-
"undici": "^6.
|
|
13
|
+
"fastify": "^4.26.2",
|
|
14
|
+
"pino": "^8.19.0",
|
|
15
|
+
"undici": "^6.9.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/inquirer": "^9.0.7",
|
|
19
|
-
"borp": "^0.
|
|
19
|
+
"borp": "^0.10.0",
|
|
20
20
|
"c8": "^9.1.0",
|
|
21
21
|
"snazzy": "^9.0.0",
|
|
22
22
|
"standard": "^17.1.0",
|
|
23
|
-
"
|
|
23
|
+
"tsd": "^0.30.7",
|
|
24
|
+
"typescript": "^5.4.2"
|
|
24
25
|
},
|
|
25
26
|
"scripts": {
|
|
26
27
|
"lint": "standard | snazzy",
|
|
27
|
-
"test": "pnpm run lint && borp -C -X fixtures -X test --concurrency=1"
|
|
28
|
+
"test": "pnpm run lint && borp -C -X fixtures -X test --concurrency=1 && tsd"
|
|
28
29
|
}
|
|
29
30
|
}
|
|
@@ -30,7 +30,8 @@ test('should write file and dirs', async (t) => {
|
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
gen.setConfig({
|
|
33
|
-
targetDirectory: dir
|
|
33
|
+
targetDirectory: dir,
|
|
34
|
+
serviceName: 'test-service'
|
|
34
35
|
})
|
|
35
36
|
|
|
36
37
|
await gen.run()
|
|
@@ -40,6 +41,8 @@ test('should write file and dirs', async (t) => {
|
|
|
40
41
|
assert.ok(packageJson.dependencies)
|
|
41
42
|
assert.ok(packageJson.engines)
|
|
42
43
|
|
|
44
|
+
assert.equal(packageJson.name, 'test-service')
|
|
45
|
+
|
|
43
46
|
const configFile = JSON.parse(await readFile(join(dir, 'platformatic.json'), 'utf8'))
|
|
44
47
|
assert.deepEqual(configFile, {})
|
|
45
48
|
|