@platformatic/generators 1.31.1 → 1.33.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/lib/base-generator.d.ts
CHANGED
|
@@ -93,7 +93,7 @@ export namespace BaseGenerator {
|
|
|
93
93
|
getEnvVar (envVarName: string): EnvVarValue
|
|
94
94
|
setEnvVars(env?: Env): void
|
|
95
95
|
|
|
96
|
-
getDefaultConfig(): JSONValue
|
|
96
|
+
getDefaultConfig(): { [x: string]: JSONValue }
|
|
97
97
|
getDefaultEnv(): Env
|
|
98
98
|
|
|
99
99
|
getFastifyVersion(): Promise<string>
|
|
@@ -106,19 +106,19 @@ export namespace BaseGenerator {
|
|
|
106
106
|
run(): Promise<GeneratorMetadata>
|
|
107
107
|
addQuestion(question: any, where?: WhereClause): Promise<void>
|
|
108
108
|
removeQuestion(variableName: string): void
|
|
109
|
-
getTSConfig(): JSONValue
|
|
109
|
+
getTSConfig(): { [x: string]: JSONValue }
|
|
110
110
|
|
|
111
111
|
getConfigFieldsDefinitions(): ConfigFieldDefinition[]
|
|
112
112
|
setConfigFields(fields: ConfigField[]): void
|
|
113
113
|
|
|
114
114
|
generateConfigFile(): Promise<void>
|
|
115
115
|
readPackageJsonFile(): Promise<JSONValue>
|
|
116
|
-
generatePackageJson(): Promise<JSONValue>
|
|
116
|
+
generatePackageJson(): Promise<{ [x: string]: JSONValue }>
|
|
117
117
|
getConfigFileName(): string
|
|
118
118
|
checkEnvVariablesInConfigFile(): boolean
|
|
119
119
|
_beforePrepare(): Promise<void>
|
|
120
120
|
_afterPrepare(): Promise<void | JSONValue>
|
|
121
|
-
_getConfigFileContents(): Promise<JSONValue>
|
|
121
|
+
_getConfigFileContents(): Promise<{ [x: string]: BaseGenerator.JSONValue }>
|
|
122
122
|
_generateEnv(): Promise<void>
|
|
123
123
|
appendConfigEnv(): Promise<void>
|
|
124
124
|
|
|
@@ -89,7 +89,7 @@ async function execute (): Promise<void> {
|
|
|
89
89
|
type: 'string',
|
|
90
90
|
default: join(process.cwd(), '${kebabCase(stackableName + '-app')}')
|
|
91
91
|
},
|
|
92
|
-
port: { type: 'string'
|
|
92
|
+
port: { type: 'string' },
|
|
93
93
|
hostname: { type: 'string', default: '0.0.0.0' },
|
|
94
94
|
plugin: { type: 'boolean', default: true },
|
|
95
95
|
tests: { type: 'boolean', default: true },
|
|
@@ -102,7 +102,7 @@ async function execute (): Promise<void> {
|
|
|
102
102
|
const generator = new Generator()
|
|
103
103
|
|
|
104
104
|
generator.setConfig({
|
|
105
|
-
port: parseInt(args.values.port
|
|
105
|
+
port: parseInt(args.values.port || '3042'),
|
|
106
106
|
hostname: args.values.hostname,
|
|
107
107
|
plugin: args.values.plugin,
|
|
108
108
|
tests: args.values.tests,
|
|
@@ -36,8 +36,6 @@ stackable.configManagerConfig = {
|
|
|
36
36
|
stackable[Symbol.for('skip-override')] = true
|
|
37
37
|
|
|
38
38
|
module.exports = stackable
|
|
39
|
-
module.exports.schema = schema
|
|
40
|
-
module.exports.Generator = Generator
|
|
41
39
|
`
|
|
42
40
|
}
|
|
43
41
|
|
|
@@ -266,7 +264,7 @@ type PackageJson = {
|
|
|
266
264
|
class ${stackableGeneratorType} extends ServiceGenerator {
|
|
267
265
|
private _packageJson: PackageJson | null = null
|
|
268
266
|
|
|
269
|
-
getDefaultConfig (): BaseGenerator.JSONValue {
|
|
267
|
+
getDefaultConfig (): { [x: string]: BaseGenerator.JSONValue } {
|
|
270
268
|
const defaultBaseConfig = super.getDefaultConfig()
|
|
271
269
|
const defaultConfig = {
|
|
272
270
|
greeting: 'Hello world!'
|
|
@@ -287,7 +285,7 @@ class ${stackableGeneratorType} extends ServiceGenerator {
|
|
|
287
285
|
]
|
|
288
286
|
}
|
|
289
287
|
|
|
290
|
-
async _getConfigFileContents (): Promise<BaseGenerator.JSONValue> {
|
|
288
|
+
async _getConfigFileContents (): Promise<{ [x: string]: BaseGenerator.JSONValue }> {
|
|
291
289
|
const baseConfig = await super._getConfigFileContents()
|
|
292
290
|
const packageJson = await this.getStackablePackageJson()
|
|
293
291
|
const config = {
|
|
@@ -402,6 +400,9 @@ function getTsStackableSchemaFile (stackableName) {
|
|
|
402
400
|
|
|
403
401
|
return `\
|
|
404
402
|
import { schema } from '@platformatic/service'
|
|
403
|
+
import { readFileSync } from 'node:fs'
|
|
404
|
+
|
|
405
|
+
const { version } = JSON.parse(readFileSync('package.json', 'utf8'))
|
|
405
406
|
|
|
406
407
|
const ${schemaVarName} = {
|
|
407
408
|
...schema.schema,
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { kebabCase } = require('change-case-all')
|
|
4
|
+
|
|
5
|
+
function getJsStackableIndexTestFile (stackableName) {
|
|
6
|
+
const configType = kebabCase(stackableName + '-app')
|
|
7
|
+
|
|
8
|
+
return `\
|
|
9
|
+
'use strict'
|
|
10
|
+
|
|
11
|
+
const test = require('node:test')
|
|
12
|
+
const assert = require('node:assert')
|
|
13
|
+
const stackable = require('../index')
|
|
14
|
+
const { schema } = require('../lib/schema')
|
|
15
|
+
const { Generator } = require('../lib/generator')
|
|
16
|
+
|
|
17
|
+
test('should export stackable interface', async () => {
|
|
18
|
+
assert.strictEqual(typeof stackable, 'function')
|
|
19
|
+
assert.strictEqual(stackable.configType, '${configType}')
|
|
20
|
+
assert.deepStrictEqual(stackable.schema, schema)
|
|
21
|
+
assert.deepStrictEqual(stackable.Generator, Generator)
|
|
22
|
+
assert.ok(stackable.configManagerConfig)
|
|
23
|
+
assert.ok(typeof stackable.transformConfig, 'function')
|
|
24
|
+
})
|
|
25
|
+
`
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getTsStackableIndexTestFile (stackableName) {
|
|
29
|
+
const configType = kebabCase(stackableName + '-app')
|
|
30
|
+
|
|
31
|
+
return `\
|
|
32
|
+
import test from 'node:test'
|
|
33
|
+
import assert from 'node:assert'
|
|
34
|
+
import stackable from '../index'
|
|
35
|
+
import { schema } from '../lib/schema'
|
|
36
|
+
import { Generator } from '../lib/generator'
|
|
37
|
+
|
|
38
|
+
test('should export stackable interface', async () => {
|
|
39
|
+
assert.strictEqual(typeof stackable, 'function')
|
|
40
|
+
assert.strictEqual(stackable.configType, '${configType}')
|
|
41
|
+
assert.deepStrictEqual(stackable.schema, schema)
|
|
42
|
+
assert.deepStrictEqual(stackable.Generator, Generator)
|
|
43
|
+
assert.ok(stackable.configManagerConfig)
|
|
44
|
+
assert.ok(typeof stackable.transformConfig, 'function')
|
|
45
|
+
})
|
|
46
|
+
`
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getJsStackableSchemaTestFile (stackableName) {
|
|
50
|
+
const schemaId = kebabCase(stackableName)
|
|
51
|
+
|
|
52
|
+
return `\
|
|
53
|
+
'use strict'
|
|
54
|
+
|
|
55
|
+
const test = require('node:test')
|
|
56
|
+
const assert = require('node:assert')
|
|
57
|
+
const { schema } = require('../index')
|
|
58
|
+
|
|
59
|
+
test('should export stackable schema', async () => {
|
|
60
|
+
assert.strictEqual(schema.$id, '${schemaId}')
|
|
61
|
+
assert.strictEqual(typeof schema.version, 'string')
|
|
62
|
+
|
|
63
|
+
assert.deepStrictEqual(schema.properties.greeting, {
|
|
64
|
+
type: 'object',
|
|
65
|
+
properties: {
|
|
66
|
+
text: {
|
|
67
|
+
type: 'string'
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
required: ['text'],
|
|
71
|
+
additionalProperties: false
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
`
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function getTsStackableSchemaTestFile (stackableName) {
|
|
78
|
+
const schemaId = kebabCase(stackableName)
|
|
79
|
+
|
|
80
|
+
return `\
|
|
81
|
+
import test from 'node:test'
|
|
82
|
+
import assert from 'node:assert'
|
|
83
|
+
import { schema } from '../index'
|
|
84
|
+
|
|
85
|
+
test('should export stackable schema', async () => {
|
|
86
|
+
assert.strictEqual(schema.$id, '${schemaId}')
|
|
87
|
+
assert.strictEqual(typeof schema.version, 'string')
|
|
88
|
+
|
|
89
|
+
assert.deepStrictEqual(schema.properties.greeting, {
|
|
90
|
+
type: 'object',
|
|
91
|
+
properties: {
|
|
92
|
+
text: {
|
|
93
|
+
type: 'string'
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
required: ['text'],
|
|
97
|
+
additionalProperties: false
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
`
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function getJsStackableGeneratorTestFile () {
|
|
104
|
+
return `\
|
|
105
|
+
'use strict'
|
|
106
|
+
|
|
107
|
+
const test = require('node:test')
|
|
108
|
+
const assert = require('node:assert')
|
|
109
|
+
const { tmpdir } = require('node:os')
|
|
110
|
+
const { join } = require('node:path')
|
|
111
|
+
const { readFile, readdir, mkdtemp, rm } = require('node:fs/promises')
|
|
112
|
+
const { Generator } = require('../index')
|
|
113
|
+
const stackablePackageJson = require('../package.json')
|
|
114
|
+
|
|
115
|
+
test('should return a default Generator config', async () => {
|
|
116
|
+
const generator = new Generator()
|
|
117
|
+
const defaultConfig = generator.getDefaultConfig()
|
|
118
|
+
|
|
119
|
+
assert.strictEqual(defaultConfig.hostname, '0.0.0.0')
|
|
120
|
+
assert.strictEqual(defaultConfig.port, 3042)
|
|
121
|
+
assert.strictEqual(defaultConfig.greeting, 'Hello world!')
|
|
122
|
+
assert.deepStrictEqual(defaultConfig.env, {})
|
|
123
|
+
assert.deepStrictEqual(defaultConfig.dependencies, {})
|
|
124
|
+
assert.deepStrictEqual(defaultConfig.devDependencies, {})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('should return Generator config fields definitions', async () => {
|
|
128
|
+
const generator = new Generator()
|
|
129
|
+
const configFieldsDefs = generator.getConfigFieldsDefinitions()
|
|
130
|
+
|
|
131
|
+
const hostnameField = configFieldsDefs.find(
|
|
132
|
+
field => field.var === 'PLT_SERVER_HOSTNAME'
|
|
133
|
+
)
|
|
134
|
+
assert.deepStrictEqual(hostnameField, {
|
|
135
|
+
var: 'PLT_SERVER_HOSTNAME',
|
|
136
|
+
label: 'What is the hostname?',
|
|
137
|
+
default: '0.0.0.0',
|
|
138
|
+
type: 'string',
|
|
139
|
+
configValue: 'hostname'
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
const portField = configFieldsDefs.find(
|
|
143
|
+
field => field.var === 'PORT'
|
|
144
|
+
)
|
|
145
|
+
assert.deepStrictEqual(portField, {
|
|
146
|
+
var: 'PORT',
|
|
147
|
+
label: 'Which port do you want to use?',
|
|
148
|
+
default: 3042,
|
|
149
|
+
type: 'number',
|
|
150
|
+
configValue: 'port'
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
const greetingField = configFieldsDefs.find(
|
|
154
|
+
field => field.var === 'PLT_GREETING_TEXT'
|
|
155
|
+
)
|
|
156
|
+
assert.deepStrictEqual(greetingField, {
|
|
157
|
+
var: 'PLT_GREETING_TEXT',
|
|
158
|
+
label: 'What should the stackable greeting say?',
|
|
159
|
+
default: 'Hello world!',
|
|
160
|
+
type: 'string'
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
test('should generate a stackable app', async (t) => {
|
|
165
|
+
const testDir = await mkdtemp(join(tmpdir(), 'stackable-'))
|
|
166
|
+
t.after(() => rm(testDir, { recursive: true, force: true }))
|
|
167
|
+
|
|
168
|
+
const generator = new Generator()
|
|
169
|
+
|
|
170
|
+
generator.setConfig({
|
|
171
|
+
serviceName: 'stackable-app',
|
|
172
|
+
targetDirectory: testDir
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
await generator.prepare()
|
|
176
|
+
await generator.writeFiles()
|
|
177
|
+
|
|
178
|
+
const files = await readdir(testDir)
|
|
179
|
+
assert.deepStrictEqual(files.sort(), [
|
|
180
|
+
'.env',
|
|
181
|
+
'.env.sample',
|
|
182
|
+
'.gitignore',
|
|
183
|
+
'global.d.ts',
|
|
184
|
+
'package.json',
|
|
185
|
+
'platformatic.json',
|
|
186
|
+
'stackable.schema.json'
|
|
187
|
+
])
|
|
188
|
+
|
|
189
|
+
const packageJson = require(join(testDir, 'package.json'))
|
|
190
|
+
assert.strictEqual(packageJson.name, 'stackable-app')
|
|
191
|
+
|
|
192
|
+
const envFile = await readFile(join(testDir, '.env'), 'utf8')
|
|
193
|
+
const envVars = envFile.split('\\n').filter(Boolean)
|
|
194
|
+
assert.deepStrictEqual(envVars.sort(), [
|
|
195
|
+
'PLT_GREETING_TEXT=Hello world!',
|
|
196
|
+
'PLT_SERVER_HOSTNAME=0.0.0.0',
|
|
197
|
+
'PLT_SERVER_LOGGER_LEVEL=info',
|
|
198
|
+
'PLT_TYPESCRIPT=false',
|
|
199
|
+
'PORT=3042'
|
|
200
|
+
])
|
|
201
|
+
|
|
202
|
+
const stackableConfig = require(join(testDir, 'platformatic.json'))
|
|
203
|
+
const stackableName = stackablePackageJson.name
|
|
204
|
+
const stackableVersion = stackablePackageJson.version
|
|
205
|
+
|
|
206
|
+
assert.deepStrictEqual(stackableConfig, {
|
|
207
|
+
$schema: './stackable.schema.json',
|
|
208
|
+
module: \`\${stackableName}@\${stackableVersion}\`,
|
|
209
|
+
server: {
|
|
210
|
+
hostname: '{PLT_SERVER_HOSTNAME}',
|
|
211
|
+
port: '{PORT}',
|
|
212
|
+
logger: {
|
|
213
|
+
level: '{PLT_SERVER_LOGGER_LEVEL}'
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
service: {
|
|
217
|
+
openapi: true
|
|
218
|
+
},
|
|
219
|
+
greeting: {
|
|
220
|
+
text: '{PLT_GREETING_TEXT}'
|
|
221
|
+
},
|
|
222
|
+
watch: true
|
|
223
|
+
})
|
|
224
|
+
})
|
|
225
|
+
`
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function getTsStackableGeneratorTestFile () {
|
|
229
|
+
return `\
|
|
230
|
+
import test from 'node:test'
|
|
231
|
+
import assert from 'node:assert'
|
|
232
|
+
import { tmpdir } from 'node:os'
|
|
233
|
+
import { join } from 'node:path'
|
|
234
|
+
import { readFile, readdir, mkdtemp, rm } from 'node:fs/promises'
|
|
235
|
+
import { readFileSync } from 'node:fs'
|
|
236
|
+
import { Generator } from '../index'
|
|
237
|
+
|
|
238
|
+
const stackablePackageJsonPath = require.resolve('../../package.json')
|
|
239
|
+
const stackablePackageJson = JSON.parse(readFileSync(stackablePackageJsonPath, 'utf8'))
|
|
240
|
+
|
|
241
|
+
test('should return a default Generator config', async () => {
|
|
242
|
+
const generator = new Generator()
|
|
243
|
+
const defaultConfig = generator.getDefaultConfig()
|
|
244
|
+
|
|
245
|
+
assert.strictEqual(defaultConfig.hostname, '0.0.0.0')
|
|
246
|
+
assert.strictEqual(defaultConfig.port, 3042)
|
|
247
|
+
assert.strictEqual(defaultConfig.greeting, 'Hello world!')
|
|
248
|
+
assert.deepStrictEqual(defaultConfig.env, {})
|
|
249
|
+
assert.deepStrictEqual(defaultConfig.dependencies, {})
|
|
250
|
+
assert.deepStrictEqual(defaultConfig.devDependencies, {})
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
test('should return Generator config fields definitions', async () => {
|
|
254
|
+
const generator = new Generator()
|
|
255
|
+
const configFieldsDefs = generator.getConfigFieldsDefinitions()
|
|
256
|
+
|
|
257
|
+
const hostnameField = configFieldsDefs.find(
|
|
258
|
+
field => field.var === 'PLT_SERVER_HOSTNAME'
|
|
259
|
+
)
|
|
260
|
+
assert.deepStrictEqual(hostnameField, {
|
|
261
|
+
var: 'PLT_SERVER_HOSTNAME',
|
|
262
|
+
label: 'What is the hostname?',
|
|
263
|
+
default: '0.0.0.0',
|
|
264
|
+
type: 'string',
|
|
265
|
+
configValue: 'hostname'
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
const portField = configFieldsDefs.find(
|
|
269
|
+
field => field.var === 'PORT'
|
|
270
|
+
)
|
|
271
|
+
assert.deepStrictEqual(portField, {
|
|
272
|
+
var: 'PORT',
|
|
273
|
+
label: 'Which port do you want to use?',
|
|
274
|
+
default: 3042,
|
|
275
|
+
type: 'number',
|
|
276
|
+
configValue: 'port'
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
const greetingField = configFieldsDefs.find(
|
|
280
|
+
field => field.var === 'PLT_GREETING_TEXT'
|
|
281
|
+
)
|
|
282
|
+
assert.deepStrictEqual(greetingField, {
|
|
283
|
+
var: 'PLT_GREETING_TEXT',
|
|
284
|
+
label: 'What should the stackable greeting say?',
|
|
285
|
+
default: 'Hello world!',
|
|
286
|
+
type: 'string'
|
|
287
|
+
})
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
test('should generate a stackable app', async (t) => {
|
|
291
|
+
const testDir = await mkdtemp(join(tmpdir(), 'stackable-'))
|
|
292
|
+
t.after(() => rm(testDir, { recursive: true, force: true }))
|
|
293
|
+
|
|
294
|
+
const generator = new Generator()
|
|
295
|
+
|
|
296
|
+
generator.setConfig({
|
|
297
|
+
serviceName: 'stackable-app',
|
|
298
|
+
targetDirectory: testDir
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
await generator.prepare()
|
|
302
|
+
await generator.writeFiles()
|
|
303
|
+
|
|
304
|
+
const files = await readdir(testDir)
|
|
305
|
+
assert.deepStrictEqual(files.sort(), [
|
|
306
|
+
'.env',
|
|
307
|
+
'.env.sample',
|
|
308
|
+
'.gitignore',
|
|
309
|
+
'global.d.ts',
|
|
310
|
+
'package.json',
|
|
311
|
+
'platformatic.json',
|
|
312
|
+
'stackable.schema.json'
|
|
313
|
+
])
|
|
314
|
+
|
|
315
|
+
const packageJson = require(join(testDir, 'package.json'))
|
|
316
|
+
assert.strictEqual(packageJson.name, 'stackable-app')
|
|
317
|
+
|
|
318
|
+
const envFile = await readFile(join(testDir, '.env'), 'utf8')
|
|
319
|
+
const envVars = envFile.split('\\n').filter(Boolean)
|
|
320
|
+
assert.deepStrictEqual(envVars.sort(), [
|
|
321
|
+
'PLT_GREETING_TEXT=Hello world!',
|
|
322
|
+
'PLT_SERVER_HOSTNAME=0.0.0.0',
|
|
323
|
+
'PLT_SERVER_LOGGER_LEVEL=info',
|
|
324
|
+
'PLT_TYPESCRIPT=false',
|
|
325
|
+
'PORT=3042'
|
|
326
|
+
])
|
|
327
|
+
|
|
328
|
+
const stackableConfig = require(join(testDir, 'platformatic.json'))
|
|
329
|
+
const stackableName = stackablePackageJson.name
|
|
330
|
+
const stackableVersion = stackablePackageJson.version
|
|
331
|
+
|
|
332
|
+
assert.deepStrictEqual(stackableConfig, {
|
|
333
|
+
$schema: './stackable.schema.json',
|
|
334
|
+
module: \`\${stackableName}@\${stackableVersion}\`,
|
|
335
|
+
server: {
|
|
336
|
+
hostname: '{PLT_SERVER_HOSTNAME}',
|
|
337
|
+
port: '{PORT}',
|
|
338
|
+
logger: {
|
|
339
|
+
level: '{PLT_SERVER_LOGGER_LEVEL}'
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
service: {
|
|
343
|
+
openapi: true
|
|
344
|
+
},
|
|
345
|
+
greeting: {
|
|
346
|
+
text: '{PLT_GREETING_TEXT}'
|
|
347
|
+
},
|
|
348
|
+
watch: true
|
|
349
|
+
})
|
|
350
|
+
})
|
|
351
|
+
`
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function generateStackableTests (typescript, stackableName) {
|
|
355
|
+
if (typescript) {
|
|
356
|
+
return [
|
|
357
|
+
{
|
|
358
|
+
path: 'test',
|
|
359
|
+
file: 'index.test.ts',
|
|
360
|
+
contents: getTsStackableIndexTestFile(stackableName)
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
path: 'test',
|
|
364
|
+
file: 'schema.test.ts',
|
|
365
|
+
contents: getTsStackableSchemaTestFile(stackableName)
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
path: 'test',
|
|
369
|
+
file: 'generator.test.ts',
|
|
370
|
+
contents: getTsStackableGeneratorTestFile()
|
|
371
|
+
}
|
|
372
|
+
]
|
|
373
|
+
}
|
|
374
|
+
return [
|
|
375
|
+
{
|
|
376
|
+
path: 'test',
|
|
377
|
+
file: 'index.test.js',
|
|
378
|
+
contents: getJsStackableIndexTestFile(stackableName)
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
path: 'test',
|
|
382
|
+
file: 'schema.test.js',
|
|
383
|
+
contents: getJsStackableSchemaTestFile(stackableName)
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
path: 'test',
|
|
387
|
+
file: 'generator.test.js',
|
|
388
|
+
contents: getJsStackableGeneratorTestFile()
|
|
389
|
+
}
|
|
390
|
+
]
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
module.exports = {
|
|
394
|
+
generateStackableTests
|
|
395
|
+
}
|
|
@@ -10,6 +10,7 @@ const { generateGitignore } = require('./create-gitignore')
|
|
|
10
10
|
const { generateStackableCli } = require('./create-stackable-cli')
|
|
11
11
|
const { generateStackableFiles } = require('./create-stackable-files')
|
|
12
12
|
const { generateStackablePlugins } = require('./create-stackable-plugin')
|
|
13
|
+
const { generateStackableTests } = require('./create-stackable-tests')
|
|
13
14
|
|
|
14
15
|
/* c8 ignore start */
|
|
15
16
|
const fakeLogger = {
|
|
@@ -109,6 +110,7 @@ class StackableGenerator extends FileGenerator {
|
|
|
109
110
|
this.files.push(...generateStackableFiles(typescript, stackableName))
|
|
110
111
|
this.files.push(...generateStackableCli(typescript, stackableName))
|
|
111
112
|
this.files.push(...generateStackablePlugins(typescript))
|
|
113
|
+
this.files.push(...generateStackableTests(typescript, stackableName))
|
|
112
114
|
this.files.push(generateGitignore())
|
|
113
115
|
|
|
114
116
|
await this._afterPrepare()
|
|
@@ -209,6 +211,7 @@ class StackableGenerator extends FileGenerator {
|
|
|
209
211
|
}
|
|
210
212
|
|
|
211
213
|
const devDependencies = {
|
|
214
|
+
borp: '^0.10.0',
|
|
212
215
|
fastify: `^${this.fastifyVersion}`
|
|
213
216
|
}
|
|
214
217
|
|
|
@@ -233,7 +236,8 @@ class StackableGenerator extends FileGenerator {
|
|
|
233
236
|
'gen-schema': 'node lib/schema.js > schema.json',
|
|
234
237
|
'gen-types': 'json2ts > config.d.ts < schema.json',
|
|
235
238
|
'build:config': 'pnpm run gen-schema && pnpm run gen-types',
|
|
236
|
-
clean: 'rm -fr ./dist'
|
|
239
|
+
clean: 'rm -fr ./dist',
|
|
240
|
+
test: 'borp'
|
|
237
241
|
},
|
|
238
242
|
engines: {
|
|
239
243
|
node: '^18.8.0 || >=20.6.0'
|
|
@@ -247,9 +251,6 @@ class StackableGenerator extends FileGenerator {
|
|
|
247
251
|
...dependencies,
|
|
248
252
|
'@platformatic/generators': `^${this.platformaticVersion}`,
|
|
249
253
|
...this.config.dependencies
|
|
250
|
-
},
|
|
251
|
-
overrides: {
|
|
252
|
-
minimatch: '^5.0.0'
|
|
253
254
|
}
|
|
254
255
|
}
|
|
255
256
|
}
|
|
@@ -267,7 +268,8 @@ class StackableGenerator extends FileGenerator {
|
|
|
267
268
|
'gen-types': 'json2ts > config.d.ts < schema.json',
|
|
268
269
|
'build:config': 'pnpm run gen-schema && pnpm run gen-types',
|
|
269
270
|
prepublishOnly: 'pnpm run build:config',
|
|
270
|
-
lint: 'standard'
|
|
271
|
+
lint: 'standard',
|
|
272
|
+
test: 'borp'
|
|
271
273
|
},
|
|
272
274
|
engines: {
|
|
273
275
|
node: '^18.8.0 || >=20.6.0'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/generators",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.33.0",
|
|
4
4
|
"description": "Main classes and utils for generators.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [],
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"c8": "^9.1.0",
|
|
21
21
|
"snazzy": "^9.0.0",
|
|
22
22
|
"standard": "^17.1.0",
|
|
23
|
-
"tsd": "^0.
|
|
23
|
+
"tsd": "^0.31.0",
|
|
24
24
|
"typescript": "^5.4.2"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
@@ -53,6 +53,15 @@ test('should create a stackable project without typescript', async (t) => {
|
|
|
53
53
|
|
|
54
54
|
const gitignore = await readFile(join(dir, '.gitignore'), 'utf8')
|
|
55
55
|
assert.ok(gitignore.length > 0)
|
|
56
|
+
|
|
57
|
+
const testIndexFile = await readFile(join(dir, 'test', 'index.test.js'), 'utf8')
|
|
58
|
+
assert.ok(testIndexFile.length > 0)
|
|
59
|
+
|
|
60
|
+
const testSchemaFile = await readFile(join(dir, 'test', 'schema.test.js'), 'utf8')
|
|
61
|
+
assert.ok(testSchemaFile.length > 0)
|
|
62
|
+
|
|
63
|
+
const testGeneratorFile = await readFile(join(dir, 'test', 'generator.test.js'), 'utf8')
|
|
64
|
+
assert.ok(testGeneratorFile.length > 0)
|
|
56
65
|
})
|
|
57
66
|
|
|
58
67
|
test('should create a stackable project with typescript', async (t) => {
|
|
@@ -93,4 +102,13 @@ test('should create a stackable project with typescript', async (t) => {
|
|
|
93
102
|
|
|
94
103
|
const gitignore = await readFile(join(dir, '.gitignore'), 'utf8')
|
|
95
104
|
assert.ok(gitignore.length > 0)
|
|
105
|
+
|
|
106
|
+
const testIndexFile = await readFile(join(dir, 'test', 'index.test.ts'), 'utf8')
|
|
107
|
+
assert.ok(testIndexFile.length > 0)
|
|
108
|
+
|
|
109
|
+
const testSchemaFile = await readFile(join(dir, 'test', 'schema.test.ts'), 'utf8')
|
|
110
|
+
assert.ok(testSchemaFile.length > 0)
|
|
111
|
+
|
|
112
|
+
const testGeneratorFile = await readFile(join(dir, 'test', 'generator.test.ts'), 'utf8')
|
|
113
|
+
assert.ok(testGeneratorFile.length > 0)
|
|
96
114
|
})
|