@platformatic/service 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.
- package/config.d.ts +4 -17
- package/eslint.config.js +14 -0
- package/help/help.txt +0 -2
- package/index.d.ts +20 -21
- package/index.js +56 -22
- package/index.test-d.ts +34 -31
- package/lib/compile.js +24 -102
- package/lib/create.mjs +7 -7
- package/lib/gen-schema.js +1 -1
- package/lib/gen-types.mjs +2 -2
- package/lib/generator/service-generator.js +16 -16
- package/lib/openapi-schema-defs.js +363 -363
- package/lib/plugins/graphql.js +2 -2
- package/lib/plugins/health-check.js +1 -1
- package/lib/plugins/metrics.js +18 -30
- package/lib/plugins/openapi.js +10 -21
- package/lib/plugins/plugins.js +13 -6
- package/lib/plugins/sandbox-wrapper.js +2 -2
- package/lib/plugins/typescript.js +10 -6
- package/lib/root-endpoint/index.js +2 -19
- package/lib/root-endpoint/public/index.html +4 -21
- package/lib/schema.js +199 -576
- package/lib/stackable.js +259 -0
- package/lib/start.js +51 -68
- package/lib/upgrade.js +2 -2
- package/lib/utils.js +12 -133
- package/lib/versions/0.16.0.js +7 -7
- package/lib/versions/from-zero-twenty-eight-to-will-see.js +3 -3
- package/lib/versions/no-allow-cycles.js +15 -0
- package/package.json +50 -66
- package/schema.json +8 -195
- package/service.mjs +9 -13
- package/help/versions bump.txt +0 -25
- package/help/versions update.txt +0 -23
- package/lib/bump-version.js +0 -178
- package/lib/errors.js +0 -16
- package/lib/get-openapi-schema.js +0 -47
- package/lib/plugins/versions.js +0 -217
- package/lib/update-version.js +0 -863
package/config.d.ts
CHANGED
|
@@ -61,6 +61,9 @@ export interface PlatformaticService {
|
|
|
61
61
|
};
|
|
62
62
|
[k: string]: unknown;
|
|
63
63
|
};
|
|
64
|
+
loggerInstance?: {
|
|
65
|
+
[k: string]: unknown;
|
|
66
|
+
};
|
|
64
67
|
serializerOpts?: {
|
|
65
68
|
schema?: {
|
|
66
69
|
[k: string]: unknown;
|
|
@@ -151,7 +154,6 @@ export interface PlatformaticService {
|
|
|
151
154
|
defaultMetrics?: {
|
|
152
155
|
enabled: boolean;
|
|
153
156
|
};
|
|
154
|
-
prefix?: string;
|
|
155
157
|
auth?: {
|
|
156
158
|
username: string;
|
|
157
159
|
password: string;
|
|
@@ -173,6 +175,7 @@ export interface PlatformaticService {
|
|
|
173
175
|
| boolean
|
|
174
176
|
| string;
|
|
175
177
|
$schema?: string;
|
|
178
|
+
module?: string;
|
|
176
179
|
service?: {
|
|
177
180
|
openapi?:
|
|
178
181
|
| {
|
|
@@ -214,22 +217,6 @@ export interface PlatformaticService {
|
|
|
214
217
|
fullRequest?: boolean;
|
|
215
218
|
validateResponse?: boolean;
|
|
216
219
|
}[];
|
|
217
|
-
versions?: {
|
|
218
|
-
/**
|
|
219
|
-
* The path to the directory containing the versions mappers
|
|
220
|
-
*/
|
|
221
|
-
dir: string;
|
|
222
|
-
configs: {
|
|
223
|
-
version: string;
|
|
224
|
-
openapi?: {
|
|
225
|
-
prefix?: string;
|
|
226
|
-
path?: string;
|
|
227
|
-
};
|
|
228
|
-
plugins?: {
|
|
229
|
-
[k: string]: unknown;
|
|
230
|
-
};
|
|
231
|
-
}[];
|
|
232
|
-
};
|
|
233
220
|
}
|
|
234
221
|
export interface OpenTelemetry {
|
|
235
222
|
/**
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const neostandard = require('neostandard')
|
|
4
|
+
|
|
5
|
+
module.exports = neostandard({
|
|
6
|
+
ts: true,
|
|
7
|
+
ignores: [
|
|
8
|
+
...neostandard.resolveIgnoresFromGitignore(),
|
|
9
|
+
'test/tmp/**/*',
|
|
10
|
+
'test/fixtures/*/dist/**/*',
|
|
11
|
+
'**/dist/*',
|
|
12
|
+
'fixtures/**/*',
|
|
13
|
+
],
|
|
14
|
+
})
|
package/help/help.txt
CHANGED
|
@@ -6,5 +6,3 @@ Available commands:
|
|
|
6
6
|
* `start` - start the server.
|
|
7
7
|
* `schema config` - generate the schema configuration file.
|
|
8
8
|
* `compile` - compile the typescript files.
|
|
9
|
-
* `versions bump` - bump a new version of the API.
|
|
10
|
-
* `versions update` - update the latest version of the API.
|
package/index.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/triple-slash-reference */
|
|
2
1
|
/// <reference types="mercurius" />
|
|
3
2
|
/// <reference types="@fastify/swagger" />
|
|
4
3
|
import { FastifyInstance, FastifyBaseLogger } from 'fastify'
|
|
5
4
|
import ConfigManager from '@platformatic/config'
|
|
6
|
-
import type {
|
|
5
|
+
import type { ConfigManagerConfig } from '@platformatic/config'
|
|
6
|
+
import type { Stackable as _Stackable, StackableInterface } from '@platformatic/config'
|
|
7
7
|
import { BaseGenerator } from '@platformatic/generators'
|
|
8
8
|
import { PlatformaticService } from './config'
|
|
9
9
|
import type { JSONSchemaType } from 'ajv'
|
|
10
10
|
import { ServiceGenerator } from './lib/generator/service-generator'
|
|
11
11
|
|
|
12
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
13
12
|
export import Generator = ServiceGenerator.ServiceGenerator
|
|
14
13
|
|
|
15
14
|
export interface PlatformaticApp<T> {
|
|
@@ -28,28 +27,16 @@ declare module 'fastify' {
|
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
transformConfig: (this: ConfigManager<T>) => Promise<void>
|
|
33
|
-
schema: object
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface Stackable<ConfigType> {
|
|
37
|
-
(app: FastifyInstance, opts: object): Promise<void>
|
|
38
|
-
|
|
39
|
-
configType: string
|
|
40
|
-
configManagerConfig: ConfigManagerConfig<ConfigType>
|
|
41
|
-
schema: object
|
|
42
|
-
Generator?: new () => BaseGenerator.BaseGenerator
|
|
30
|
+
type DefaultGenerator = new () => BaseGenerator.BaseGenerator
|
|
43
31
|
|
|
32
|
+
export interface Stackable<ConfigType, Generator = DefaultGenerator> extends _Stackable<ConfigType> {
|
|
33
|
+
app: (app: FastifyInstance, opts: object) => Promise<void>
|
|
34
|
+
Generator?: Generator
|
|
44
35
|
version?: string
|
|
45
36
|
upgrade?: (config: any, version: string) => Promise<any>
|
|
46
37
|
transformConfig?: (config: any) => Promise<any>
|
|
47
38
|
}
|
|
48
39
|
|
|
49
|
-
interface SchemaExport {
|
|
50
|
-
schema: JSONSchemaType<PlatformaticServiceConfig>
|
|
51
|
-
}
|
|
52
|
-
|
|
53
40
|
interface TSCompilerOptions {
|
|
54
41
|
clean: boolean
|
|
55
42
|
}
|
|
@@ -57,10 +44,22 @@ interface TSCompiler {
|
|
|
57
44
|
compile: (cwd: string, config: object, originalLogger: FastifyBaseLogger, options: TSCompilerOptions) => Promise<boolean>
|
|
58
45
|
}
|
|
59
46
|
|
|
60
|
-
export const schema:
|
|
47
|
+
export const schema: JSONSchemaType<PlatformaticServiceConfig>
|
|
48
|
+
export const configManagerConfig: ConfigManagerConfig<PlatformaticServiceConfig>
|
|
61
49
|
|
|
62
50
|
export declare const platformaticService: Stackable<PlatformaticServiceConfig>
|
|
63
51
|
|
|
64
|
-
export
|
|
52
|
+
export declare const app: (app: FastifyInstance, opts: object) => Promise<void>
|
|
65
53
|
|
|
66
54
|
export const tsCompiler: TSCompiler
|
|
55
|
+
|
|
56
|
+
type defaultExport = Stackable<PlatformaticServiceConfig> & {
|
|
57
|
+
buildServer: (opts: object, app?: object, ConfigManagerConstructor?: object) => Promise<FastifyInstance>,
|
|
58
|
+
start: <ConfigType>(app: Stackable<ConfigType>, args: string[]) => Promise<void>,
|
|
59
|
+
tsCompiler: TSCompiler,
|
|
60
|
+
schema: JSONSchemaType<PlatformaticServiceConfig>,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function buildStackable (opts: { config: string }, app?: object): Promise<StackableInterface>
|
|
64
|
+
|
|
65
|
+
export default defaultExport
|
package/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { isKeyEnabled } = require('@platformatic/utils')
|
|
4
|
+
const { loadConfig, ConfigManager } = require('@platformatic/config')
|
|
4
5
|
const { readFile } = require('fs/promises')
|
|
5
6
|
const { join } = require('path')
|
|
6
7
|
|
|
7
|
-
const compiler = require('./lib/compile')
|
|
8
8
|
const setupCors = require('./lib/plugins/cors')
|
|
9
9
|
const setupOpenAPI = require('./lib/plugins/openapi.js')
|
|
10
10
|
const setupGraphQL = require('./lib/plugins/graphql.js')
|
|
@@ -13,14 +13,15 @@ const setupMetrics = require('./lib/plugins/metrics')
|
|
|
13
13
|
const setupTsCompiler = require('./lib/plugins/typescript')
|
|
14
14
|
const setupHealthCheck = require('./lib/plugins/health-check')
|
|
15
15
|
const loadPlugins = require('./lib/plugins/plugins')
|
|
16
|
-
const loadVersions = require('./lib/plugins/versions')
|
|
17
16
|
const upgrade = require('./lib/upgrade')
|
|
18
17
|
const { telemetry } = require('@platformatic/telemetry')
|
|
19
18
|
|
|
19
|
+
const { buildCompileCmd, extractTypeScriptCompileOptionsFromConfig } = require('./lib/compile')
|
|
20
20
|
const { schema } = require('./lib/schema')
|
|
21
21
|
const { addLoggerToTheConfig } = require('./lib/utils')
|
|
22
22
|
const { start, buildServer } = require('./lib/start')
|
|
23
23
|
const ServiceGenerator = require('./lib/generator/service-generator.js')
|
|
24
|
+
const { ServiceStackable } = require('./lib/stackable')
|
|
24
25
|
|
|
25
26
|
const { version } = require('./package.json')
|
|
26
27
|
|
|
@@ -40,7 +41,7 @@ async function platformaticService (app, opts) {
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
// This must be done before loading the plugins, so they can inspect if the
|
|
43
|
-
// openTelemetry
|
|
44
|
+
// openTelemetry decorator exists and then configure accordingly.
|
|
44
45
|
if (isKeyEnabled('telemetry', config)) {
|
|
45
46
|
await app.register(telemetry, config.telemetry)
|
|
46
47
|
}
|
|
@@ -61,8 +62,7 @@ async function platformaticService (app, opts) {
|
|
|
61
62
|
|
|
62
63
|
if (isKeyEnabled('openapi', serviceConfig)) {
|
|
63
64
|
const openapi = serviceConfig.openapi
|
|
64
|
-
|
|
65
|
-
app.register(setupOpenAPI, { openapi, versions })
|
|
65
|
+
app.register(setupOpenAPI, { openapi })
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
if (isKeyEnabled('graphql', serviceConfig)) {
|
|
@@ -80,18 +80,11 @@ async function platformaticService (app, opts) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
if (registerTsCompiler) {
|
|
83
|
-
app.register(setupTsCompiler)
|
|
83
|
+
app.register(setupTsCompiler, { context: opts.context })
|
|
84
84
|
}
|
|
85
|
-
app.register(loadPlugins)
|
|
85
|
+
app.register(loadPlugins, { context: opts.context })
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
await app.register(async (app) => {
|
|
89
|
-
if (config.versions) {
|
|
90
|
-
// TODO: Add typescript mappers support
|
|
91
|
-
await app.register(loadVersions)
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
|
|
95
88
|
if (isKeyEnabled('cors', config.server)) {
|
|
96
89
|
app.register(setupCors, config.server.cors)
|
|
97
90
|
}
|
|
@@ -102,9 +95,8 @@ async function platformaticService (app, opts) {
|
|
|
102
95
|
}
|
|
103
96
|
|
|
104
97
|
platformaticService[Symbol.for('skip-override')] = true
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
platformaticService.configManagerConfig = {
|
|
98
|
+
|
|
99
|
+
module.exports.configManagerConfig = {
|
|
108
100
|
version,
|
|
109
101
|
schema,
|
|
110
102
|
allowToWatch: ['.env'],
|
|
@@ -112,7 +104,7 @@ platformaticService.configManagerConfig = {
|
|
|
112
104
|
useDefaults: true,
|
|
113
105
|
coerceTypes: true,
|
|
114
106
|
allErrors: true,
|
|
115
|
-
strict: false
|
|
107
|
+
strict: false,
|
|
116
108
|
},
|
|
117
109
|
async transformConfig () {
|
|
118
110
|
// Set watch to true by default. This is not possible
|
|
@@ -142,17 +134,59 @@ platformaticService.configManagerConfig = {
|
|
|
142
134
|
this.current.watch.ignore.push(outDir + '/**/*')
|
|
143
135
|
}
|
|
144
136
|
},
|
|
145
|
-
upgrade
|
|
137
|
+
upgrade,
|
|
146
138
|
}
|
|
147
139
|
|
|
140
|
+
platformaticService.configType = 'service'
|
|
141
|
+
platformaticService.schema = schema
|
|
142
|
+
platformaticService.configManagerConfig = module.exports.configManagerConfig
|
|
143
|
+
|
|
148
144
|
function _buildServer (options, app) {
|
|
149
|
-
return buildServer(options, app ||
|
|
145
|
+
return buildServer(options, app || module.exports)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function buildStackable (
|
|
149
|
+
options,
|
|
150
|
+
app = platformaticService,
|
|
151
|
+
Stackable = ServiceStackable
|
|
152
|
+
) {
|
|
153
|
+
let configManager = options.configManager
|
|
154
|
+
|
|
155
|
+
if (configManager === undefined) {
|
|
156
|
+
if (typeof options.config === 'string') {
|
|
157
|
+
({ configManager } = await loadConfig({}, ['-c', options.config], app, {
|
|
158
|
+
onMissingEnv: options.onMissingEnv,
|
|
159
|
+
context: options.context,
|
|
160
|
+
}, true))
|
|
161
|
+
} else {
|
|
162
|
+
configManager = new ConfigManager({
|
|
163
|
+
...app.configManagerConfig,
|
|
164
|
+
source: options.config,
|
|
165
|
+
})
|
|
166
|
+
await configManager.parseAndValidate()
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const stackable = new Stackable({
|
|
171
|
+
init: () => buildServer(configManager.current, app, options.context),
|
|
172
|
+
stackable: app,
|
|
173
|
+
configManager,
|
|
174
|
+
context: options.context,
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
return stackable
|
|
150
178
|
}
|
|
151
179
|
|
|
180
|
+
module.exports.configType = 'service'
|
|
181
|
+
module.exports.app = platformaticService
|
|
182
|
+
module.exports.schema = schema
|
|
152
183
|
module.exports.buildServer = _buildServer
|
|
153
|
-
module.exports.
|
|
184
|
+
module.exports.buildStackable = buildStackable
|
|
185
|
+
module.exports.schemas = require('./lib/schema')
|
|
154
186
|
module.exports.platformaticService = platformaticService
|
|
155
187
|
module.exports.addLoggerToTheConfig = addLoggerToTheConfig
|
|
156
|
-
module.exports.tsCompiler = compiler
|
|
157
188
|
module.exports.start = start
|
|
158
189
|
module.exports.Generator = ServiceGenerator
|
|
190
|
+
module.exports.ServiceStackable = ServiceStackable
|
|
191
|
+
module.exports.buildCompileCmd = buildCompileCmd
|
|
192
|
+
module.exports.extractTypeScriptCompileOptionsFromConfig = extractTypeScriptCompileOptionsFromConfig
|
package/index.test-d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
platformaticService,
|
|
13
13
|
Stackable,
|
|
14
14
|
Generator,
|
|
15
|
-
PlatformaticServiceConfig
|
|
15
|
+
PlatformaticServiceConfig,
|
|
16
16
|
} from '.'
|
|
17
17
|
|
|
18
18
|
declare module 'fastify' {
|
|
@@ -32,21 +32,23 @@ expectType<MercuriusPlugin>(server.graphql)
|
|
|
32
32
|
expectType<Promise<void>>(server.restart())
|
|
33
33
|
|
|
34
34
|
function buildStackable (): Stackable<PlatformaticServiceConfig> {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const myApp: Stackable<PlatformaticServiceConfig> = {
|
|
36
|
+
async app (app: FastifyInstance, opts: object): Promise<void> {
|
|
37
|
+
await platformaticService.app(app, opts)
|
|
38
|
+
},
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
schema: platformaticService.schema,
|
|
41
|
+
configType: 'myApp',
|
|
42
|
+
configManagerConfig: {
|
|
43
|
+
version: platformaticService.configManagerConfig.version,
|
|
44
|
+
...platformaticService.configManagerConfig,
|
|
45
|
+
async transformConfig (this: ConfigManager<PlatformaticServiceConfig>) {
|
|
46
|
+
this.current.plugins = {
|
|
47
|
+
paths: [{
|
|
48
|
+
path: 'my-plugin',
|
|
49
|
+
}],
|
|
50
|
+
}
|
|
51
|
+
},
|
|
50
52
|
},
|
|
51
53
|
async upgrade (config: PlatformaticServiceConfig, version: string) {
|
|
52
54
|
const upgrade = platformaticService.configManagerConfig.upgrade
|
|
@@ -54,7 +56,7 @@ function buildStackable (): Stackable<PlatformaticServiceConfig> {
|
|
|
54
56
|
return upgrade.call(this, config, version)
|
|
55
57
|
}
|
|
56
58
|
return config
|
|
57
|
-
}
|
|
59
|
+
},
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
// configVersion is not part of ConfigManagerConfig
|
|
@@ -77,21 +79,22 @@ expectType<MyGenerator>(myGenerator)
|
|
|
77
79
|
expectType<BaseGenerator.BaseGeneratorConfig>(myGenerator.config)
|
|
78
80
|
|
|
79
81
|
function buildStackable2 (): Stackable<PlatformaticServiceConfig> {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
82
|
+
const myApp: Stackable<PlatformaticServiceConfig> = {
|
|
83
|
+
async app (app: FastifyInstance, opts: object): Promise<void> {
|
|
84
|
+
await platformaticService.app(app, opts)
|
|
85
|
+
},
|
|
86
|
+
schema: platformaticService.schema,
|
|
87
|
+
configType: 'myApp',
|
|
88
|
+
configManagerConfig: {
|
|
89
|
+
...platformaticService.configManagerConfig,
|
|
90
|
+
async transformConfig (this: ConfigManager<PlatformaticServiceConfig>) {
|
|
91
|
+
this.current.plugins = {
|
|
92
|
+
paths: [{
|
|
93
|
+
path: 'my-plugin',
|
|
94
|
+
}],
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
},
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
await start(myApp, ['--help'])
|
package/lib/compile.js
CHANGED
|
@@ -1,110 +1,19 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { compile } = require('@platformatic/ts-compiler')
|
|
4
|
+
const { loadConfig } = require('@platformatic/config')
|
|
4
5
|
const pino = require('pino')
|
|
5
6
|
const pretty = require('pino-pretty')
|
|
6
|
-
const {
|
|
7
|
-
const { isFileAccessible } = require('./utils.js')
|
|
8
|
-
const { readFile, rm } = require('fs/promises')
|
|
9
|
-
|
|
10
|
-
async function getTSCExecutablePath (cwd) {
|
|
11
|
-
const typescriptPath = require.resolve('typescript')
|
|
12
|
-
const typescriptPathCWD = require.resolve('typescript', { paths: [process.cwd()] })
|
|
13
|
-
|
|
14
|
-
const tscLocalPath = join(typescriptPath, '..', '..', 'bin', 'tsc')
|
|
15
|
-
const tscGlobalPath = join(typescriptPathCWD, '..', '..', 'bin', 'tsc')
|
|
16
|
-
|
|
17
|
-
const [tscLocalExists, tscGlobalExists] = await Promise.all([
|
|
18
|
-
isFileAccessible(tscLocalPath),
|
|
19
|
-
isFileAccessible(tscGlobalPath)
|
|
20
|
-
])
|
|
21
|
-
|
|
22
|
-
/* c8 ignore next 7 */
|
|
23
|
-
if (tscLocalExists) {
|
|
24
|
-
return tscLocalPath
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (tscGlobalExists) {
|
|
28
|
-
return tscGlobalPath
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function setup (cwd, config, logger) {
|
|
33
|
-
if (!logger) {
|
|
34
|
-
logger = pino(
|
|
35
|
-
pretty({
|
|
36
|
-
translateTime: 'SYS:HH:MM:ss',
|
|
37
|
-
ignore: 'hostname,pid'
|
|
38
|
-
})
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
if (config?.server.logger) {
|
|
42
|
-
logger.level = config.server.logger.level
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const { execa } = await import('execa')
|
|
47
|
-
|
|
48
|
-
const tscExecutablePath = await getTSCExecutablePath(cwd)
|
|
49
|
-
/* c8 ignore next 4 */
|
|
50
|
-
if (tscExecutablePath === undefined) {
|
|
51
|
-
const msg = 'The tsc executable was not found.'
|
|
52
|
-
logger.warn(msg)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const tsConfigPath = config?.plugins?.typescript?.tsConfig || resolve(cwd, 'tsconfig.json')
|
|
56
|
-
const tsConfigExists = await isFileAccessible(tsConfigPath)
|
|
57
|
-
|
|
58
|
-
if (!tsConfigExists) {
|
|
59
|
-
const msg = 'No typescript configuration file was found, skipping compilation.'
|
|
60
|
-
logger.info(msg)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return { execa, logger, tscExecutablePath, tsConfigPath, tsConfigExists }
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function compile (cwd, config, originalLogger, options) {
|
|
67
|
-
const { execa, logger, tscExecutablePath, tsConfigPath, tsConfigExists } = await setup(cwd, config, originalLogger)
|
|
68
|
-
/* c8 ignore next 3 */
|
|
69
|
-
if (!tscExecutablePath || !tsConfigExists) {
|
|
70
|
-
return false
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
const tsFlags = config?.plugins?.typescript?.flags || ['--project', tsConfigPath, '--rootDir', '.']
|
|
75
|
-
const env = {
|
|
76
|
-
...process.env
|
|
77
|
-
}
|
|
78
|
-
delete env.NODE_V8_COVERAGE
|
|
79
|
-
// somehow c8 does not pick up these lines even if there is a specific test
|
|
80
|
-
/* c8 ignore start */
|
|
81
|
-
if (options && options.clean) {
|
|
82
|
-
// delete outdir directory
|
|
83
|
-
const tsConfigContents = JSON.parse(await readFile(tsConfigPath, 'utf8'))
|
|
84
|
-
const outDir = tsConfigContents.compilerOptions.outDir
|
|
85
|
-
if (outDir) {
|
|
86
|
-
const outDirFullPath = join(dirname(tsConfigPath), outDir)
|
|
87
|
-
originalLogger.info(`Removing build directory ${outDirFullPath}`)
|
|
88
|
-
await rm(outDirFullPath, { recursive: true })
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/* c8 ignore stop */
|
|
92
|
-
await execa(tscExecutablePath, tsFlags, { cwd, env })
|
|
93
|
-
logger.info('Typescript compilation completed successfully.')
|
|
94
|
-
return true
|
|
95
|
-
} catch (error) {
|
|
96
|
-
logger.error(error.message)
|
|
97
|
-
return false
|
|
98
|
-
}
|
|
99
|
-
}
|
|
7
|
+
const { dirname } = require('path')
|
|
100
8
|
|
|
101
9
|
function buildCompileCmd (app) {
|
|
102
10
|
return async function compileCmd (_args) {
|
|
103
11
|
let fullPath = null
|
|
104
12
|
let config = null
|
|
13
|
+
|
|
105
14
|
try {
|
|
106
15
|
const { configManager } = await loadConfig({}, _args, app, {
|
|
107
|
-
watch: false
|
|
16
|
+
watch: false,
|
|
108
17
|
})
|
|
109
18
|
await configManager.parseAndValidate()
|
|
110
19
|
config = configManager.current
|
|
@@ -114,21 +23,34 @@ function buildCompileCmd (app) {
|
|
|
114
23
|
console.error(err)
|
|
115
24
|
process.exit(1)
|
|
116
25
|
}
|
|
117
|
-
|
|
118
|
-
clean: _args.includes('--clean')
|
|
119
|
-
}
|
|
26
|
+
|
|
120
27
|
const logger = pino(
|
|
121
28
|
pretty({
|
|
122
29
|
translateTime: 'SYS:HH:MM:ss',
|
|
123
|
-
ignore: 'hostname,pid'
|
|
30
|
+
ignore: 'hostname,pid',
|
|
124
31
|
})
|
|
125
32
|
)
|
|
126
33
|
|
|
127
|
-
|
|
34
|
+
const compileOptions = {
|
|
35
|
+
...extractTypeScriptCompileOptionsFromConfig(config),
|
|
36
|
+
cwd: fullPath,
|
|
37
|
+
logger,
|
|
38
|
+
clean: _args.includes('--clean'),
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!await compile(compileOptions)) {
|
|
128
42
|
process.exit(1)
|
|
129
43
|
}
|
|
130
44
|
}
|
|
131
45
|
}
|
|
132
46
|
|
|
133
|
-
module.exports.compile = compile
|
|
134
47
|
module.exports.buildCompileCmd = buildCompileCmd
|
|
48
|
+
|
|
49
|
+
function extractTypeScriptCompileOptionsFromConfig (config) {
|
|
50
|
+
return {
|
|
51
|
+
tsConfig: config.plugins?.typescript?.tsConfig,
|
|
52
|
+
flags: config.plugins?.typescript?.flags,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports.extractTypeScriptCompileOptionsFromConfig = extractTypeScriptCompileOptionsFromConfig
|
package/lib/create.mjs
CHANGED
|
@@ -16,14 +16,14 @@ function printAppSummary (args, logger) {
|
|
|
16
16
|
{ config: 'Language', value: args.typescript ? 'Typescript' : 'Javascript' },
|
|
17
17
|
{ config: 'Init Git Repository', value: args.git },
|
|
18
18
|
{ config: 'Install Dependencies', value: args.install },
|
|
19
|
-
{ config: 'Sample Plugin and Tests', value: args.plugin }
|
|
19
|
+
{ config: 'Sample Plugin and Tests', value: args.plugin },
|
|
20
20
|
]
|
|
21
21
|
|
|
22
22
|
const p = new Table({
|
|
23
23
|
columns: [
|
|
24
24
|
{ name: 'config', alignment: 'right' },
|
|
25
|
-
{ name: 'value', alignment: 'left' }
|
|
26
|
-
]
|
|
25
|
+
{ name: 'value', alignment: 'left' },
|
|
26
|
+
],
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
p.addRows(table)
|
|
@@ -34,7 +34,7 @@ async function createService (_args) {
|
|
|
34
34
|
translateTime: 'SYS:HH:MM:ss',
|
|
35
35
|
ignore: 'hostname,pid',
|
|
36
36
|
minimumLevel: 'debug',
|
|
37
|
-
sync: true
|
|
37
|
+
sync: true,
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
const logger = pino(stream)
|
|
@@ -49,8 +49,8 @@ async function createService (_args) {
|
|
|
49
49
|
plugin: true,
|
|
50
50
|
typescript: false,
|
|
51
51
|
git: false,
|
|
52
|
-
install: true
|
|
53
|
-
}
|
|
52
|
+
install: true,
|
|
53
|
+
},
|
|
54
54
|
|
|
55
55
|
})
|
|
56
56
|
|
|
@@ -64,7 +64,7 @@ async function createService (_args) {
|
|
|
64
64
|
tests: args.plugin,
|
|
65
65
|
typescript: args.typescript,
|
|
66
66
|
initGitRepository: args.git,
|
|
67
|
-
targetDirectory: args.dir
|
|
67
|
+
targetDirectory: args.dir,
|
|
68
68
|
})
|
|
69
69
|
|
|
70
70
|
try {
|
package/lib/gen-schema.js
CHANGED
package/lib/gen-types.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { writeFile } from 'fs/promises'
|
|
|
4
4
|
import pino from 'pino'
|
|
5
5
|
import pretty from 'pino-pretty'
|
|
6
6
|
import { loadConfig } from '@platformatic/config'
|
|
7
|
-
import
|
|
7
|
+
import platformaticService from '../index.js'
|
|
8
8
|
import { checkForDependencies } from '@platformatic/utils'
|
|
9
9
|
|
|
10
10
|
const GLOBAL_TYPES_TEMPLATE = `
|
|
@@ -25,7 +25,7 @@ async function execute ({ logger, configManager }) {
|
|
|
25
25
|
async function generateTypes (_args) {
|
|
26
26
|
const logger = pino(pretty({
|
|
27
27
|
translateTime: 'SYS:HH:MM:ss',
|
|
28
|
-
ignore: 'hostname,pid'
|
|
28
|
+
ignore: 'hostname,pid',
|
|
29
29
|
}))
|
|
30
30
|
const { configManager, args } = await loadConfig({}, _args, platformaticService)
|
|
31
31
|
await configManager.parseAndValidate()
|