@platformatic/service 1.9.0 → 1.11.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/help/compile.txt CHANGED
@@ -7,6 +7,8 @@ Compile typescript plugins.
7
7
  As a result of executing this command, Platformatic Service will compile typescript
8
8
  plugins in the `outDir` directory.
9
9
 
10
+ Using the `--clean` flag, the outDir directory will be removed before the new compilation process starts.
11
+
10
12
  If not specified, the configuration will be loaded from any of the following, in the current directory.
11
13
 
12
14
  * `platformatic.service.json`, or
package/index.d.ts CHANGED
@@ -38,8 +38,11 @@ interface SchemaExport {
38
38
  schema: JSONSchemaType<PlatformaticServiceConfig>
39
39
  }
40
40
 
41
+ interface TSCompilerOptions {
42
+ clean: boolean
43
+ }
41
44
  interface TSCompiler {
42
- compile: (cwd: string, config: object, originalLogger: FastifyBaseLogger) => Promise<boolean>
45
+ compile: (cwd: string, config: object, originalLogger: FastifyBaseLogger, options: TSCompilerOptions) => Promise<boolean>
43
46
  }
44
47
  export const schema: SchemaExport
45
48
 
package/lib/compile.js CHANGED
@@ -5,6 +5,7 @@ const pino = require('pino')
5
5
  const pretty = require('pino-pretty')
6
6
  const { loadConfig } = require('@platformatic/config')
7
7
  const { isFileAccessible } = require('./utils.js')
8
+ const { readFile, rm } = require('fs/promises')
8
9
 
9
10
  async function getTSCExecutablePath (cwd) {
10
11
  const typescriptPath = require.resolve('typescript')
@@ -62,7 +63,7 @@ async function setup (cwd, config, logger) {
62
63
  return { execa, logger, tscExecutablePath, tsConfigPath, tsConfigExists }
63
64
  }
64
65
 
65
- async function compile (cwd, config, originalLogger) {
66
+ async function compile (cwd, config, originalLogger, options) {
66
67
  const { execa, logger, tscExecutablePath, tsConfigPath, tsConfigExists } = await setup(cwd, config, originalLogger)
67
68
  /* c8 ignore next 3 */
68
69
  if (!tscExecutablePath || !tsConfigExists) {
@@ -75,7 +76,18 @@ async function compile (cwd, config, originalLogger) {
75
76
  ...process.env
76
77
  }
77
78
  delete env.NODE_V8_COVERAGE
78
-
79
+ // somehow c8 does not pick up these lines even if there is a specific test
80
+ /* c8 ignore 10 */
81
+ if (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
+ }
79
91
  await execa(tscExecutablePath, tsFlags, { cwd, env })
80
92
  logger.info('Typescript compilation completed successfully.')
81
93
  return true
@@ -101,8 +113,17 @@ function buildCompileCmd (app) {
101
113
  console.error(err)
102
114
  process.exit(1)
103
115
  }
116
+ const compileOptions = {
117
+ clean: _args.includes('--clean')
118
+ }
119
+ const logger = pino(
120
+ pretty({
121
+ translateTime: 'SYS:HH:MM:ss',
122
+ ignore: 'hostname,pid'
123
+ })
124
+ )
104
125
 
105
- if (!await compile(fullPath, config)) {
126
+ if (!await compile(fullPath, config, logger, compileOptions)) {
106
127
  process.exit(1)
107
128
  }
108
129
  }
package/lib/gen-types.mjs CHANGED
@@ -28,8 +28,6 @@ async function generateTypes (_args) {
28
28
  ignore: 'hostname,pid'
29
29
  }))
30
30
  const { configManager, args } = await loadConfig({}, _args, platformaticService)
31
-
32
- console.log('antanis', new Error().stack)
33
31
  await configManager.parseAndValidate()
34
32
  const config = configManager.current
35
33
 
@@ -19,7 +19,7 @@ async function setupOpenAPI (app, opts) {
19
19
  }
20
20
  }, typeof opts === 'object' ? opts : {})
21
21
  app.log.trace({ openapi: openapiConfig })
22
- await app.register(Swagger, {
22
+ const swaggerOptions = {
23
23
  exposeRoute: openapiConfig.exposeRoute,
24
24
  openapi: {
25
25
  ...openapiConfig
@@ -31,7 +31,15 @@ async function setupOpenAPI (app, opts) {
31
31
  return json.$id || `def-${i}`
32
32
  }
33
33
  }
34
- })
34
+ }
35
+
36
+ if (opts.path) {
37
+ swaggerOptions.mode = 'static'
38
+ swaggerOptions.specification = {
39
+ path: opts.path
40
+ }
41
+ }
42
+ await app.register(Swagger, swaggerOptions)
35
43
 
36
44
  const { default: theme } = await import('@platformatic/swagger-ui-theme')
37
45
  app.register(SwaggerUI, {
@@ -10,7 +10,7 @@ async function setupTsCompiler (app) {
10
10
  const config = configManager.current
11
11
  const workingDir = configManager.dirname
12
12
 
13
- await compiler.compile(workingDir, config, app.log)
13
+ await compiler.compile(workingDir, config, app.log, { clean: false })
14
14
  }
15
15
 
16
16
  module.exports = fp(setupTsCompiler)
package/lib/schema.js CHANGED
@@ -600,6 +600,11 @@ const openApiBase = {
600
600
  prefix: {
601
601
  type: 'string',
602
602
  description: 'Base URL for the OpenAPI'
603
+ },
604
+ path: {
605
+ type: 'string',
606
+ description: 'Path to an OpenAPI spec file',
607
+ resolvePath: true
603
608
  }
604
609
  }
605
610
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -68,11 +68,11 @@
68
68
  "pino-pretty": "^10.2.0",
69
69
  "rfdc": "^1.3.0",
70
70
  "ua-parser-js": "^1.0.36",
71
- "@platformatic/client": "1.9.0",
72
- "@platformatic/config": "1.9.0",
73
- "@platformatic/swagger-ui-theme": "1.9.0",
74
- "@platformatic/telemetry": "1.9.0",
75
- "@platformatic/utils": "1.9.0"
71
+ "@platformatic/client": "1.11.0",
72
+ "@platformatic/config": "1.11.0",
73
+ "@platformatic/swagger-ui-theme": "1.11.0",
74
+ "@platformatic/telemetry": "1.11.0",
75
+ "@platformatic/utils": "1.11.0"
76
76
  },
77
77
  "standard": {
78
78
  "ignore": [