create-platformatic 1.10.0 → 1.12.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 +8 -8
- package/src/cli-options.mjs +0 -10
- package/src/composer/create-composer-cli.mjs +6 -8
- package/src/db/create-db-cli.mjs +8 -10
- package/src/db/create-db.mjs +0 -1
- package/src/index.mjs +1 -0
- package/src/runtime/create-runtime-cli.mjs +11 -9
- package/src/service/create-service-cli.mjs +6 -9
- package/src/service/create-service.mjs +0 -1
- package/src/utils.mjs +39 -13
- package/.taprc +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-platformatic",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Create platformatic-db interactive tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"license": "Apache-2.0",
|
|
16
16
|
"author": "Marco Piraccini <marco.piraccini@gmail.com>",
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"@types/node": "^20.8.10",
|
|
18
19
|
"boring-name-generator": "^1.0.3",
|
|
19
20
|
"chalk": "^5.3.0",
|
|
20
21
|
"columnify": "^1.6.0",
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
"strip-ansi": "^7.1.0",
|
|
36
37
|
"undici": "^5.25.4",
|
|
37
38
|
"which": "^3.0.1",
|
|
38
|
-
"@platformatic/config": "1.
|
|
39
|
+
"@platformatic/config": "1.12.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"ajv": "^8.12.0",
|
|
@@ -45,15 +46,14 @@
|
|
|
45
46
|
"esmock": "^2.5.1",
|
|
46
47
|
"snazzy": "^9.0.0",
|
|
47
48
|
"standard": "^17.1.0",
|
|
48
|
-
"
|
|
49
|
-
"typescript": "~5.2.2",
|
|
49
|
+
"typescript": "~5.3.0",
|
|
50
50
|
"yaml": "^2.3.2",
|
|
51
|
-
"@platformatic/
|
|
52
|
-
"@platformatic/
|
|
51
|
+
"@platformatic/service": "1.12.0",
|
|
52
|
+
"@platformatic/db": "1.12.0"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
|
-
"test:cli": "
|
|
56
|
-
"test:unit": "standard | snazzy && cross-env NODE_OPTIONS=\"--loader=esmock --no-warnings\" c8
|
|
55
|
+
"test:cli": "node --test ./test/cli",
|
|
56
|
+
"test:unit": "standard | snazzy && cross-env NODE_OPTIONS=\"--loader=esmock --no-warnings\" c8 node --test ./test/unit",
|
|
57
57
|
"test": "npm run test:unit && npm run test:cli",
|
|
58
58
|
"lint": "standard | snazzy"
|
|
59
59
|
}
|
package/src/cli-options.mjs
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
export const getRunPackageManagerInstall = pkgManager => {
|
|
2
|
-
return {
|
|
3
|
-
type: 'list',
|
|
4
|
-
name: 'runPackageManagerInstall',
|
|
5
|
-
message: `Do you want to run ${pkgManager} install?`,
|
|
6
|
-
default: true,
|
|
7
|
-
choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
1
|
export const getUseTypescript = typescript => {
|
|
12
2
|
return {
|
|
13
3
|
type: 'list',
|
|
@@ -10,7 +10,7 @@ import { execa } from 'execa'
|
|
|
10
10
|
import ora from 'ora'
|
|
11
11
|
import createComposer from './create-composer.mjs'
|
|
12
12
|
import askDir from '../ask-dir.mjs'
|
|
13
|
-
import {
|
|
13
|
+
import { getPort, getUseTypescript, getInitGitRepository } from '../cli-options.mjs'
|
|
14
14
|
import { createReadme } from '../create-readme.mjs'
|
|
15
15
|
import { join } from 'path'
|
|
16
16
|
|
|
@@ -32,12 +32,14 @@ const createPlatformaticComposer = async (_args, opts) => {
|
|
|
32
32
|
|
|
33
33
|
const args = parseArgs(_args, {
|
|
34
34
|
default: {
|
|
35
|
-
hostname: '127.0.0.1'
|
|
35
|
+
hostname: '127.0.0.1',
|
|
36
|
+
install: true
|
|
36
37
|
},
|
|
37
38
|
alias: {
|
|
38
39
|
h: 'hostname',
|
|
39
40
|
p: 'port'
|
|
40
|
-
}
|
|
41
|
+
},
|
|
42
|
+
boolean: ['install']
|
|
41
43
|
})
|
|
42
44
|
|
|
43
45
|
const version = await getVersion()
|
|
@@ -63,9 +65,6 @@ const createPlatformaticComposer = async (_args, opts) => {
|
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
if (!opts.skipPackageJson) {
|
|
67
|
-
toAsk.push(getRunPackageManagerInstall(pkgManager))
|
|
68
|
-
}
|
|
69
68
|
if (!opts.skipGitHubActions) {
|
|
70
69
|
toAsk.push({
|
|
71
70
|
type: 'list',
|
|
@@ -87,7 +86,6 @@ const createPlatformaticComposer = async (_args, opts) => {
|
|
|
87
86
|
toAsk.push(getInitGitRepository())
|
|
88
87
|
}
|
|
89
88
|
const {
|
|
90
|
-
runPackageManagerInstall,
|
|
91
89
|
servicesToCompose,
|
|
92
90
|
port,
|
|
93
91
|
staticWorkspaceGitHubAction,
|
|
@@ -130,7 +128,7 @@ const createPlatformaticComposer = async (_args, opts) => {
|
|
|
130
128
|
}
|
|
131
129
|
await createReadme(logger, projectDir, 'composer')
|
|
132
130
|
|
|
133
|
-
if (
|
|
131
|
+
if (args.install && !opts.skipPackageJson) {
|
|
134
132
|
const spinner = ora('Installing dependencies...').start()
|
|
135
133
|
await execa(pkgManager, ['install'], { cwd: projectDir })
|
|
136
134
|
spinner.succeed()
|
package/src/db/create-db-cli.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { execa } from 'execa'
|
|
|
11
11
|
import ora from 'ora'
|
|
12
12
|
import { getConnectionString, createDB } from './create-db.mjs'
|
|
13
13
|
import askDir from '../ask-dir.mjs'
|
|
14
|
-
import {
|
|
14
|
+
import { getUseTypescript, getPort, getInitGitRepository } from '../cli-options.mjs'
|
|
15
15
|
import { createReadme } from '../create-readme.mjs'
|
|
16
16
|
import { join } from 'node:path'
|
|
17
17
|
|
|
@@ -34,7 +34,8 @@ export function parseDBArgs (_args) {
|
|
|
34
34
|
default: {
|
|
35
35
|
hostname: '127.0.0.1',
|
|
36
36
|
database: 'sqlite',
|
|
37
|
-
migrations: 'migrations'
|
|
37
|
+
migrations: 'migrations',
|
|
38
|
+
install: true
|
|
38
39
|
},
|
|
39
40
|
alias: {
|
|
40
41
|
h: 'hostname',
|
|
@@ -45,7 +46,7 @@ export function parseDBArgs (_args) {
|
|
|
45
46
|
t: 'types',
|
|
46
47
|
ts: 'typescript'
|
|
47
48
|
},
|
|
48
|
-
boolean: ['plugin', 'types', 'typescript']
|
|
49
|
+
boolean: ['plugin', 'types', 'typescript', 'install']
|
|
49
50
|
})
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -68,11 +69,6 @@ const createPlatformaticDB = async (_args, opts) => {
|
|
|
68
69
|
portQuestion.when = !isRuntimeContext
|
|
69
70
|
toAsk.push(portQuestion)
|
|
70
71
|
|
|
71
|
-
// Ask to install deps
|
|
72
|
-
const installDepsQuestion = getRunPackageManagerInstall(pkgManager)
|
|
73
|
-
installDepsQuestion.when = !opts.skipPackageJson
|
|
74
|
-
toAsk.push(installDepsQuestion)
|
|
75
|
-
|
|
76
72
|
const { database } = await inquirer.prompt({
|
|
77
73
|
type: 'list',
|
|
78
74
|
name: 'database',
|
|
@@ -208,7 +204,7 @@ const createPlatformaticDB = async (_args, opts) => {
|
|
|
208
204
|
await createReadme(logger, projectDir, 'db')
|
|
209
205
|
|
|
210
206
|
let hasPlatformaticInstalled = false
|
|
211
|
-
if (
|
|
207
|
+
if (args.install && !opts.skipPackageJson) {
|
|
212
208
|
const spinner = ora('Installing dependencies...').start()
|
|
213
209
|
await execa(pkgManager, ['install'], { cwd: projectDir })
|
|
214
210
|
spinner.succeed()
|
|
@@ -234,18 +230,20 @@ const createPlatformaticDB = async (_args, opts) => {
|
|
|
234
230
|
// - run the migrations
|
|
235
231
|
// - generate types
|
|
236
232
|
// if we don't generate migrations, we don't ask to apply them (the folder might not exist)
|
|
233
|
+
let migrationApplied = false
|
|
237
234
|
if (wizardOptions.defaultMigrations && wizardOptions.applyMigrations) {
|
|
238
235
|
const spinner = ora('Applying migrations...').start()
|
|
239
236
|
// We need to apply migrations using the platformatic installed in the project
|
|
240
237
|
try {
|
|
241
238
|
await execa(pkgManager, ['exec', 'platformatic', 'db', 'migrations', 'apply'], { cwd: projectDir })
|
|
242
239
|
spinner.succeed()
|
|
240
|
+
migrationApplied = true
|
|
243
241
|
} catch (err) {
|
|
244
242
|
logger.trace({ err })
|
|
245
243
|
spinner.fail('Failed applying migrations! Try again by running "platformatic db migrations apply"')
|
|
246
244
|
}
|
|
247
245
|
}
|
|
248
|
-
if (generatePlugin) {
|
|
246
|
+
if (generatePlugin && migrationApplied) {
|
|
249
247
|
const spinner = ora('Generating types...').start()
|
|
250
248
|
try {
|
|
251
249
|
await execa(pkgManager, ['exec', 'platformatic', 'db', 'types'], { cwd: projectDir })
|
package/src/db/create-db.mjs
CHANGED
|
@@ -376,7 +376,6 @@ export async function createDB (params, logger, currentDir, version) {
|
|
|
376
376
|
const envSample = generateEnv(isRuntimeContext, hostname, port, getConnectionString(database), typescript, envPrefix)
|
|
377
377
|
await appendFile(join(currentDir, '.env'), env)
|
|
378
378
|
await writeFile(join(currentDir, '.env.sample'), envSample)
|
|
379
|
-
logger.info('Environment file .env found, appending new environment variables to existing .env file.')
|
|
380
379
|
|
|
381
380
|
const migrationsFolderName = migrations
|
|
382
381
|
if (createMigrations) {
|
package/src/index.mjs
CHANGED
|
@@ -8,9 +8,10 @@ import pino from 'pino'
|
|
|
8
8
|
import pretty from 'pino-pretty'
|
|
9
9
|
import { execa } from 'execa'
|
|
10
10
|
import ora from 'ora'
|
|
11
|
+
import parseArgs from 'minimist'
|
|
11
12
|
import createRuntime from './create-runtime.mjs'
|
|
12
13
|
import askDir from '../ask-dir.mjs'
|
|
13
|
-
import { getInitGitRepository, getPort
|
|
14
|
+
import { getInitGitRepository, getPort } from '../cli-options.mjs'
|
|
14
15
|
import generateName from 'boring-name-generator'
|
|
15
16
|
import { chooseKind } from '../index.mjs'
|
|
16
17
|
import { createReadme } from '../create-readme.mjs'
|
|
@@ -21,6 +22,13 @@ export async function createPlatformaticRuntime (_args) {
|
|
|
21
22
|
ignore: 'hostname,pid'
|
|
22
23
|
}))
|
|
23
24
|
|
|
25
|
+
const args = parseArgs(_args, {
|
|
26
|
+
default: {
|
|
27
|
+
install: true
|
|
28
|
+
},
|
|
29
|
+
boolean: ['install']
|
|
30
|
+
})
|
|
31
|
+
|
|
24
32
|
const version = await getVersion()
|
|
25
33
|
const pkgManager = getPkgManager()
|
|
26
34
|
|
|
@@ -40,11 +48,6 @@ export async function createPlatformaticRuntime (_args) {
|
|
|
40
48
|
process.exit(1)
|
|
41
49
|
}
|
|
42
50
|
|
|
43
|
-
toAsk.push(getRunPackageManagerInstall(pkgManager))
|
|
44
|
-
// const { runPackageManagerInstall } = await inquirer.prompt([
|
|
45
|
-
// getRunPackageManagerInstall(pkgManager)
|
|
46
|
-
// ])
|
|
47
|
-
|
|
48
51
|
toAsk.push({
|
|
49
52
|
type: 'list',
|
|
50
53
|
name: 'staticWorkspaceGitHubAction',
|
|
@@ -62,7 +65,6 @@ export async function createPlatformaticRuntime (_args) {
|
|
|
62
65
|
|
|
63
66
|
toAsk.push(getInitGitRepository())
|
|
64
67
|
const {
|
|
65
|
-
runPackageManagerInstall,
|
|
66
68
|
staticWorkspaceGitHubAction,
|
|
67
69
|
dynamicWorkspaceGitHubAction,
|
|
68
70
|
initGitRepository
|
|
@@ -99,7 +101,7 @@ export async function createPlatformaticRuntime (_args) {
|
|
|
99
101
|
if (addTypescriptDevDep) {
|
|
100
102
|
const typescriptVersion = await getDependencyVersion('typescript')
|
|
101
103
|
devDependencies.typescript = `^${typescriptVersion}`
|
|
102
|
-
devDependencies['@types/node'] = '
|
|
104
|
+
devDependencies['@types/node'] = await getDependencyVersion('@types/node')
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
// Create the package.json, notes that we don't have the option for TS (yet) so we don't generate
|
|
@@ -138,7 +140,7 @@ export async function createPlatformaticRuntime (_args) {
|
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
await createRuntime(params, logger, projectDir, version)
|
|
141
|
-
if (
|
|
143
|
+
if (args.install) {
|
|
142
144
|
const spinner = ora('Installing dependencies...').start()
|
|
143
145
|
await execa(pkgManager, ['install'], { cwd: projectDir })
|
|
144
146
|
spinner.succeed()
|
|
@@ -11,7 +11,7 @@ import { execa } from 'execa'
|
|
|
11
11
|
import ora from 'ora'
|
|
12
12
|
import createService from './create-service.mjs'
|
|
13
13
|
import askDir from '../ask-dir.mjs'
|
|
14
|
-
import {
|
|
14
|
+
import { getUseTypescript, getPort, getInitGitRepository } from '../cli-options.mjs'
|
|
15
15
|
import { createReadme } from '../create-readme.mjs'
|
|
16
16
|
|
|
17
17
|
const createPlatformaticService = async (_args, opts = {}) => {
|
|
@@ -22,12 +22,14 @@ const createPlatformaticService = async (_args, opts = {}) => {
|
|
|
22
22
|
|
|
23
23
|
const args = parseArgs(_args, {
|
|
24
24
|
default: {
|
|
25
|
-
hostname: '127.0.0.1'
|
|
25
|
+
hostname: '127.0.0.1',
|
|
26
|
+
install: true
|
|
26
27
|
},
|
|
27
28
|
alias: {
|
|
28
29
|
h: 'hostname',
|
|
29
30
|
p: 'port'
|
|
30
|
-
}
|
|
31
|
+
},
|
|
32
|
+
boolean: ['install']
|
|
31
33
|
})
|
|
32
34
|
|
|
33
35
|
const version = await getVersion()
|
|
@@ -43,10 +45,6 @@ const createPlatformaticService = async (_args, opts = {}) => {
|
|
|
43
45
|
toAsk.push(getPort(args.port))
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
if (!opts.skipPackageJson) {
|
|
47
|
-
toAsk.unshift(getRunPackageManagerInstall(pkgManager))
|
|
48
|
-
}
|
|
49
|
-
|
|
50
48
|
if (!opts.skipGitHubActions) {
|
|
51
49
|
toAsk.push({
|
|
52
50
|
type: 'list',
|
|
@@ -67,7 +65,6 @@ const createPlatformaticService = async (_args, opts = {}) => {
|
|
|
67
65
|
toAsk.push(getInitGitRepository())
|
|
68
66
|
}
|
|
69
67
|
const {
|
|
70
|
-
runPackageManagerInstall,
|
|
71
68
|
useTypescript,
|
|
72
69
|
port,
|
|
73
70
|
staticWorkspaceGitHubAction,
|
|
@@ -106,7 +103,7 @@ const createPlatformaticService = async (_args, opts = {}) => {
|
|
|
106
103
|
}
|
|
107
104
|
await createReadme(logger, projectDir, 'service')
|
|
108
105
|
|
|
109
|
-
if (
|
|
106
|
+
if (args.install && !opts.skipPackageJson) {
|
|
110
107
|
const spinner = ora('Installing dependencies...').start()
|
|
111
108
|
await execa(pkgManager, ['install'], { cwd: projectDir })
|
|
112
109
|
spinner.succeed()
|
|
@@ -99,7 +99,6 @@ async function createService (params, logger, currentDir = process.cwd(), versio
|
|
|
99
99
|
const env = generateEnv(isRuntimeContext, hostname, port, typescript, envPrefix)
|
|
100
100
|
await appendFile(join(currentDir, '.env'), env)
|
|
101
101
|
await writeFile(join(currentDir, '.env.sample'), env)
|
|
102
|
-
logger.info('Environment file .env found, appending new environment variables to existing .env file.')
|
|
103
102
|
|
|
104
103
|
if (typescript === true) {
|
|
105
104
|
const tsConfigFileName = join(currentDir, 'tsconfig.json')
|
package/src/utils.mjs
CHANGED
|
@@ -4,10 +4,13 @@ import { resolve, join, dirname } from 'path'
|
|
|
4
4
|
import { createRequire } from 'module'
|
|
5
5
|
import semver from 'semver'
|
|
6
6
|
import * as desm from 'desm'
|
|
7
|
+
import * as url from 'url'
|
|
8
|
+
|
|
7
9
|
import ConfigManager from '@platformatic/config'
|
|
8
10
|
|
|
9
11
|
export const sleep = ms => new Promise((resolve) => setTimeout(resolve, ms))
|
|
10
12
|
export const randomBetween = (min, max) => Math.floor(Math.random() * (max - min + 1) + min)
|
|
13
|
+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
|
|
11
14
|
|
|
12
15
|
export async function isFileAccessible (filename, directory) {
|
|
13
16
|
try {
|
|
@@ -73,21 +76,44 @@ export const findRuntimeConfigFile = async (directory) => (ConfigManager.findCon
|
|
|
73
76
|
* @returns string
|
|
74
77
|
*/
|
|
75
78
|
export const getDependencyVersion = async (dependencyName) => {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
|
|
79
|
+
const rootPackageJson = join(__dirname, '..', 'package.json')
|
|
80
|
+
const packageJsonContents = JSON.parse(await readFile(rootPackageJson, 'utf8'))
|
|
81
|
+
const dependencies = packageJsonContents.dependencies
|
|
82
|
+
const devDependencies = packageJsonContents.devDependencies
|
|
83
|
+
const regexp = /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/
|
|
84
|
+
if (dependencies[dependencyName]) {
|
|
85
|
+
const match = dependencies[dependencyName].match(regexp)
|
|
86
|
+
if (!match) {
|
|
87
|
+
return await resolveWorkspaceDependency(dependencyName)
|
|
88
|
+
}
|
|
89
|
+
return match[0]
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (devDependencies[dependencyName]) {
|
|
93
|
+
const match = devDependencies[dependencyName].match(regexp)
|
|
94
|
+
if (!match) {
|
|
95
|
+
return await resolveWorkspaceDependency(dependencyName)
|
|
96
|
+
}
|
|
97
|
+
return match[0]
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function resolveWorkspaceDependency (dependencyName) {
|
|
101
|
+
const require = createRequire(import.meta.url)
|
|
102
|
+
let dependencyPath = dirname(require.resolve(dependencyName))
|
|
103
|
+
// some deps are resolved not at their root level
|
|
104
|
+
// for instance 'typescript' will be risolved in its own ./lib directory
|
|
105
|
+
// next loop is to find the nearest parent directory that contains a package.json file
|
|
106
|
+
while (!await isFileAccessible(join(dependencyPath, 'package.json'))) {
|
|
107
|
+
dependencyPath = join(dependencyPath, '..')
|
|
108
|
+
if (dependencyPath === '/') {
|
|
109
|
+
throw new Error(`Cannot find package.json for ${dependencyName}`)
|
|
110
|
+
}
|
|
85
111
|
}
|
|
112
|
+
const pathToPackageJson = join(dependencyPath, 'package.json')
|
|
113
|
+
const packageJsonFile = await readFile(pathToPackageJson, 'utf-8')
|
|
114
|
+
const packageJson = JSON.parse(packageJsonFile)
|
|
115
|
+
return packageJson.version
|
|
86
116
|
}
|
|
87
|
-
const pathToPackageJson = join(dependencyPath, 'package.json')
|
|
88
|
-
const packageJsonFile = await readFile(pathToPackageJson, 'utf-8')
|
|
89
|
-
const packageJson = JSON.parse(packageJsonFile)
|
|
90
|
-
return packageJson.version
|
|
91
117
|
}
|
|
92
118
|
|
|
93
119
|
export const minimumSupportedNodeVersions = ['18.8.0', '20.6.0']
|
package/.taprc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
jobs: 1
|