@platformatic/generators 1.27.0 → 1.28.1

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.
@@ -367,10 +367,11 @@ class BaseGenerator extends FileGenerator {
367
367
  name: `${this.config.serviceName}`,
368
368
  scripts: {
369
369
  start: 'platformatic start',
370
- test: 'node --test test/**'
370
+ test: 'borp'
371
371
  },
372
372
  devDependencies: {
373
373
  fastify: `^${this.fastifyVersion}`,
374
+ borp: `${this.pkgData.devDependencies.borp}`,
374
375
  ...this.config.devDependencies
375
376
  },
376
377
  dependencies: {
@@ -45,7 +45,7 @@ async function execute () {
45
45
  },
46
46
  port: { type: 'string', default: '3042' },
47
47
  hostname: { type: 'string', default: '0.0.0.0' },
48
- plugins: { type: 'boolean', default: true },
48
+ plugin: { type: 'boolean', default: true },
49
49
  tests: { type: 'boolean', default: true },
50
50
  typescript: { type: 'boolean', default: false },
51
51
  git: { type: 'boolean', default: false },
@@ -58,7 +58,7 @@ async function execute () {
58
58
  generator.setConfig({
59
59
  port: parseInt(args.values.port),
60
60
  hostname: args.values.hostname,
61
- plugins: args.values.plugins,
61
+ plugin: args.values.plugin,
62
62
  tests: args.values.tests,
63
63
  typescript: args.values.typescript,
64
64
  initGitRepository: args.values.git,
@@ -81,7 +81,7 @@ import { join } from 'node:path'
81
81
  import { parseArgs } from 'node:util'
82
82
  import { Generator } from '../lib/generator'
83
83
 
84
- async function execute () {
84
+ async function execute (): Promise<void> {
85
85
  const args = parseArgs({
86
86
  args: process.argv.slice(2),
87
87
  options: {
@@ -91,7 +91,7 @@ async function execute () {
91
91
  },
92
92
  port: { type: 'string', default: '3042' },
93
93
  hostname: { type: 'string', default: '0.0.0.0' },
94
- plugins: { type: 'boolean', default: true },
94
+ plugin: { type: 'boolean', default: true },
95
95
  tests: { type: 'boolean', default: true },
96
96
  typescript: { type: 'boolean', default: false },
97
97
  git: { type: 'boolean', default: false },
@@ -104,7 +104,7 @@ async function execute () {
104
104
  generator.setConfig({
105
105
  port: parseInt(args.values.port as string),
106
106
  hostname: args.values.hostname,
107
- plugins: args.values.plugins,
107
+ plugin: args.values.plugin,
108
108
  tests: args.values.tests,
109
109
  typescript: args.values.typescript,
110
110
  initGitRepository: args.values.git,
@@ -116,7 +116,9 @@ async function execute () {
116
116
  console.log('Application created successfully! Run \`npm run start\` to start an application.')
117
117
  }
118
118
 
119
- execute()
119
+ execute().catch(err => {
120
+ throw err
121
+ })
120
122
  `
121
123
  }
122
124
 
@@ -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
  }
@@ -295,8 +300,8 @@ class ${stackableGeneratorType} extends ServiceGenerator {
295
300
  return Object.assign({}, baseConfig, config)
296
301
  }
297
302
 
298
- async _beforePrepare () {
299
- super._beforePrepare()
303
+ async _beforePrepare (): Promise<void> {
304
+ await super._beforePrepare()
300
305
 
301
306
  this.addEnvVars({
302
307
  PLT_GREETING_TEXT: this.config.greeting ?? 'Hello world!'
@@ -309,7 +314,7 @@ class ${stackableGeneratorType} extends ServiceGenerator {
309
314
  }
310
315
  }
311
316
 
312
- async _afterPrepare () {
317
+ async _afterPrepare (): Promise<void> {
313
318
  const packageJson = await this.getStackablePackageJson()
314
319
  this.addFile({
315
320
  path: '',
@@ -328,18 +333,18 @@ class ${stackableGeneratorType} extends ServiceGenerator {
328
333
  if (!this._packageJson) {
329
334
  const packageJsonPath = join(__dirname, '..', '..', 'package.json')
330
335
  const packageJsonFile = await readFile(packageJsonPath, 'utf8')
331
- const packageJson = JSON.parse(packageJsonFile)
336
+ const packageJson: Partial<PackageJson> = JSON.parse(packageJsonFile)
332
337
 
333
- if (!packageJson.name) {
338
+ if (packageJson.name === undefined || packageJson.name === null) {
334
339
  throw new Error('Missing package name in package.json')
335
340
  }
336
341
 
337
- if (!packageJson.version) {
342
+ if (packageJson.version === undefined || packageJson.version === null) {
338
343
  throw new Error('Missing package version in package.json')
339
344
  }
340
345
 
341
- this._packageJson = packageJson
342
- return packageJson
346
+ this._packageJson = packageJson as PackageJson
347
+ return packageJson as PackageJson
343
348
  }
344
349
  return this._packageJson
345
350
  }
@@ -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' },
@@ -16,6 +16,7 @@ module.exports = async function (fastify, opts) {
16
16
 
17
17
  function getTsStackablePluginFile () {
18
18
  return `\
19
+ // eslint-disable-next-line
19
20
  /// <reference path="../index.d.ts" />
20
21
  import { FastifyInstance, FastifyPluginOptions } from 'fastify'
21
22
 
@@ -230,7 +230,9 @@ class StackableGenerator extends FileGenerator {
230
230
  },
231
231
  scripts: {
232
232
  build: 'tsc --build',
233
- 'build:config': 'node ./dist/lib/schema.js | json2ts > config.d.ts',
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
- 'build:config': 'node lib/schema.js | json2ts > config.d.ts',
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.27.0",
3
+ "version": "1.28.1",
4
4
  "description": "Main classes and utils for generators.",
5
5
  "main": "index.js",
6
6
  "keywords": [],
@@ -10,9 +10,9 @@
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.0",
14
- "pino": "^8.17.2",
15
- "undici": "^6.6.0"
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",
@@ -20,8 +20,8 @@
20
20
  "c8": "^9.1.0",
21
21
  "snazzy": "^9.0.0",
22
22
  "standard": "^17.1.0",
23
- "tsd": "^0.30.4",
24
- "typescript": "^5.3.3"
23
+ "tsd": "^0.30.7",
24
+ "typescript": "^5.4.2"
25
25
  },
26
26
  "scripts": {
27
27
  "lint": "standard | snazzy",