@platformatic/generators 2.63.3 → 2.64.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.d.ts CHANGED
@@ -1,8 +1,5 @@
1
1
  import { BaseGenerator } from './lib/base-generator'
2
- import { generateTests, generatePlugins } from './lib/create-plugin'
2
+ import { generatePlugins, generateTests } from './lib/create-plugin'
3
+ import { FileGenerator } from './lib/file-generator'
3
4
 
4
- export {
5
- BaseGenerator,
6
- generateTests,
7
- generatePlugins,
8
- }
5
+ export { BaseGenerator, FileGenerator, generatePlugins, generateTests }
@@ -20,11 +20,11 @@ const { flattenObject } = require('./utils')
20
20
  const { envStringToObject } = require('./utils')
21
21
  /* c8 ignore start */
22
22
  const fakeLogger = {
23
- info: () => {},
24
- warn: () => {},
25
- debug: () => {},
26
- trace: () => {},
27
- error: () => {},
23
+ info: () => { },
24
+ warn: () => { },
25
+ debug: () => { },
26
+ trace: () => { },
27
+ error: () => { },
28
28
  }
29
29
  /* c8 ignore start */
30
30
 
@@ -40,6 +40,7 @@ class BaseGenerator extends FileGenerator {
40
40
  this.config = this.getDefaultConfig()
41
41
  this.packages = []
42
42
  this.module = opts.module
43
+ this.runtimeConfig = opts.runtimeConfig ?? 'platformatic.json'
43
44
  if (!this.module) {
44
45
  throw ModuleNeeded()
45
46
  }
@@ -175,8 +176,8 @@ class BaseGenerator extends FileGenerator {
175
176
  if (this.config.isUpdating) {
176
177
  // only the packages options may have changed, let's update those
177
178
  await this.generateConfigFile()
178
- const generatedConfigFile = JSON.parse(this.getFileObject('platformatic.json', '').contents)
179
- const fileFromDisk = await this.loadFile({ file: 'platformatic.json', path: '' })
179
+ const generatedConfigFile = JSON.parse(this.getFileObject(this.runtimeConfig, '').contents)
180
+ const fileFromDisk = await this.loadFile({ file: this.runtimeConfig, path: '' })
180
181
  const currentConfigFile = JSON.parse(fileFromDisk.contents)
181
182
  if (currentConfigFile.plugins) {
182
183
  if (generatedConfigFile.plugins && generatedConfigFile.plugins.packages) {
@@ -189,7 +190,7 @@ class BaseGenerator extends FileGenerator {
189
190
  this.reset()
190
191
  this.addFile({
191
192
  path: '',
192
- file: 'platformatic.json',
193
+ file: this.runtimeConfig,
193
194
  contents: JSON.stringify(currentConfigFile, null, 2),
194
195
  })
195
196
  } else {
@@ -251,7 +252,7 @@ class BaseGenerator extends FileGenerator {
251
252
 
252
253
  checkEnvVariablesInConfigFile () {
253
254
  const excludedEnvs = [PLT_ROOT]
254
- const configFileName = 'platformatic.json'
255
+ const configFileName = this.runtimeConfig
255
256
  const fileObject = this.getFileObject(configFileName)
256
257
  const envVars = extractEnvVariablesFromText(fileObject.contents)
257
258
  const envKeys = Object.keys(this.config.env)
@@ -323,7 +324,7 @@ class BaseGenerator extends FileGenerator {
323
324
  }
324
325
 
325
326
  async generateConfigFile () {
326
- const configFileName = 'platformatic.json'
327
+ const configFileName = this.runtimeConfig
327
328
  const contents = await this._getConfigFileContents()
328
329
  // handle packages
329
330
  if (this.packages.length > 0) {
@@ -392,7 +393,7 @@ class BaseGenerator extends FileGenerator {
392
393
  ...this.config.dependencies,
393
394
  },
394
395
  engines: {
395
- node: '^18.8.0 || >=20.6.0',
396
+ node: '^22.14.0 || ^20.6.0',
396
397
  },
397
398
  }
398
399
 
@@ -451,7 +452,7 @@ class BaseGenerator extends FileGenerator {
451
452
  }
452
453
 
453
454
  async loadFromDir (serviceName, runtimeRootPath) {
454
- const runtimePkgConfigFileData = JSON.parse(await readFile(join(runtimeRootPath, 'platformatic.json'), 'utf-8'))
455
+ const runtimePkgConfigFileData = JSON.parse(await readFile(join(runtimeRootPath, this.runtimeConfig), 'utf-8'))
455
456
  const servicesPath = runtimePkgConfigFileData.autoload.path
456
457
  const servicePkgJsonFileData = JSON.parse(await readFile(join(runtimeRootPath, servicesPath, serviceName, 'platformatic.json'), 'utf-8'))
457
458
  const runtimeEnv = envStringToObject(await readFile(join(runtimeRootPath, '.env'), 'utf-8'))
@@ -494,9 +495,9 @@ class BaseGenerator extends FileGenerator {
494
495
 
495
496
  // implement in the subclass
496
497
  /* c8 ignore next 1 */
497
- async postInstallActions () {}
498
- async _beforePrepare () {}
499
- async _afterPrepare () {}
498
+ async postInstallActions () { }
499
+ async _beforePrepare () { }
500
+ async _afterPrepare () { }
500
501
  async _getConfigFileContents () { return {} }
501
502
  }
502
503
 
@@ -61,7 +61,7 @@ class FileGenerator {
61
61
  }
62
62
  await createDirectory(this.targetDirectory)
63
63
  for (const fileToWrite of this.files) {
64
- if (fileToWrite.contents.length === 0) {
64
+ if (fileToWrite.contents.length === 0 && !fileToWrite.file.match(/^\..+keep$/)) {
65
65
  continue
66
66
  }
67
67
  const baseDir = join(this.targetDirectory, fileToWrite.path)
package/lib/utils.js CHANGED
@@ -18,6 +18,7 @@ function stripVersion (version) {
18
18
  if (match) {
19
19
  return match[0]
20
20
  }
21
+ /* c8 ignore next */
21
22
  return version
22
23
  }
23
24
 
@@ -70,7 +71,7 @@ function extractEnvVariablesFromText (text) {
70
71
  function getPackageConfigurationObject (config, serviceName = '') {
71
72
  const output = {
72
73
  config: {},
73
- env: {},
74
+ env: {}
74
75
  }
75
76
  let current = output.config
76
77
  for (const param of config) {
@@ -172,6 +173,7 @@ function flattenObject (ob) {
172
173
  function getServiceTemplateFromSchemaUrl (schemaUrl) {
173
174
  const splitted = schemaUrl.split('/')
174
175
 
176
+ /* c8 ignore next 3 - Legacy interface */
175
177
  if (schemaUrl.startsWith('https://platformatic.dev/schemas')) {
176
178
  return `@platformatic/${splitted[splitted.length - 1]}`
177
179
  }
@@ -190,5 +192,5 @@ module.exports = {
190
192
  createDirectory,
191
193
  stripVersion,
192
194
  PLT_ROOT,
193
- getLatestNpmVersion,
195
+ getLatestNpmVersion
194
196
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/generators",
3
- "version": "2.63.3",
3
+ "version": "2.64.0",
4
4
  "description": "Main classes and utils for generators.",
5
5
  "main": "index.js",
6
6
  "keywords": [],
@@ -12,7 +12,7 @@
12
12
  "fastify": "^5.0.0",
13
13
  "pino": "^9.0.0",
14
14
  "undici": "^7.0.0",
15
- "@platformatic/utils": "2.63.3"
15
+ "@platformatic/utils": "2.64.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/inquirer": "^9.0.7",