@platformatic/generators 3.0.0 → 3.0.2

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,2 +1,160 @@
1
- export * from './lib/base-generator'
2
- export * from './lib/file-generator'
1
+ import { BaseLogger } from 'pino'
2
+
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>
160
+ }
package/index.test-d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { expectAssignable } from 'tsd'
2
- import { BaseGenerator } from './lib/base-generator'
2
+ import { ConfigField, ConfigFieldDefinition } from './index.js'
3
3
 
4
- expectAssignable<BaseGenerator.ConfigFieldDefinition>({
4
+ expectAssignable<ConfigFieldDefinition>({
5
5
  label: 'PLT_TESTING',
6
6
  var: 'testing',
7
7
  default: 'hello world',
@@ -9,7 +9,7 @@ expectAssignable<BaseGenerator.ConfigFieldDefinition>({
9
9
  configValue: 'someConfigValue'
10
10
  })
11
11
 
12
- expectAssignable<BaseGenerator.ConfigField>({
12
+ expectAssignable<ConfigField>({
13
13
  var: 'testing',
14
14
  configValue: 'someConfigValue',
15
15
  value: 'asd123'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/generators",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Main classes and utils for generators.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  "fastify": "^5.0.0",
24
24
  "pino": "^9.9.0",
25
25
  "undici": "^7.0.0",
26
- "@platformatic/foundation": "3.0.0"
26
+ "@platformatic/foundation": "3.0.2"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/inquirer": "^9.0.7",
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "esnext",
4
+ "esModuleInterop": true,
5
+ "lib": ["es2022"],
6
+ "target": "esnext",
7
+ "sourceMap": true,
8
+ "pretty": true,
9
+ "noEmitOnError": true,
10
+ "incremental": true,
11
+ "strict": true,
12
+ "outDir": "dist",
13
+ "skipLibCheck": true
14
+ },
15
+ "watchOptions": {
16
+ "watchFile": "fixedPollingInterval",
17
+ "watchDirectory": "fixedPollingInterval",
18
+ "fallbackPolling": "dynamicPriority",
19
+ "synchronousWatchDirectory": true,
20
+ "excludeDirectories": ["**/node_modules", "dist"]
21
+ }
22
+ }
@@ -1,122 +0,0 @@
1
- import { BaseLogger } from 'pino'
2
- import { FileGenerator } from './file-generator'
3
- import { PackageConfiguration } from './utils'
4
- export namespace BaseGenerator {
5
- export type BaseGeneratorOptions = FileGenerator.FileGeneratorOptions & {
6
- module: string
7
- inquirer?: object
8
- }
9
-
10
- export type EnvVarValue = string | number | boolean
11
- export type Env = {
12
- [key: string]: EnvVarValue
13
- }
14
- type KeyValue = {
15
- [key: string]: string | number | undefined | null | boolean | object
16
- }
17
- type JSONValue =
18
- | string
19
- | number
20
- | boolean
21
- | { [x: string]: JSONValue }
22
- | object
23
- | Array<JSONValue>
24
-
25
- type Dependency = {
26
- [key: string]: string
27
- }
28
-
29
- type PackageDefinition = {
30
- name: string,
31
- options: PackageConfiguration
32
- }
33
- type BaseGeneratorConfig = Record<string, any> & {
34
- port?: number
35
- hostname?: string
36
- plugin?: boolean
37
- dependencies?: Dependency
38
- devDependencies?: Dependency
39
- typescript?: boolean
40
- initGitRepository?: boolean
41
- env?: KeyValue,
42
- isRuntimeContext?: boolean,
43
- applicationName?: string,
44
- envPrefix?: string
45
- }
46
-
47
- type WhereClause = {
48
- before?: string
49
- after?: string
50
- }
51
-
52
- type GeneratorMetadata = {
53
- targetDirectory: string
54
- env: KeyValue
55
- }
56
-
57
- type ConfigFieldDefinition = {
58
- label: string
59
- var: string
60
- default: string
61
- type: 'number' | 'string' | 'boolean' | 'path'
62
- configValue?: string
63
- }
64
-
65
- type ConfigField = {
66
- var: string
67
- configValue?: string
68
- value: string
69
- }
70
-
71
- type AddEnvVarOptions = {
72
- overwrite: boolean
73
- }
74
-
75
- export class BaseGenerator extends FileGenerator.FileGenerator {
76
- logger: BaseLogger
77
- platformaticVersion: string
78
- fastifyVersion: string
79
-
80
- config: BaseGeneratorConfig
81
- questions: Array<object>
82
-
83
- packages: PackageConfiguration[]
84
- constructor (opts?: BaseGeneratorOptions)
85
-
86
- setConfig (config?: BaseGeneratorConfig): void
87
-
88
- getEnvVarName (envVarName: string): string
89
- addEnvVars (envVars: Env, opts: AddEnvVarOptions): void
90
- addEnvVar (envVarName: string, envVarValue: EnvVarValue, opts: AddEnvVarOptions): void
91
- getEnvVar (envVarName: string): EnvVarValue
92
- setEnvVars (env?: Env): void
93
-
94
- getDefaultConfig (): { [x: string]: JSONValue }
95
-
96
- getFastifyVersion (): Promise<string>
97
- getPlatformaticVersion (): Promise<string>
98
-
99
- addPackage (pkg: PackageDefinition): Promise<void>
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 }
107
-
108
- getConfigFieldsDefinitions (): ConfigFieldDefinition[]
109
- setConfigFields (fields: ConfigField[]): void
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 }>
119
-
120
- postInstallActions (): Promise<void>
121
- }
122
- }
@@ -1,30 +0,0 @@
1
- import { BaseLogger } from 'pino'
2
-
3
- export namespace FileGenerator {
4
- export type FileGeneratorOptions = {
5
- logger?: BaseLogger
6
- }
7
-
8
- export type FileObject = {
9
- path: string,
10
- file: string,
11
- contents: string
12
- }
13
-
14
- export class FileGenerator {
15
- files: FileObject[]
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
28
- }
29
-
30
- }
package/lib/utils.d.ts DELETED
@@ -1,22 +0,0 @@
1
- type Env = {
2
- [key: string]: string
3
- }
4
-
5
- export type PackageConfiguration = {
6
- type: 'number' | 'string' | 'boolean' | 'path'
7
- path: string
8
- value: number | string | boolean
9
- }
10
-
11
- export namespace GeneratorUtils {
12
- export function stripVersion (version: string): string
13
- export function convertApplicationNameToPrefix (applicationName: string): string
14
- export function addPrefixToServiceName (applicationName: string, prefix: 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 getApplicationTemplateFromSchemaUrl (schemaUrl: string): string
21
- export const PLT_ROOT: string
22
- }