@platformatic/generators 2.0.0-alpha.2 → 2.0.0-alpha.21

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.
@@ -0,0 +1,3 @@
1
+ 'use strict'
2
+
3
+ module.exports = require('neostandard')({ ts: true })
package/index.d.ts CHANGED
@@ -4,5 +4,5 @@ import { generateTests, generatePlugins } from './lib/create-plugin'
4
4
  export {
5
5
  BaseGenerator,
6
6
  generateTests,
7
- generatePlugins
7
+ generatePlugins,
8
8
  }
package/index.js CHANGED
@@ -1,12 +1,10 @@
1
1
  'use strict'
2
2
 
3
3
  const { BaseGenerator } = require('./lib/base-generator')
4
- const { StackableGenerator } = require('./lib/stackable-generator')
5
4
  const { generateTests } = require('./lib/create-plugin')
6
5
  const utils = require('./lib/utils')
7
6
  module.exports = {
8
7
  BaseGenerator,
9
- StackableGenerator,
10
8
  generateTests,
11
- ...utils
9
+ ...utils,
12
10
  }
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))
@@ -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
  }
@@ -2,12 +2,12 @@
2
2
 
3
3
  const { readFile } = require('node:fs/promises')
4
4
  const {
5
- stripVersion,
6
5
  convertServiceNameToPrefix,
7
6
  extractEnvVariablesFromText,
8
7
  getPackageConfigurationObject,
9
8
  PLT_ROOT,
10
- getLatestNpmVersion
9
+ getLatestNpmVersion,
10
+ stripVersion,
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,16 @@ class BaseGenerator extends FileGenerator {
280
280
  noEmitOnError: true,
281
281
  incremental: true,
282
282
  strict: true,
283
- outDir: 'dist'
283
+ outDir: 'dist',
284
+ skipLibCheck: true,
284
285
  },
285
286
  watchOptions: {
286
287
  watchFile: 'fixedPollingInterval',
287
288
  watchDirectory: 'fixedPollingInterval',
288
289
  fallbackPolling: 'dynamicPriority',
289
290
  synchronousWatchDirectory: true,
290
- excludeDirectories: ['**/node_modules', 'dist']
291
- }
291
+ excludeDirectories: ['**/node_modules', 'dist'],
292
+ },
292
293
  }
293
294
  }
294
295
 
@@ -299,7 +300,7 @@ class BaseGenerator extends FileGenerator {
299
300
  this.questions.push({
300
301
  type: 'input',
301
302
  name: 'targetDirectory',
302
- message: 'Where would you like to create your project?'
303
+ message: 'Where would you like to create your project?',
303
304
  })
304
305
  }
305
306
 
@@ -309,14 +310,14 @@ class BaseGenerator extends FileGenerator {
309
310
  name: 'typescript',
310
311
  message: 'Do you want to use TypeScript?',
311
312
  default: false,
312
- choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
313
+ choices: [{ name: 'yes', value: true }, { name: 'no', value: false }],
313
314
  })
314
315
 
315
316
  // port
316
317
  this.questions.push({
317
318
  type: 'input',
318
319
  name: 'port',
319
- message: 'What port do you want to use?'
320
+ message: 'What port do you want to use?',
320
321
  })
321
322
  }
322
323
  }
@@ -340,7 +341,7 @@ class BaseGenerator extends FileGenerator {
340
341
  }
341
342
  return {
342
343
  name: packageDefinition.name,
343
- options: packageConfigOutput.config
344
+ options: packageConfigOutput.config,
344
345
  }
345
346
  })
346
347
  }
@@ -348,7 +349,7 @@ class BaseGenerator extends FileGenerator {
348
349
  this.addFile({
349
350
  path: '',
350
351
  file: configFileName,
351
- contents: JSON.stringify(contents, null, 2)
352
+ contents: JSON.stringify(contents, null, 2),
352
353
  })
353
354
  }
354
355
 
@@ -372,7 +373,7 @@ class BaseGenerator extends FileGenerator {
372
373
 
373
374
  async getPlatformaticVersion () {
374
375
  const pkgData = await this.readPackageJsonFile()
375
- this.platformaticVersion = stripVersion(pkgData.version)
376
+ this.platformaticVersion = pkgData.version
376
377
  }
377
378
 
378
379
  async generatePackageJson () {
@@ -380,19 +381,19 @@ class BaseGenerator extends FileGenerator {
380
381
  name: `${this.config.serviceName}`,
381
382
  scripts: {
382
383
  start: 'platformatic start',
383
- test: 'borp'
384
+ test: 'borp',
384
385
  },
385
386
  devDependencies: {
386
387
  fastify: `^${this.fastifyVersion}`,
387
388
  borp: `${this.pkgData.devDependencies.borp}`,
388
- ...this.config.devDependencies
389
+ ...this.config.devDependencies,
389
390
  },
390
391
  dependencies: {
391
- ...this.config.dependencies
392
+ ...this.config.dependencies,
392
393
  },
393
394
  engines: {
394
- node: '^18.8.0 || >=20.6.0'
395
- }
395
+ node: '^18.8.0 || >=20.6.0',
396
+ },
396
397
  }
397
398
 
398
399
  if (this.config.typescript) {
@@ -409,7 +410,7 @@ class BaseGenerator extends FileGenerator {
409
410
  this.addFile({
410
411
  path: '',
411
412
  file: '.env',
412
- contents: serializeEnvVars(this.config.env)
413
+ contents: serializeEnvVars(this.config.env),
413
414
  })
414
415
 
415
416
  const emptyEnvVars = {}
@@ -424,8 +425,8 @@ class BaseGenerator extends FileGenerator {
424
425
  file: '.env.sample',
425
426
  contents: serializeEnvVars({
426
427
  ...this.config.defaultEnv,
427
- ...emptyEnvVars
428
- })
428
+ ...emptyEnvVars,
429
+ }),
429
430
  })
430
431
  }
431
432
  }
@@ -461,7 +462,7 @@ class BaseGenerator extends FileGenerator {
461
462
  const flattened = flattenObject(pkg)
462
463
  const output = {
463
464
  name: flattened.name,
464
- options: []
465
+ options: [],
465
466
  }
466
467
  if (pkg.options) {
467
468
  Object.entries(flattened)
@@ -473,7 +474,7 @@ class BaseGenerator extends FileGenerator {
473
474
  name: serviceEnvVarKey,
474
475
  path: key.replace('options.', ''),
475
476
  type: 'string',
476
- value: runtimeEnv[runtimeEnvVarKey]
477
+ value: runtimeEnv[runtimeEnvVarKey],
477
478
  }
478
479
  output.options.push(option)
479
480
  })
@@ -487,7 +488,7 @@ class BaseGenerator extends FileGenerator {
487
488
  name: serviceName,
488
489
  template: getServiceTemplateFromSchemaUrl(servicePkgJsonFileData.$schema),
489
490
  fields: [],
490
- plugins
491
+ plugins,
491
492
  }
492
493
  }
493
494
 
@@ -33,10 +33,10 @@ function generateGitignore () {
33
33
  return {
34
34
  path: '',
35
35
  file: '.gitignore',
36
- contents: gitignore
36
+ contents: gitignore,
37
37
  }
38
38
  }
39
39
 
40
40
  module.exports = {
41
- generateGitignore
41
+ generateGitignore,
42
42
  }
@@ -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>
@@ -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
  }
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
  }
@@ -4,27 +4,27 @@ export namespace FileGenerator {
4
4
  export type FileGeneratorOptions = {
5
5
  logger?: BaseLogger
6
6
  }
7
-
7
+
8
8
  export type FileObject = {
9
9
  path: string,
10
10
  file: string,
11
11
  contents: string
12
12
  }
13
-
13
+
14
14
  export class FileGenerator {
15
15
  files: FileObject[]
16
16
  targetDirectory: string
17
-
18
- constructor(opts?: FileGeneratorOptions)
19
-
20
- setTargetDirectory(dir: string): void
21
- addFile(file: FileObject): void
22
- appendfile(file: FileObject): void
23
- reset(): void
24
- writeFiles(): Promise<void>
25
- listFiles(): FileObject
26
- loadFile(): Promise<FileObject>
27
- getFileObject(file: string, path?: string): FileObject
17
+
18
+ constructor (opts?: FileGeneratorOptions)
19
+
20
+ setTargetDirectory (dir: string): void
21
+ addFile (file: FileObject): void
22
+ appendfile (file: FileObject): void
23
+ reset (): void
24
+ writeFiles (): Promise<void>
25
+ listFiles (): FileObject
26
+ loadFile (): Promise<FileObject>
27
+ getFileObject (file: string, path?: string): FileObject
28
28
  }
29
-
29
+
30
30
  }
@@ -1,5 +1,5 @@
1
1
  'use strict'
2
- const { safeMkdir } = require('./utils')
2
+ const { createDirectory } = require('@platformatic/utils')
3
3
  const { join } = require('node:path')
4
4
  const { writeFile, readFile } = require('node:fs/promises')
5
5
 
@@ -9,7 +9,7 @@ const fakeLogger = {
9
9
  warn: () => {},
10
10
  debug: () => {},
11
11
  trace: () => {},
12
- error: () => {}
12
+ error: () => {},
13
13
  }
14
14
  /* c8 ignore start */
15
15
 
@@ -59,14 +59,14 @@ class FileGenerator {
59
59
  if (!this.targetDirectory) {
60
60
  throw new Error('No target directory set.')
61
61
  }
62
- await safeMkdir(this.targetDirectory)
62
+ await createDirectory(this.targetDirectory)
63
63
  for (const fileToWrite of this.files) {
64
64
  if (fileToWrite.contents.length === 0) {
65
65
  continue
66
66
  }
67
67
  const baseDir = join(this.targetDirectory, fileToWrite.path)
68
68
  if (fileToWrite.path !== '') {
69
- await safeMkdir(baseDir)
69
+ await createDirectory(baseDir)
70
70
  }
71
71
  const fullFilePath = join(baseDir, fileToWrite.file)
72
72
  await writeFile(fullFilePath, fileToWrite.contents, fileToWrite.options)
package/lib/utils.d.ts CHANGED
@@ -9,14 +9,13 @@ export type PackageConfiguration = {
9
9
  }
10
10
 
11
11
  export namespace GeneratorUtils {
12
- export function safeMkdir(dir: string): Promise<void>
13
- export function stripVersion(version: string): string
14
- export function convertServiceNameToPrefix(serviceName: string): string
15
- export function envObjectToString(env: Env): string
16
- export function envStringToObject(env: string): Env
17
- export function extractEnvVariablesFromText(text: string): string[]
18
- export function getPackageConfigurationObject(config: PackageConfiguration[]): object
19
- export function flattenObject(obj: object): object
20
- export function getServiceTemplateFromSchemaUrl(schemaUrl: string): string
12
+ export function stripVersion (version: string): string
13
+ export function convertServiceNameToPrefix (serviceName: string): string
14
+ export function envObjectToString (env: Env): string
15
+ export function envStringToObject (env: string): Env
16
+ export function extractEnvVariablesFromText (text: string): string[]
17
+ export function getPackageConfigurationObject (config: PackageConfiguration[]): object
18
+ export function flattenObject (obj: object): object
19
+ export function getServiceTemplateFromSchemaUrl (schemaUrl: string): string
21
20
  export const PLT_ROOT: string
22
21
  }
package/lib/utils.js CHANGED
@@ -1,20 +1,12 @@
1
1
  'use strict'
2
2
 
3
- const { mkdir } = require('node:fs/promises')
4
3
  const { WrongTypeError } = require('./errors')
5
4
  const { join } = require('node:path')
6
5
  const { request } = require('undici')
7
6
  const { setTimeout } = require('timers/promises')
8
7
  const PLT_ROOT = 'PLT_ROOT'
9
8
  const { EOL } = require('node:os')
10
- async function safeMkdir (dir) {
11
- try {
12
- await mkdir(dir, { recursive: true })
13
- /* c8 ignore next 3 */
14
- } catch (err) {
15
- // do nothing
16
- }
17
- }
9
+ const { createDirectory } = require('@platformatic/utils')
18
10
 
19
11
  /**
20
12
  * Strip all extra characters from a simple semver version string
@@ -49,7 +41,7 @@ function addPrefixToString (input, prefix) {
49
41
 
50
42
  function envObjectToString (env) {
51
43
  const output = []
52
- Object.entries(env).forEach((kv) => {
44
+ Object.entries(env).forEach(kv => {
53
45
  output.push(`${kv[0]}=${kv[1]}`)
54
46
  })
55
47
  return output.join(EOL)
@@ -57,12 +49,12 @@ function envObjectToString (env) {
57
49
 
58
50
  function envStringToObject (envString) {
59
51
  const output = {}
60
- const split = envString.split(EOL)
52
+ const split = envString.split(/\r?\n/)
61
53
  split
62
- .filter((line) => {
54
+ .filter(line => {
63
55
  return line.trim() !== '' && line.indexOf('#') !== 0
64
56
  })
65
- .forEach((line) => {
57
+ .forEach(line => {
66
58
  const kv = line.split('=')
67
59
  output[kv[0]] = kv[1]
68
60
  })
@@ -71,16 +63,14 @@ function envStringToObject (envString) {
71
63
  function extractEnvVariablesFromText (text) {
72
64
  const match = text.match(/\{[a-zA-Z0-9-_]*\}/g)
73
65
  if (match) {
74
- return match
75
- .map((found) => found.replace('{', '').replace('}', ''))
76
- .filter((found) => found !== '')
66
+ return match.map(found => found.replace('{', '').replace('}', '')).filter(found => found !== '')
77
67
  }
78
68
  return []
79
69
  }
80
70
  function getPackageConfigurationObject (config, serviceName = '') {
81
71
  const output = {
82
72
  config: {},
83
- env: {}
73
+ env: {},
84
74
  }
85
75
  let current = output.config
86
76
  for (const param of config) {
@@ -90,14 +80,14 @@ function getPackageConfigurationObject (config, serviceName = '') {
90
80
  let value
91
81
  let isPath = false
92
82
  switch (param.type) {
93
- case 'string' :
83
+ case 'string':
94
84
  value = param.value.toString()
95
85
  break
96
86
  case 'number':
97
87
  value = parseInt(param.value)
98
88
  break
99
89
  case 'boolean':
100
- value = (param.value === 'true')
90
+ value = param.value === 'true'
101
91
  break
102
92
  case 'path':
103
93
  value = `${join(`{${PLT_ROOT}}`, param.value)}`
@@ -167,7 +157,7 @@ async function getLatestNpmVersion (pkg) {
167
157
  function flattenObject (ob) {
168
158
  const result = {}
169
159
  for (const i in ob) {
170
- if ((typeof ob[i]) === 'object' && !Array.isArray(ob[i])) {
160
+ if (typeof ob[i] === 'object' && !Array.isArray(ob[i])) {
171
161
  const temp = flattenObject(ob[i])
172
162
  for (const j in temp) {
173
163
  result[i + '.' + j] = temp[j]
@@ -181,8 +171,13 @@ function flattenObject (ob) {
181
171
 
182
172
  function getServiceTemplateFromSchemaUrl (schemaUrl) {
183
173
  const splitted = schemaUrl.split('/')
184
- return `@platformatic/${splitted[splitted.length - 1]}`
174
+
175
+ if (schemaUrl.startsWith('https://platformatic.dev/schemas')) {
176
+ return `@platformatic/${splitted[splitted.length - 1]}`
177
+ }
178
+ return `@platformatic/${splitted[splitted.length - 2]}`
185
179
  }
180
+
186
181
  module.exports = {
187
182
  addPrefixToString,
188
183
  convertServiceNameToPrefix,
@@ -192,8 +187,8 @@ module.exports = {
192
187
  extractEnvVariablesFromText,
193
188
  flattenObject,
194
189
  getServiceTemplateFromSchemaUrl,
195
- safeMkdir,
190
+ createDirectory,
196
191
  stripVersion,
197
192
  PLT_ROOT,
198
- getLatestNpmVersion
193
+ getLatestNpmVersion,
199
194
  }