@platformatic/generators 1.53.3 → 2.0.0-alpha.10

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,11 @@
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,
11
10
  } = require('./utils')
12
11
  const { join } = require('node:path')
13
12
  const { FileGenerator } = require('./file-generator')
@@ -24,7 +23,7 @@ const fakeLogger = {
24
23
  warn: () => {},
25
24
  debug: () => {},
26
25
  trace: () => {},
27
- error: () => {}
26
+ error: () => {},
28
27
  }
29
28
  /* c8 ignore start */
30
29
 
@@ -60,7 +59,7 @@ class BaseGenerator extends FileGenerator {
60
59
  envPrefix: '',
61
60
  env: {},
62
61
  defaultEnv: {},
63
- isUpdating: false
62
+ isUpdating: false,
64
63
  }
65
64
  }
66
65
 
@@ -137,7 +136,7 @@ class BaseGenerator extends FileGenerator {
137
136
  this.config = {
138
137
  ...this.getDefaultConfig(),
139
138
  ...oldConfig,
140
- ...config
139
+ ...config,
141
140
  }
142
141
 
143
142
  if (this.config.isRuntimeContext) {
@@ -163,7 +162,7 @@ class BaseGenerator extends FileGenerator {
163
162
  const newConfig = await this.inquirer.prompt(this.questions)
164
163
  this.setConfig({
165
164
  ...this.config,
166
- ...newConfig
165
+ ...newConfig,
167
166
  })
168
167
  }
169
168
  }
@@ -190,7 +189,7 @@ class BaseGenerator extends FileGenerator {
190
189
  this.addFile({
191
190
  path: '',
192
191
  file: 'platformatic.json',
193
- contents: JSON.stringify(currentConfigFile, null, 2)
192
+ contents: JSON.stringify(currentConfigFile, null, 2),
194
193
  })
195
194
  } else {
196
195
  await this.getFastifyVersion()
@@ -203,7 +202,7 @@ class BaseGenerator extends FileGenerator {
203
202
  this.addFile({
204
203
  path: '',
205
204
  file: 'package.json',
206
- contents: JSON.stringify(template, null, 2)
205
+ contents: JSON.stringify(template, null, 2),
207
206
  })
208
207
 
209
208
  await this.generateConfigFile()
@@ -215,7 +214,7 @@ class BaseGenerator extends FileGenerator {
215
214
  this.addFile({
216
215
  path: '',
217
216
  file: 'tsconfig.json',
218
- contents: JSON.stringify(this.getTsConfig(), null, 2)
217
+ contents: JSON.stringify(this.getTsConfig(), null, 2),
219
218
  })
220
219
  }
221
220
 
@@ -236,7 +235,7 @@ class BaseGenerator extends FileGenerator {
236
235
  }
237
236
  return {
238
237
  targetDirectory: this.targetDirectory,
239
- env: this.config.env
238
+ env: this.config.env,
240
239
  }
241
240
  } catch (err) {
242
241
  if (err.code?.startsWith('PLT_GEN')) {
@@ -281,15 +280,15 @@ class BaseGenerator extends FileGenerator {
281
280
  incremental: true,
282
281
  strict: true,
283
282
  outDir: 'dist',
284
- skipLibCheck: true
283
+ skipLibCheck: true,
285
284
  },
286
285
  watchOptions: {
287
286
  watchFile: 'fixedPollingInterval',
288
287
  watchDirectory: 'fixedPollingInterval',
289
288
  fallbackPolling: 'dynamicPriority',
290
289
  synchronousWatchDirectory: true,
291
- excludeDirectories: ['**/node_modules', 'dist']
292
- }
290
+ excludeDirectories: ['**/node_modules', 'dist'],
291
+ },
293
292
  }
294
293
  }
295
294
 
@@ -300,7 +299,7 @@ class BaseGenerator extends FileGenerator {
300
299
  this.questions.push({
301
300
  type: 'input',
302
301
  name: 'targetDirectory',
303
- message: 'Where would you like to create your project?'
302
+ message: 'Where would you like to create your project?',
304
303
  })
305
304
  }
306
305
 
@@ -310,14 +309,14 @@ class BaseGenerator extends FileGenerator {
310
309
  name: 'typescript',
311
310
  message: 'Do you want to use TypeScript?',
312
311
  default: false,
313
- choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
312
+ choices: [{ name: 'yes', value: true }, { name: 'no', value: false }],
314
313
  })
315
314
 
316
315
  // port
317
316
  this.questions.push({
318
317
  type: 'input',
319
318
  name: 'port',
320
- message: 'What port do you want to use?'
319
+ message: 'What port do you want to use?',
321
320
  })
322
321
  }
323
322
  }
@@ -341,7 +340,7 @@ class BaseGenerator extends FileGenerator {
341
340
  }
342
341
  return {
343
342
  name: packageDefinition.name,
344
- options: packageConfigOutput.config
343
+ options: packageConfigOutput.config,
345
344
  }
346
345
  })
347
346
  }
@@ -349,7 +348,7 @@ class BaseGenerator extends FileGenerator {
349
348
  this.addFile({
350
349
  path: '',
351
350
  file: configFileName,
352
- contents: JSON.stringify(contents, null, 2)
351
+ contents: JSON.stringify(contents, null, 2),
353
352
  })
354
353
  }
355
354
 
@@ -368,12 +367,12 @@ class BaseGenerator extends FileGenerator {
368
367
 
369
368
  async getFastifyVersion () {
370
369
  const pkgData = await this.readPackageJsonFile()
371
- this.fastifyVersion = stripVersion(pkgData.dependencies.fastify)
370
+ this.fastifyVersion = pkgData.dependencies.fastify
372
371
  }
373
372
 
374
373
  async getPlatformaticVersion () {
375
374
  const pkgData = await this.readPackageJsonFile()
376
- this.platformaticVersion = stripVersion(pkgData.version)
375
+ this.platformaticVersion = pkgData.version
377
376
  }
378
377
 
379
378
  async generatePackageJson () {
@@ -381,19 +380,19 @@ class BaseGenerator extends FileGenerator {
381
380
  name: `${this.config.serviceName}`,
382
381
  scripts: {
383
382
  start: 'platformatic start',
384
- test: 'borp'
383
+ test: 'borp',
385
384
  },
386
385
  devDependencies: {
387
386
  fastify: `^${this.fastifyVersion}`,
388
387
  borp: `${this.pkgData.devDependencies.borp}`,
389
- ...this.config.devDependencies
388
+ ...this.config.devDependencies,
390
389
  },
391
390
  dependencies: {
392
- ...this.config.dependencies
391
+ ...this.config.dependencies,
393
392
  },
394
393
  engines: {
395
- node: '^18.8.0 || >=20.6.0'
396
- }
394
+ node: '^18.8.0 || >=20.6.0',
395
+ },
397
396
  }
398
397
 
399
398
  if (this.config.typescript) {
@@ -410,7 +409,7 @@ class BaseGenerator extends FileGenerator {
410
409
  this.addFile({
411
410
  path: '',
412
411
  file: '.env',
413
- contents: serializeEnvVars(this.config.env)
412
+ contents: serializeEnvVars(this.config.env),
414
413
  })
415
414
 
416
415
  const emptyEnvVars = {}
@@ -425,8 +424,8 @@ class BaseGenerator extends FileGenerator {
425
424
  file: '.env.sample',
426
425
  contents: serializeEnvVars({
427
426
  ...this.config.defaultEnv,
428
- ...emptyEnvVars
429
- })
427
+ ...emptyEnvVars,
428
+ }),
430
429
  })
431
430
  }
432
431
  }
@@ -462,7 +461,7 @@ class BaseGenerator extends FileGenerator {
462
461
  const flattened = flattenObject(pkg)
463
462
  const output = {
464
463
  name: flattened.name,
465
- options: []
464
+ options: [],
466
465
  }
467
466
  if (pkg.options) {
468
467
  Object.entries(flattened)
@@ -474,7 +473,7 @@ class BaseGenerator extends FileGenerator {
474
473
  name: serviceEnvVarKey,
475
474
  path: key.replace('options.', ''),
476
475
  type: 'string',
477
- value: runtimeEnv[runtimeEnvVarKey]
476
+ value: runtimeEnv[runtimeEnvVarKey],
478
477
  }
479
478
  output.options.push(option)
480
479
  })
@@ -488,7 +487,7 @@ class BaseGenerator extends FileGenerator {
488
487
  name: serviceName,
489
488
  template: getServiceTemplateFromSchemaUrl(servicePkgJsonFileData.$schema),
490
489
  fields: [],
491
- plugins
490
+ plugins,
492
491
  }
493
492
  }
494
493
 
@@ -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,33 +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
- }
18
-
19
- /**
20
- * Strip all extra characters from a simple semver version string
21
- * @param {string} version
22
- * @returns string
23
- */
24
- function stripVersion (version) {
25
- const match = version.match(/(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)/)
26
- if (match) {
27
- return match[0]
28
- }
29
- return version
30
- }
9
+ const { createDirectory } = require('@platformatic/utils')
31
10
 
32
11
  function convertServiceNameToPrefix (serviceName) {
33
12
  return serviceName.replace(/-/g, '_').toUpperCase()
@@ -49,7 +28,7 @@ function addPrefixToString (input, prefix) {
49
28
 
50
29
  function envObjectToString (env) {
51
30
  const output = []
52
- Object.entries(env).forEach((kv) => {
31
+ Object.entries(env).forEach(kv => {
53
32
  output.push(`${kv[0]}=${kv[1]}`)
54
33
  })
55
34
  return output.join(EOL)
@@ -57,12 +36,12 @@ function envObjectToString (env) {
57
36
 
58
37
  function envStringToObject (envString) {
59
38
  const output = {}
60
- const split = envString.split(EOL)
39
+ const split = envString.split(/\r?\n/)
61
40
  split
62
- .filter((line) => {
41
+ .filter(line => {
63
42
  return line.trim() !== '' && line.indexOf('#') !== 0
64
43
  })
65
- .forEach((line) => {
44
+ .forEach(line => {
66
45
  const kv = line.split('=')
67
46
  output[kv[0]] = kv[1]
68
47
  })
@@ -71,16 +50,14 @@ function envStringToObject (envString) {
71
50
  function extractEnvVariablesFromText (text) {
72
51
  const match = text.match(/\{[a-zA-Z0-9-_]*\}/g)
73
52
  if (match) {
74
- return match
75
- .map((found) => found.replace('{', '').replace('}', ''))
76
- .filter((found) => found !== '')
53
+ return match.map(found => found.replace('{', '').replace('}', '')).filter(found => found !== '')
77
54
  }
78
55
  return []
79
56
  }
80
57
  function getPackageConfigurationObject (config, serviceName = '') {
81
58
  const output = {
82
59
  config: {},
83
- env: {}
60
+ env: {},
84
61
  }
85
62
  let current = output.config
86
63
  for (const param of config) {
@@ -90,14 +67,14 @@ function getPackageConfigurationObject (config, serviceName = '') {
90
67
  let value
91
68
  let isPath = false
92
69
  switch (param.type) {
93
- case 'string' :
70
+ case 'string':
94
71
  value = param.value.toString()
95
72
  break
96
73
  case 'number':
97
74
  value = parseInt(param.value)
98
75
  break
99
76
  case 'boolean':
100
- value = (param.value === 'true')
77
+ value = param.value === 'true'
101
78
  break
102
79
  case 'path':
103
80
  value = `${join(`{${PLT_ROOT}}`, param.value)}`
@@ -167,7 +144,7 @@ async function getLatestNpmVersion (pkg) {
167
144
  function flattenObject (ob) {
168
145
  const result = {}
169
146
  for (const i in ob) {
170
- if ((typeof ob[i]) === 'object' && !Array.isArray(ob[i])) {
147
+ if (typeof ob[i] === 'object' && !Array.isArray(ob[i])) {
171
148
  const temp = flattenObject(ob[i])
172
149
  for (const j in temp) {
173
150
  result[i + '.' + j] = temp[j]
@@ -181,8 +158,13 @@ function flattenObject (ob) {
181
158
 
182
159
  function getServiceTemplateFromSchemaUrl (schemaUrl) {
183
160
  const splitted = schemaUrl.split('/')
184
- return `@platformatic/${splitted[splitted.length - 1]}`
161
+
162
+ if (schemaUrl.startsWith('https://platformatic.dev/schemas')) {
163
+ return `@platformatic/${splitted[splitted.length - 1]}`
164
+ }
165
+ return `@platformatic/${splitted[splitted.length - 2]}`
185
166
  }
167
+
186
168
  module.exports = {
187
169
  addPrefixToString,
188
170
  convertServiceNameToPrefix,
@@ -192,8 +174,7 @@ module.exports = {
192
174
  extractEnvVariablesFromText,
193
175
  flattenObject,
194
176
  getServiceTemplateFromSchemaUrl,
195
- safeMkdir,
196
- stripVersion,
177
+ createDirectory,
197
178
  PLT_ROOT,
198
- getLatestNpmVersion
179
+ getLatestNpmVersion,
199
180
  }