@platformatic/generators 3.4.1 → 3.5.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/README.md CHANGED
@@ -7,7 +7,7 @@ Generates a Platformatic app programmatically.
7
7
  The base class `BaseGenerator` is basically a file writer with some default behaviours.
8
8
 
9
9
  It should be instantiated with an `options` object having this properties
10
- - `type`: `"db" | "service" | "composer"`
10
+ - `type`: `"db" | "service" | "gateway"`
11
11
  - `logger`: A pino-like logger object. If not provided a fake logger with no output will be used
12
12
  - `questions`: An array of custom questions object to provide to `inquirer`. Default to `[]`
13
13
 
package/eslint.config.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict'
1
+ import neostandard from 'neostandard'
2
2
 
3
- module.exports = require('neostandard')({ ts: true })
3
+ export default neostandard({ ts: true })
package/index.d.ts CHANGED
@@ -1,8 +1,160 @@
1
- import { BaseGenerator } from './lib/base-generator'
2
- import { generateTests, generatePlugins } from './lib/create-plugin'
1
+ import { BaseLogger } from 'pino'
3
2
 
4
- export {
5
- BaseGenerator,
6
- generateTests,
7
- generatePlugins,
3
+ export type EnvVarValue = string | number | boolean
4
+
5
+ export type Env = {
6
+ [key: string]: EnvVarValue
7
+ }
8
+
9
+ export type KeyValue = {
10
+ [key: string]: string | number | undefined | null | boolean | object
11
+ }
12
+
13
+ export type JSONValue = string | number | boolean | { [x: string]: JSONValue } | object | Array<JSONValue>
14
+
15
+ export type Dependency = {
16
+ [key: string]: string
17
+ }
18
+
19
+ export type WhereClause = {
20
+ before?: string
21
+ after?: string
22
+ }
23
+
24
+ export type GeneratorMetadata = {
25
+ targetDirectory: string
26
+ env: KeyValue
27
+ }
28
+
29
+ export type ConfigFieldDefinition = {
30
+ label: string
31
+ var: string
32
+ default: string
33
+ type: 'number' | 'string' | 'boolean' | 'path'
34
+ configValue?: string
35
+ }
36
+
37
+ export type ConfigField = {
38
+ var: string
39
+ configValue?: string
40
+ value: string
41
+ }
42
+
43
+ export type AddEnvVarOptions = {
44
+ overwrite: boolean
45
+ }
46
+
47
+ export type PackageConfiguration = {
48
+ type: 'number' | 'string' | 'boolean' | 'path'
49
+ path: string
50
+ value: number | string | boolean
51
+ }
52
+
53
+ export type PackageDefinition = {
54
+ name: string
55
+ options: PackageConfiguration
56
+ }
57
+
58
+ export declare function stripVersion (version: string): string
59
+ export declare function convertApplicationNameToPrefix (applicationName: string): string
60
+ export declare function addPrefixToServiceName (applicationName: string, prefix: string): string
61
+ export declare function envObjectToString (env: Env): string
62
+ export declare function envStringToObject (env: string): Env
63
+ export declare function extractEnvVariablesFromText (text: string): string[]
64
+ export declare function getPackageConfigurationObject (config: PackageConfiguration[]): object
65
+ export declare function flattenObject (obj: object): object
66
+ export declare function getApplicationTemplateFromSchemaUrl (schemaUrl: string): string
67
+ export declare const PLT_ROOT: string
68
+
69
+ export type FileGeneratorOptions = {
70
+ logger?: BaseLogger
71
+ }
72
+
73
+ export type FileObject = {
74
+ path: string
75
+ file: string
76
+ contents: string
77
+ }
78
+
79
+ export class FileGenerator {
80
+ files: FileObject[]
81
+ targetDirectory: string
82
+
83
+ constructor (opts?: FileGeneratorOptions)
84
+
85
+ setTargetDirectory (dir: string): void
86
+ addFile (file: FileObject): void
87
+ appendfile (file: FileObject): void
88
+ reset (): void
89
+ writeFiles (): Promise<void>
90
+ listFiles (): FileObject
91
+ loadFile (): Promise<FileObject>
92
+ getFileObject (file: string, path?: string): FileObject
93
+ }
94
+
95
+ export type BaseGeneratorOptions = FileGeneratorOptions & {
96
+ module: string
97
+ inquirer?: object
98
+ }
99
+
100
+ export type BaseGeneratorConfig = Record<string, any> & {
101
+ port?: number
102
+ hostname?: string
103
+ plugin?: boolean
104
+ dependencies?: Dependency
105
+ devDependencies?: Dependency
106
+ typescript?: boolean
107
+ initGitRepository?: boolean
108
+ env?: KeyValue
109
+ isRuntimeContext?: boolean
110
+ applicationName?: string
111
+ envPrefix?: string
112
+ }
113
+
114
+ export class BaseGenerator extends FileGenerator {
115
+ logger: BaseLogger
116
+ platformaticVersion: string
117
+ fastifyVersion: string
118
+
119
+ config: BaseGeneratorConfig
120
+ questions: Array<object>
121
+
122
+ packages: PackageConfiguration[]
123
+ constructor (opts?: BaseGeneratorOptions)
124
+
125
+ setConfig (config?: BaseGeneratorConfig): void
126
+
127
+ getEnvVarName (envVarName: string): string
128
+ addEnvVars (envVars: Env, opts: AddEnvVarOptions): void
129
+ addEnvVar (envVarName: string, envVarValue: EnvVarValue, opts: AddEnvVarOptions): void
130
+ getEnvVar (envVarName: string): EnvVarValue
131
+ setEnvVars (env?: Env): void
132
+
133
+ getDefaultConfig (): { [x: string]: JSONValue }
134
+
135
+ getFastifyVersion (): Promise<string>
136
+ getPlatformaticVersion (): Promise<string>
137
+
138
+ addPackage (pkg: PackageDefinition): Promise<void>
139
+
140
+ loadFromDir (dir: string): Promise<void>
141
+ prepare (): Promise<GeneratorMetadata>
142
+ run (): Promise<GeneratorMetadata>
143
+ addQuestion (question: any, where?: WhereClause): Promise<void>
144
+ removeQuestion (variableName: string): void
145
+ getTSConfig (): { [x: string]: JSONValue }
146
+
147
+ getConfigFieldsDefinitions (): ConfigFieldDefinition[]
148
+ setConfigFields (fields: ConfigField[]): void
149
+
150
+ generateConfigFile (): Promise<void>
151
+ readPackageJsonFile (): Promise<JSONValue>
152
+ generatePackageJson (): Promise<{ [x: string]: JSONValue }>
153
+ getConfigFileName (): string
154
+ checkEnvVariablesInConfigFile (): boolean
155
+ _beforePrepare (): Promise<void>
156
+ _afterPrepare (): Promise<void | JSONValue>
157
+ _getConfigFileContents (): Promise<{ [x: string]: JSONValue }>
158
+
159
+ postInstallActions (): Promise<void>
8
160
  }
package/index.js CHANGED
@@ -1,10 +1,3 @@
1
- 'use strict'
2
-
3
- const { BaseGenerator } = require('./lib/base-generator')
4
- const { generateTests } = require('./lib/create-plugin')
5
- const utils = require('./lib/utils')
6
- module.exports = {
7
- BaseGenerator,
8
- generateTests,
9
- ...utils,
10
- }
1
+ export { BaseGenerator } from './lib/base-generator.js'
2
+ export { ImportGenerator } from './lib/import-generator.js'
3
+ export * from './lib/utils.js'
package/index.test-d.ts CHANGED
@@ -1,22 +1,16 @@
1
1
  import { expectAssignable } from 'tsd'
2
- import { BaseGenerator } from './lib/base-generator'
3
- import { generatePlugins, generateTests } from './index'
4
- import { FileGenerator } from './lib/file-generator'
2
+ import { ConfigField, ConfigFieldDefinition } from './index.js'
5
3
 
6
- expectAssignable<BaseGenerator.ConfigFieldDefinition>({
4
+ expectAssignable<ConfigFieldDefinition>({
7
5
  label: 'PLT_TESTING',
8
6
  var: 'testing',
9
7
  default: 'hello world',
10
8
  type: 'string',
11
- configValue: 'someConfigValue',
9
+ configValue: 'someConfigValue'
12
10
  })
13
11
 
14
- expectAssignable<BaseGenerator.ConfigField>({
12
+ expectAssignable<ConfigField>({
15
13
  var: 'testing',
16
14
  configValue: 'someConfigValue',
17
- value: 'asd123',
15
+ value: 'asd123'
18
16
  })
19
-
20
- expectAssignable<FileGenerator.FileObject[]>(generatePlugins(true))
21
-
22
- expectAssignable<FileGenerator.FileObject[]>(generateTests(true, '@platformatic/service'))