create-platformatic 1.8.1 → 1.10.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/package.json +4 -4
- package/src/composer/create-composer-cli.mjs +5 -0
- package/src/create-package-json.mjs +2 -1
- package/src/create-plugins.mjs +5 -1
- package/src/db/create-db-cli.mjs +4 -0
- package/src/get-tsconfig.mjs +1 -0
- package/src/ghaction.mjs +8 -2
- package/src/index.mjs +3 -6
- package/src/runtime/create-runtime-cli.mjs +20 -12
- package/src/service/create-service-cli.mjs +4 -0
- package/src/utils.mjs +11 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-platformatic",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Create platformatic-db interactive tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"strip-ansi": "^7.1.0",
|
|
36
36
|
"undici": "^5.25.4",
|
|
37
37
|
"which": "^3.0.1",
|
|
38
|
-
"@platformatic/config": "1.
|
|
38
|
+
"@platformatic/config": "1.10.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"ajv": "^8.12.0",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"tap": "^16.3.9",
|
|
49
49
|
"typescript": "~5.2.2",
|
|
50
50
|
"yaml": "^2.3.2",
|
|
51
|
-
"@platformatic/
|
|
52
|
-
"@platformatic/
|
|
51
|
+
"@platformatic/db": "1.10.0",
|
|
52
|
+
"@platformatic/service": "1.10.0"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"test:cli": "tap --no-coverage test/cli/*test.mjs -t120",
|
|
@@ -135,6 +135,11 @@ const createPlatformaticComposer = async (_args, opts) => {
|
|
|
135
135
|
await execa(pkgManager, ['install'], { cwd: projectDir })
|
|
136
136
|
spinner.succeed()
|
|
137
137
|
}
|
|
138
|
+
|
|
139
|
+
// returns metadata that can be used to make some further actions
|
|
140
|
+
return {
|
|
141
|
+
typescript: useTypescript
|
|
142
|
+
}
|
|
138
143
|
}
|
|
139
144
|
|
|
140
145
|
export default createPlatformaticComposer
|
|
@@ -47,11 +47,12 @@ const packageJsonTemplate = async (addTSBuild, fastifyVersion, platVersion) => {
|
|
|
47
47
|
* @param {object} scripts Package.json scripts list
|
|
48
48
|
* @param {object} dependencies Package.json dependencies list
|
|
49
49
|
*/
|
|
50
|
-
export const createPackageJson = async (platVersion, fastifyVersion, logger, dir, addTSBuild = false, scripts = {}, dependencies = {}) => {
|
|
50
|
+
export const createPackageJson = async (platVersion, fastifyVersion, logger, dir, addTSBuild = false, scripts = {}, dependencies = {}, devDependencies = {}) => {
|
|
51
51
|
const packageJsonFileName = join(dir, 'package.json')
|
|
52
52
|
const pkg = await packageJsonTemplate(addTSBuild, fastifyVersion, platVersion)
|
|
53
53
|
Object.assign(pkg.scripts, scripts)
|
|
54
54
|
Object.assign(pkg.dependencies, dependencies)
|
|
55
|
+
Object.assign(pkg.devDependencies, devDependencies)
|
|
55
56
|
await writeFile(packageJsonFileName, JSON.stringify(pkg, null, 2))
|
|
56
57
|
logger.debug(`${packageJsonFileName} successfully created.`)
|
|
57
58
|
}
|
package/src/create-plugins.mjs
CHANGED
|
@@ -116,9 +116,13 @@ function testHelperTS (mod, customizations = { pre: '', post: '', config: '', re
|
|
|
116
116
|
import { join } from 'node:path'
|
|
117
117
|
import { readFile } from 'node:fs/promises'
|
|
118
118
|
import { buildServer } from '@platformatic/${mod}'
|
|
119
|
+
import { test } from 'node:test'
|
|
119
120
|
${customizations.requires}
|
|
120
121
|
|
|
121
|
-
|
|
122
|
+
type testfn = Parameters<typeof test>[0]
|
|
123
|
+
type TestContext = Parameters<Exclude<testfn, undefined>>[0]
|
|
124
|
+
|
|
125
|
+
export async function getServer (t: TestContext) {
|
|
122
126
|
${customizations.pre}
|
|
123
127
|
// We go up two folder because this files executes in the dist folder
|
|
124
128
|
const config = JSON.parse(await readFile(join(__dirname, '..', '..', 'platformatic.${mod}.json'), 'utf8'))
|
package/src/db/create-db-cli.mjs
CHANGED
package/src/get-tsconfig.mjs
CHANGED
package/src/ghaction.mjs
CHANGED
|
@@ -99,6 +99,13 @@ ${envBlock}
|
|
|
99
99
|
|
|
100
100
|
export const staticWorkspaceGHTemplate = (env, config, buildTS = false) => {
|
|
101
101
|
const envString = envAsString(env, 3)
|
|
102
|
+
let envBlock = ''
|
|
103
|
+
if (envString.length) {
|
|
104
|
+
envBlock = `
|
|
105
|
+
env:
|
|
106
|
+
${envString}
|
|
107
|
+
`
|
|
108
|
+
}
|
|
102
109
|
|
|
103
110
|
return `name: Deploy Platformatic application to the cloud
|
|
104
111
|
on:
|
|
@@ -116,8 +123,7 @@ jobs:
|
|
|
116
123
|
permissions:
|
|
117
124
|
contents: read
|
|
118
125
|
runs-on: ubuntu-latest
|
|
119
|
-
|
|
120
|
-
${envString}
|
|
126
|
+
${envBlock}
|
|
121
127
|
steps:
|
|
122
128
|
- name: Checkout application project repository
|
|
123
129
|
uses: actions/checkout@v3
|
package/src/index.mjs
CHANGED
|
@@ -31,14 +31,11 @@ export async function chooseKind (argv, opts = {}) {
|
|
|
31
31
|
|
|
32
32
|
switch (options.type) {
|
|
33
33
|
case 'db':
|
|
34
|
-
await createPlatformaticDB(argv, opts)
|
|
35
|
-
break
|
|
34
|
+
return await createPlatformaticDB(argv, opts)
|
|
36
35
|
case 'service':
|
|
37
|
-
await createPlatformaticService(argv, opts)
|
|
38
|
-
break
|
|
36
|
+
return await createPlatformaticService(argv, opts)
|
|
39
37
|
case 'composer':
|
|
40
|
-
await createPlatformaticComposer(argv, opts)
|
|
41
|
-
break
|
|
38
|
+
return await createPlatformaticComposer(argv, opts)
|
|
42
39
|
case 'runtime':
|
|
43
40
|
await createPlatformaticRuntime(argv, opts)
|
|
44
41
|
break
|
|
@@ -72,20 +72,15 @@ export async function createPlatformaticRuntime (_args) {
|
|
|
72
72
|
|
|
73
73
|
const fastifyVersion = await getDependencyVersion('fastify')
|
|
74
74
|
|
|
75
|
-
// Create the package.json, notes that we don't have the option for TS (yet) so we don't generate
|
|
76
|
-
// the package.json with the TS build
|
|
77
|
-
await createPackageJson(version, fastifyVersion, logger, projectDir, false)
|
|
78
|
-
await createGitignore(logger, projectDir)
|
|
79
|
-
await createReadme(logger, projectDir, 'runtime')
|
|
80
|
-
|
|
81
75
|
logger.info('Let\'s create a first service!')
|
|
82
76
|
|
|
83
77
|
const names = []
|
|
78
|
+
let addTypescriptDevDep = false
|
|
84
79
|
while (true) {
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
const serviceData = await createRuntimeService({ servicesDir, names, logger })
|
|
81
|
+
if (!addTypescriptDevDep && serviceData.typescript) {
|
|
82
|
+
addTypescriptDevDep = true
|
|
87
83
|
}
|
|
88
|
-
|
|
89
84
|
const { shouldBreak } = await inquirer.prompt([
|
|
90
85
|
{
|
|
91
86
|
type: 'list',
|
|
@@ -100,6 +95,18 @@ export async function createPlatformaticRuntime (_args) {
|
|
|
100
95
|
break
|
|
101
96
|
}
|
|
102
97
|
}
|
|
98
|
+
const devDependencies = {}
|
|
99
|
+
if (addTypescriptDevDep) {
|
|
100
|
+
const typescriptVersion = await getDependencyVersion('typescript')
|
|
101
|
+
devDependencies.typescript = `^${typescriptVersion}`
|
|
102
|
+
devDependencies['@types/node'] = 'latest'
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Create the package.json, notes that we don't have the option for TS (yet) so we don't generate
|
|
106
|
+
// the package.json with the TS build
|
|
107
|
+
await createPackageJson(version, fastifyVersion, logger, projectDir, false, {}, {}, devDependencies)
|
|
108
|
+
await createGitignore(logger, projectDir)
|
|
109
|
+
await createReadme(logger, projectDir, 'runtime')
|
|
103
110
|
|
|
104
111
|
let entrypoint = ''
|
|
105
112
|
|
|
@@ -126,7 +133,8 @@ export async function createPlatformaticRuntime (_args) {
|
|
|
126
133
|
staticWorkspaceGitHubAction,
|
|
127
134
|
dynamicWorkspaceGitHubAction,
|
|
128
135
|
serviceNames: names,
|
|
129
|
-
initGitRepository
|
|
136
|
+
initGitRepository,
|
|
137
|
+
typescript: addTypescriptDevDep
|
|
130
138
|
}
|
|
131
139
|
|
|
132
140
|
await createRuntime(params, logger, projectDir, version)
|
|
@@ -168,7 +176,7 @@ export async function createRuntimeService ({ servicesDir, names, logger }) {
|
|
|
168
176
|
|
|
169
177
|
const serviceDir = join(servicesDir, name)
|
|
170
178
|
|
|
171
|
-
await chooseKind([], {
|
|
179
|
+
const serviceData = await chooseKind([], {
|
|
172
180
|
skip: 'runtime',
|
|
173
181
|
serviceName: name,
|
|
174
182
|
dir: serviceDir,
|
|
@@ -185,5 +193,5 @@ export async function createRuntimeService ({ servicesDir, names, logger }) {
|
|
|
185
193
|
}
|
|
186
194
|
})
|
|
187
195
|
|
|
188
|
-
return
|
|
196
|
+
return serviceData
|
|
189
197
|
}
|
|
@@ -122,5 +122,9 @@ const createPlatformaticService = async (_args, opts = {}) => {
|
|
|
122
122
|
logger.trace({ err })
|
|
123
123
|
spinner.fail('Failed to generate Types. Try again by running "platformatic service types"')
|
|
124
124
|
}
|
|
125
|
+
// returns metadata that can be used to make some further actions
|
|
126
|
+
return {
|
|
127
|
+
typescript: useTypescript
|
|
128
|
+
}
|
|
125
129
|
}
|
|
126
130
|
export default createPlatformaticService
|
package/src/utils.mjs
CHANGED
|
@@ -74,7 +74,17 @@ export const findRuntimeConfigFile = async (directory) => (ConfigManager.findCon
|
|
|
74
74
|
*/
|
|
75
75
|
export const getDependencyVersion = async (dependencyName) => {
|
|
76
76
|
const require = createRequire(import.meta.url)
|
|
77
|
-
|
|
77
|
+
let dependencyPath = dirname(require.resolve(dependencyName))
|
|
78
|
+
// some deps are resolved not at their root level
|
|
79
|
+
// for instance 'typescript' will be risolved in its own ./lib directory
|
|
80
|
+
// next loop is to find the nearest parent directory that contains a package.json file
|
|
81
|
+
while (!await isFileAccessible(join(dependencyPath, 'package.json'))) {
|
|
82
|
+
dependencyPath = join(dependencyPath, '..')
|
|
83
|
+
if (dependencyPath === '/') {
|
|
84
|
+
throw new Error(`Cannot find package.json for ${dependencyName}`)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const pathToPackageJson = join(dependencyPath, 'package.json')
|
|
78
88
|
const packageJsonFile = await readFile(pathToPackageJson, 'utf-8')
|
|
79
89
|
const packageJson = JSON.parse(packageJsonFile)
|
|
80
90
|
return packageJson.version
|