@platformatic/service 1.17.0 → 1.19.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/create.txt +11 -0
- package/help/help.txt +1 -0
- package/lib/create.mjs +85 -0
- package/lib/plugins/openapi.js +8 -2
- package/package.json +11 -9
- package/service.mjs +2 -1
package/help/create.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Creates a new Platformatic Service application.
|
|
2
|
+
|
|
3
|
+
Options are
|
|
4
|
+
|
|
5
|
+
* `dir <string>` - the directory where to create the project (Default: `process.cwd() + 'platformatic-composer'`)
|
|
6
|
+
* `port <string>` - the port where the application will listen (Default: `3042`)
|
|
7
|
+
* `hostname <string>` - the hostname where the application will listen (Default: `0.0.0.0`)
|
|
8
|
+
* `git <boolean>` - Init the git repository (Default: `true`)
|
|
9
|
+
* `typescript <boolean>` - Use Typescript (Default: `false`)
|
|
10
|
+
* `install <boolean>` - Run or not `npm install` after creating the files (Default: `true`)
|
|
11
|
+
* `plugin <boolean>` - Creates a sample plugin and tests (Default: `true`)
|
package/help/help.txt
CHANGED
package/lib/create.mjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
import minimist from 'minimist'
|
|
3
|
+
import { Generator } from '../lib/generator/service-generator.js'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { getPkgManager } from '@platformatic/utils'
|
|
6
|
+
import { execa } from 'execa'
|
|
7
|
+
import ora from 'ora'
|
|
8
|
+
import { Table } from 'console-table-printer'
|
|
9
|
+
import pino from 'pino'
|
|
10
|
+
import pinoPretty from 'pino-pretty'
|
|
11
|
+
|
|
12
|
+
function printAppSummary (args, logger) {
|
|
13
|
+
logger.info('Creating a Platformatic Service app with this config: ')
|
|
14
|
+
const table = [
|
|
15
|
+
{ config: 'Directory', value: args.dir },
|
|
16
|
+
{ config: 'Language', value: args.typescript ? 'Typescript' : 'Javascript' },
|
|
17
|
+
{ config: 'Init Git Repository', value: args.git },
|
|
18
|
+
{ config: 'Install Dependencies', value: args.install },
|
|
19
|
+
{ config: 'Sample Plugin and Tests', value: args.plugin }
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
const p = new Table({
|
|
23
|
+
columns: [
|
|
24
|
+
{ name: 'config', alignment: 'right' },
|
|
25
|
+
{ name: 'value', alignment: 'left' }
|
|
26
|
+
]
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
p.addRows(table)
|
|
30
|
+
p.printTable()
|
|
31
|
+
}
|
|
32
|
+
async function createService (_args) {
|
|
33
|
+
const stream = pinoPretty({
|
|
34
|
+
translateTime: 'SYS:HH:MM:ss',
|
|
35
|
+
ignore: 'hostname,pid',
|
|
36
|
+
minimumLevel: 'debug',
|
|
37
|
+
sync: true
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const logger = pino(stream)
|
|
41
|
+
|
|
42
|
+
const args = minimist(process.argv.slice(2), {
|
|
43
|
+
string: ['dir', 'port', 'hostname'],
|
|
44
|
+
boolean: ['typescript', 'install', 'plugin', 'git'],
|
|
45
|
+
default: {
|
|
46
|
+
dir: join(process.cwd(), 'platformatic-service'),
|
|
47
|
+
port: 3042,
|
|
48
|
+
hostname: '0.0.0.0',
|
|
49
|
+
plugin: true,
|
|
50
|
+
typescript: false,
|
|
51
|
+
git: false,
|
|
52
|
+
install: true
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
printAppSummary(args, logger)
|
|
58
|
+
|
|
59
|
+
const gen = new Generator({})
|
|
60
|
+
gen.setConfig({
|
|
61
|
+
port: args.port,
|
|
62
|
+
hostname: args.hostname,
|
|
63
|
+
plugin: args.plugin,
|
|
64
|
+
tests: args.plugin,
|
|
65
|
+
typescript: args.typescript,
|
|
66
|
+
initGitRepository: args.git,
|
|
67
|
+
targetDirectory: args.dir
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
await gen.run()
|
|
72
|
+
if (args.install) {
|
|
73
|
+
const pkgManager = getPkgManager()
|
|
74
|
+
const spinner = ora('Installing dependencies...').start()
|
|
75
|
+
await execa(pkgManager, ['install'], { cwd: args.dir })
|
|
76
|
+
spinner.succeed()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
logger.info('Done! 🎉')
|
|
80
|
+
} catch (err) {
|
|
81
|
+
logger.error(err.message)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { createService }
|
package/lib/plugins/openapi.js
CHANGED
|
@@ -58,8 +58,14 @@ async function setupOpenAPI (app, opts) {
|
|
|
58
58
|
const routePrefix = openapi.swaggerPrefix || '/documentation'
|
|
59
59
|
|
|
60
60
|
/** Serve spec file in yaml and json */
|
|
61
|
-
app.get(`${routePrefix}/json`, {
|
|
62
|
-
|
|
61
|
+
app.get(`${routePrefix}/json`, {
|
|
62
|
+
schema: { hide: true },
|
|
63
|
+
logLevel: 'warn'
|
|
64
|
+
}, async () => app.swagger())
|
|
65
|
+
app.get(`${routePrefix}/yaml`, {
|
|
66
|
+
schema: { hide: true },
|
|
67
|
+
logLevel: 'warn'
|
|
68
|
+
}, async () => app.swagger({ yaml: true }))
|
|
63
69
|
|
|
64
70
|
app.register(ScalarApiReference, {
|
|
65
71
|
...opts,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/service",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"code-block-writer": "^12.0.0",
|
|
59
59
|
"colorette": "^2.0.20",
|
|
60
60
|
"commist": "^3.2.0",
|
|
61
|
+
"console-table-printer": "^2.11.2",
|
|
61
62
|
"desm": "^1.3.0",
|
|
62
63
|
"env-schema": "^5.2.0",
|
|
63
64
|
"es-main": "^1.3.0",
|
|
@@ -71,19 +72,20 @@
|
|
|
71
72
|
"mercurius": "^13.1.0",
|
|
72
73
|
"minimist": "^1.2.8",
|
|
73
74
|
"openapi-schema-diff": "^0.0.1",
|
|
75
|
+
"ora": "^6.3.1",
|
|
74
76
|
"pino": "^8.15.3",
|
|
75
77
|
"pino-pretty": "^10.2.0",
|
|
76
78
|
"rfdc": "^1.3.0",
|
|
77
79
|
"ua-parser-js": "^1.0.36",
|
|
78
80
|
"undici": "^6.0.0",
|
|
79
|
-
"@platformatic/authenticate": "1.
|
|
80
|
-
"@platformatic/client": "1.
|
|
81
|
-
"@platformatic/config": "1.
|
|
82
|
-
"@platformatic/generators": "1.
|
|
83
|
-
"@platformatic/
|
|
84
|
-
"@platformatic/
|
|
85
|
-
"@platformatic/
|
|
86
|
-
"@platformatic/
|
|
81
|
+
"@platformatic/authenticate": "1.19.0",
|
|
82
|
+
"@platformatic/client": "1.19.0",
|
|
83
|
+
"@platformatic/config": "1.19.0",
|
|
84
|
+
"@platformatic/generators": "1.19.0",
|
|
85
|
+
"@platformatic/scalar-theme": "1.19.0",
|
|
86
|
+
"@platformatic/telemetry": "1.19.0",
|
|
87
|
+
"@platformatic/utils": "1.19.0",
|
|
88
|
+
"@platformatic/metaconfig": "1.19.0"
|
|
87
89
|
},
|
|
88
90
|
"standard": {
|
|
89
91
|
"ignore": [
|
package/service.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { generateJsonSchemaConfig } from './lib/gen-schema.js'
|
|
|
11
11
|
import { bumpVersion } from './lib/bump-version.js'
|
|
12
12
|
import { updateVersion } from './lib/update-version.js'
|
|
13
13
|
import { generateTypes } from './lib/gen-types.mjs'
|
|
14
|
-
|
|
14
|
+
import { createService } from './lib/create.mjs'
|
|
15
15
|
import { buildCompileCmd } from './lib/compile.js'
|
|
16
16
|
|
|
17
17
|
import { start, platformaticService } from './index.js'
|
|
@@ -43,6 +43,7 @@ program.register('start', (argv) => {
|
|
|
43
43
|
start(platformaticService, argv).catch(printAndExitLoadConfigError)
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
+
program.register('create', wrapCommand(createService))
|
|
46
47
|
program.register('compile', buildCompileCmd(platformaticService))
|
|
47
48
|
program.register('types', wrapCommand(generateTypes))
|
|
48
49
|
program.register('schema config', wrapCommand(generateJsonSchemaConfig))
|