create-platformatic 0.11.0 → 0.12.1
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/README.md +2 -2
- package/create-platformatic.mjs +3 -0
- package/package.json +12 -12
- package/src/create-package-json.mjs +8 -5
- package/src/db/create-db-cli.mjs +13 -11
- package/src/ghaction.mjs +10 -6
- package/src/service/create-service-cli.mjs +19 -4
- package/src/service/create-service.mjs +1 -0
- package/test/create-package-json.test.mjs +18 -3
- package/test/ghaction.test.mjs +30 -3
package/README.md
CHANGED
package/create-platformatic.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-platformatic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "Create platformatic-db interactive tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,32 +14,32 @@
|
|
|
14
14
|
},
|
|
15
15
|
"author": "Marco Piraccini <marco.piraccini@gmail.com>",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"chalk": "^5.
|
|
18
|
-
"commist": "^3.
|
|
19
|
-
"desm": "^1.
|
|
17
|
+
"chalk": "^5.2.0",
|
|
18
|
+
"commist": "^3.2.0",
|
|
19
|
+
"desm": "^1.3.0",
|
|
20
20
|
"es-main": "^1.2.0",
|
|
21
21
|
"execa": "^6.1.0",
|
|
22
|
-
"fastify": "^4.
|
|
23
|
-
"help-me": "^4.
|
|
22
|
+
"fastify": "^4.10.2",
|
|
23
|
+
"help-me": "^4.2.0",
|
|
24
24
|
"inquirer": "^9.1.4",
|
|
25
25
|
"log-update": "^5.0.1",
|
|
26
26
|
"minimist": "^1.2.7",
|
|
27
27
|
"mkdirp": "^1.0.4",
|
|
28
28
|
"ora": "^6.1.2",
|
|
29
|
-
"pino": "^8.
|
|
30
|
-
"pino-pretty": "^9.
|
|
29
|
+
"pino": "^8.8.0",
|
|
30
|
+
"pino-pretty": "^9.1.1",
|
|
31
31
|
"pupa": "^3.1.0",
|
|
32
|
-
"undici": "^5.
|
|
32
|
+
"undici": "^5.14.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"c8": "^7.12.0",
|
|
36
|
-
"dotenv": "^16.0.
|
|
36
|
+
"dotenv": "^16.0.3",
|
|
37
37
|
"esmock": "^2.1.0",
|
|
38
38
|
"semver": "^7.3.8",
|
|
39
39
|
"snazzy": "^9.0.0",
|
|
40
40
|
"standard": "^17.0.0",
|
|
41
|
-
"tap": "^16.
|
|
42
|
-
"yaml": "^2.1.
|
|
41
|
+
"tap": "^16.3.2",
|
|
42
|
+
"yaml": "^2.1.3"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"test": "standard | snazzy && NODE_OPTIONS=--loader=esmock c8 --100 tap --no-coverage test/*test.mjs test/*/*test.mjs"
|
|
@@ -3,10 +3,13 @@ import { isFileAccessible } from './utils.mjs'
|
|
|
3
3
|
import { writeFile } from 'fs/promises'
|
|
4
4
|
import { join } from 'node:path'
|
|
5
5
|
|
|
6
|
-
const packageJsonTemplate = `\
|
|
6
|
+
const packageJsonTemplate = (addTSBuild = false) => (`\
|
|
7
7
|
{
|
|
8
8
|
"scripts": {
|
|
9
|
-
"start": "platformatic {type} start"
|
|
9
|
+
"start": "platformatic {type} start"${addTSBuild
|
|
10
|
+
? `,
|
|
11
|
+
"build": "npx tsc"`
|
|
12
|
+
: ''}
|
|
10
13
|
},
|
|
11
14
|
"devDependencies": {
|
|
12
15
|
"fastify": "^{fastifyVersion}"
|
|
@@ -17,13 +20,13 @@ const packageJsonTemplate = `\
|
|
|
17
20
|
"engines": {
|
|
18
21
|
"node": "^16.17.0 || ^18.8.0 || >=19"
|
|
19
22
|
}
|
|
20
|
-
}`
|
|
23
|
+
}`)
|
|
21
24
|
|
|
22
|
-
export const createPackageJson = async (type, platVersion, fastifyVersion, logger, dir =
|
|
25
|
+
export const createPackageJson = async (type, platVersion, fastifyVersion, logger, dir, addTSBuild = false) => {
|
|
23
26
|
const packageJsonFileName = join(dir, 'package.json')
|
|
24
27
|
const isPackageJsonExists = await isFileAccessible(packageJsonFileName)
|
|
25
28
|
if (!isPackageJsonExists) {
|
|
26
|
-
const packageJson = pupa(packageJsonTemplate, { platVersion, fastifyVersion, type })
|
|
29
|
+
const packageJson = pupa(packageJsonTemplate(addTSBuild), { platVersion, fastifyVersion, type })
|
|
27
30
|
await writeFile(packageJsonFileName, packageJson)
|
|
28
31
|
logger.debug(`${packageJsonFileName} successfully created.`)
|
|
29
32
|
} else {
|
package/src/db/create-db-cli.mjs
CHANGED
|
@@ -28,13 +28,8 @@ export const createReadme = async (logger, dir = '.') => {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
translateTime: 'SYS:HH:MM:ss',
|
|
34
|
-
ignore: 'hostname,pid'
|
|
35
|
-
}))
|
|
36
|
-
|
|
37
|
-
const args = parseArgs(_args, {
|
|
31
|
+
export const parseDBArgs = (_args) => {
|
|
32
|
+
return parseArgs(_args, {
|
|
38
33
|
default: {
|
|
39
34
|
hostname: '127.0.0.1',
|
|
40
35
|
port: 3042,
|
|
@@ -55,10 +50,17 @@ const createPlatformaticDB = async (_args) => {
|
|
|
55
50
|
},
|
|
56
51
|
boolean: ['plugin', 'types', 'typescript']
|
|
57
52
|
})
|
|
53
|
+
}
|
|
58
54
|
|
|
55
|
+
const createPlatformaticDB = async (_args) => {
|
|
56
|
+
const logger = pino(pretty({
|
|
57
|
+
translateTime: 'SYS:HH:MM:ss',
|
|
58
|
+
ignore: 'hostname,pid'
|
|
59
|
+
}))
|
|
60
|
+
|
|
61
|
+
const args = parseDBArgs(_args)
|
|
59
62
|
const version = await getVersion()
|
|
60
63
|
const pkgManager = getPkgManager()
|
|
61
|
-
|
|
62
64
|
const projectDir = await askProjectDir(logger, '.')
|
|
63
65
|
|
|
64
66
|
const wizardOptions = await inquirer.prompt([{
|
|
@@ -104,7 +106,7 @@ const createPlatformaticDB = async (_args) => {
|
|
|
104
106
|
const fastifyVersion = await getDependencyVersion('fastify')
|
|
105
107
|
|
|
106
108
|
// Create the package.json, .gitignore, readme
|
|
107
|
-
await createPackageJson('db', version, fastifyVersion, logger, projectDir)
|
|
109
|
+
await createPackageJson('db', version, fastifyVersion, logger, projectDir, useTypescript)
|
|
108
110
|
await createGitignore(logger, projectDir)
|
|
109
111
|
await createReadme(logger, projectDir)
|
|
110
112
|
|
|
@@ -161,12 +163,12 @@ const createPlatformaticDB = async (_args) => {
|
|
|
161
163
|
await execaNode('./node_modules/@platformatic/db/db.mjs', ['schema', 'config'], { cwd: projectDir })
|
|
162
164
|
logger.info('Configuration schema successfully created.')
|
|
163
165
|
}
|
|
164
|
-
await askCreateGHAction(logger, env, 'db')
|
|
166
|
+
await askCreateGHAction(logger, env, 'db', useTypescript)
|
|
165
167
|
|
|
166
168
|
if (!runPackageManagerInstall) {
|
|
167
169
|
logger.warn(`You must run the following commands in the project folder to complete the setup:
|
|
168
170
|
- ${pkgManager} install
|
|
169
|
-
- npx platformatic db schema config
|
|
171
|
+
- npx platformatic db schema config
|
|
170
172
|
`)
|
|
171
173
|
}
|
|
172
174
|
}
|
package/src/ghaction.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import inquirer from 'inquirer'
|
|
|
4
4
|
import { isFileAccessible } from './utils.mjs'
|
|
5
5
|
import { writeFile } from 'fs/promises'
|
|
6
6
|
|
|
7
|
-
export const ghTemplate = (env, type) => {
|
|
7
|
+
export const ghTemplate = (env, type, buildTS = false) => {
|
|
8
8
|
const envAsStr = Object.keys(env).reduce((acc, key) => {
|
|
9
9
|
acc += ` ${key}: ${env[key]} \n`
|
|
10
10
|
return acc
|
|
@@ -24,7 +24,11 @@ jobs:
|
|
|
24
24
|
- name: Checkout application project repository
|
|
25
25
|
uses: actions/checkout@v3
|
|
26
26
|
- name: npm install --omit=dev
|
|
27
|
-
run: npm install --omit=dev
|
|
27
|
+
run: npm install --omit=dev${buildTS
|
|
28
|
+
? `
|
|
29
|
+
- name: Build project
|
|
30
|
+
run: npm run build`
|
|
31
|
+
: ''}
|
|
28
32
|
- name: Deploy project
|
|
29
33
|
uses: platformatic/onestep@latest
|
|
30
34
|
with:
|
|
@@ -36,13 +40,13 @@ ${envAsStr}
|
|
|
36
40
|
`
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
export const createGHAction = async (logger, env, type, projectDir) => {
|
|
43
|
+
export const createGHAction = async (logger, env, type, projectDir, buildTS) => {
|
|
40
44
|
const ghActionFileName = 'platformatic-deploy.yml'
|
|
41
45
|
const ghActionFilePath = join(projectDir, '.github', 'workflows', ghActionFileName)
|
|
42
46
|
const isGithubActionExists = await isFileAccessible(ghActionFilePath)
|
|
43
47
|
if (!isGithubActionExists) {
|
|
44
48
|
await mkdirp(join(projectDir, '.github', 'workflows'))
|
|
45
|
-
await writeFile(ghActionFilePath, ghTemplate(env, type))
|
|
49
|
+
await writeFile(ghActionFilePath, ghTemplate(env, type, buildTS))
|
|
46
50
|
logger.info('Github action successfully created, please add PLATFORMATIC_API_KEY as repository secret.')
|
|
47
51
|
const isGitDir = await isFileAccessible('.git', projectDir)
|
|
48
52
|
if (!isGitDir) {
|
|
@@ -54,7 +58,7 @@ export const createGHAction = async (logger, env, type, projectDir) => {
|
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
/* c8 ignore next 12 */
|
|
57
|
-
export const askCreateGHAction = async (logger, env, type, projectDir = process.cwd()) => {
|
|
61
|
+
export const askCreateGHAction = async (logger, env, type, buildTS, projectDir = process.cwd()) => {
|
|
58
62
|
const { githubAction } = await inquirer.prompt([{
|
|
59
63
|
type: 'list',
|
|
60
64
|
name: 'githubAction',
|
|
@@ -63,6 +67,6 @@ export const askCreateGHAction = async (logger, env, type, projectDir = process.
|
|
|
63
67
|
choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
|
|
64
68
|
}])
|
|
65
69
|
if (githubAction) {
|
|
66
|
-
await createGHAction(logger, env, type, projectDir)
|
|
70
|
+
await createGHAction(logger, env, type, projectDir, buildTS)
|
|
67
71
|
}
|
|
68
72
|
}
|
|
@@ -9,7 +9,7 @@ import inquirer from 'inquirer'
|
|
|
9
9
|
import { readFile, writeFile } from 'fs/promises'
|
|
10
10
|
import pino from 'pino'
|
|
11
11
|
import pretty from 'pino-pretty'
|
|
12
|
-
import { execa } from 'execa'
|
|
12
|
+
import { execa, execaNode } from 'execa'
|
|
13
13
|
import ora from 'ora'
|
|
14
14
|
import createService from './create-service.mjs'
|
|
15
15
|
import askProjectDir from '../ask-project-dir.mjs'
|
|
@@ -63,8 +63,9 @@ const createPlatformaticService = async (_args) => {
|
|
|
63
63
|
|
|
64
64
|
const fastifyVersion = await getDependencyVersion('fastify')
|
|
65
65
|
|
|
66
|
-
// Create the package.json,
|
|
67
|
-
|
|
66
|
+
// Create the package.json, notes that we don't have the option for TS (yet) so we don't generate
|
|
67
|
+
// the package.json with the TS build
|
|
68
|
+
await createPackageJson('service', version, fastifyVersion, logger, projectDir, false)
|
|
68
69
|
await createGitignore(logger, projectDir)
|
|
69
70
|
await createReadme(logger, projectDir)
|
|
70
71
|
|
|
@@ -80,9 +81,23 @@ const createPlatformaticService = async (_args) => {
|
|
|
80
81
|
const spinner = ora('Installing dependencies...').start()
|
|
81
82
|
await execa(pkgManager, ['install'], { cwd: projectDir })
|
|
82
83
|
spinner.succeed('...done!')
|
|
84
|
+
try {
|
|
85
|
+
await execaNode('./node_modules/@platformatic/service/service.mjs', [], { cwd: projectDir })
|
|
86
|
+
} catch (err) {
|
|
87
|
+
console.log(err)
|
|
88
|
+
}
|
|
89
|
+
logger.info('Configuration schema successfully created.')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!runPackageManagerInstall) {
|
|
93
|
+
logger.warn(`You must run the following commands in the project folder to complete the setup:
|
|
94
|
+
- ${pkgManager} install
|
|
95
|
+
- npx platformatic service schema config
|
|
96
|
+
`)
|
|
83
97
|
}
|
|
84
98
|
|
|
85
|
-
|
|
99
|
+
// We don't have the option for TS (yet) so we don't run build on TS
|
|
100
|
+
await askCreateGHAction(logger, env, 'service', false)
|
|
86
101
|
}
|
|
87
102
|
|
|
88
103
|
export default createPlatformaticService
|
|
@@ -23,12 +23,13 @@ afterEach(() => {
|
|
|
23
23
|
test('creates package.json file for db project', async ({ end, equal }) => {
|
|
24
24
|
const version = '1.2.3'
|
|
25
25
|
const fastifyVersion = '4.5.6'
|
|
26
|
-
await createPackageJson('db', version, fastifyVersion, fakeLogger, tmpDir)
|
|
26
|
+
await createPackageJson('db', version, fastifyVersion, fakeLogger, tmpDir, false)
|
|
27
27
|
equal(log, `${tmpDir}/package.json successfully created.`)
|
|
28
28
|
const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
|
|
29
29
|
equal(accessible, true)
|
|
30
30
|
const packageJson = JSON.parse(readFileSync(join(tmpDir, 'package.json')))
|
|
31
31
|
equal(packageJson.scripts.start, 'platformatic db start')
|
|
32
|
+
equal(packageJson.scripts.build, undefined)
|
|
32
33
|
equal(packageJson.dependencies.platformatic, `^${version}`)
|
|
33
34
|
equal(packageJson.devDependencies.fastify, `^${fastifyVersion}`)
|
|
34
35
|
})
|
|
@@ -36,7 +37,7 @@ test('creates package.json file for db project', async ({ end, equal }) => {
|
|
|
36
37
|
test('creates package.json file for service project', async ({ end, equal }) => {
|
|
37
38
|
const version = '1.2.3'
|
|
38
39
|
const fastifyVersion = '4.5.6'
|
|
39
|
-
await createPackageJson('service', version, fastifyVersion, fakeLogger, tmpDir)
|
|
40
|
+
await createPackageJson('service', version, fastifyVersion, fakeLogger, tmpDir, false)
|
|
40
41
|
equal(log, `${tmpDir}/package.json successfully created.`)
|
|
41
42
|
const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
|
|
42
43
|
equal(accessible, true)
|
|
@@ -51,6 +52,20 @@ test('do not create package.json file because already present', async ({ end, eq
|
|
|
51
52
|
const fastifyVersion = '4.5.6'
|
|
52
53
|
const packagejson = join(tmpDir, 'package.json')
|
|
53
54
|
writeFileSync(packagejson, 'TEST')
|
|
54
|
-
await createPackageJson('db', version, fastifyVersion, fakeLogger, tmpDir)
|
|
55
|
+
await createPackageJson('db', version, fastifyVersion, fakeLogger, tmpDir, false)
|
|
55
56
|
equal(log, `${tmpDir}/package.json found, skipping creation of package.json file.`)
|
|
56
57
|
})
|
|
58
|
+
|
|
59
|
+
test('creates package.json file with TD build', async ({ end, equal }) => {
|
|
60
|
+
const version = '1.2.3'
|
|
61
|
+
const fastifyVersion = '4.5.6'
|
|
62
|
+
await createPackageJson('db', version, fastifyVersion, fakeLogger, tmpDir, true)
|
|
63
|
+
equal(log, `${tmpDir}/package.json successfully created.`)
|
|
64
|
+
const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
|
|
65
|
+
equal(accessible, true)
|
|
66
|
+
const packageJson = JSON.parse(readFileSync(join(tmpDir, 'package.json')))
|
|
67
|
+
equal(packageJson.scripts.start, 'platformatic db start')
|
|
68
|
+
equal(packageJson.scripts.build, 'npx tsc')
|
|
69
|
+
equal(packageJson.dependencies.platformatic, `^${version}`)
|
|
70
|
+
equal(packageJson.devDependencies.fastify, `^${fastifyVersion}`)
|
|
71
|
+
})
|
package/test/ghaction.test.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { test, beforeEach, afterEach } from 'tap'
|
|
4
|
-
import { mkdtemp, rmdir, writeFile } from 'fs/promises'
|
|
4
|
+
import { mkdtemp, rmdir, writeFile, readFile } from 'fs/promises'
|
|
5
5
|
import mkdirp from 'mkdirp'
|
|
6
6
|
import { join } from 'path'
|
|
7
7
|
import { tmpdir } from 'os'
|
|
8
8
|
import { isFileAccessible } from '../src/utils.mjs'
|
|
9
9
|
import { createGHAction } from '../src/ghaction.mjs'
|
|
10
|
+
import { parse } from 'yaml'
|
|
10
11
|
|
|
11
12
|
let log = []
|
|
12
13
|
let tmpDir
|
|
@@ -25,15 +26,41 @@ afterEach(async () => {
|
|
|
25
26
|
})
|
|
26
27
|
|
|
27
28
|
const env = {
|
|
28
|
-
DATABASE_URL: '
|
|
29
|
+
DATABASE_URL: 'mydbconnectionstring',
|
|
29
30
|
PLT_SERVER_LOGGER_LEVEL: 'info'
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
test('creates gh action', async ({ end, equal }) => {
|
|
33
|
-
await createGHAction(fakeLogger, env, 'db', tmpDir)
|
|
34
|
+
await createGHAction(fakeLogger, env, 'db', tmpDir, false)
|
|
35
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_API_KEY as repository secret.')
|
|
36
|
+
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-deploy.yml'))
|
|
37
|
+
equal(accessible, true)
|
|
38
|
+
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-deploy.yml'), 'utf8')
|
|
39
|
+
const ghAction = parse(ghFile)
|
|
40
|
+
const steps = ghAction.jobs.build_and_deploy.steps
|
|
41
|
+
equal(steps.length, 3)
|
|
42
|
+
equal(steps[0].name, 'Checkout application project repository')
|
|
43
|
+
equal(steps[1].name, 'npm install --omit=dev')
|
|
44
|
+
equal(steps[2].name, 'Deploy project')
|
|
45
|
+
equal(steps[2].env.DATABASE_URL, 'mydbconnectionstring')
|
|
46
|
+
equal(steps[2].env.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('creates gh action with TS build step', async ({ end, equal }) => {
|
|
50
|
+
await createGHAction(fakeLogger, env, 'db', tmpDir, true)
|
|
34
51
|
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_API_KEY as repository secret.')
|
|
35
52
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-deploy.yml'))
|
|
36
53
|
equal(accessible, true)
|
|
54
|
+
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-deploy.yml'), 'utf8')
|
|
55
|
+
const ghAction = parse(ghFile)
|
|
56
|
+
const steps = ghAction.jobs.build_and_deploy.steps
|
|
57
|
+
equal(steps.length, 4)
|
|
58
|
+
equal(steps[0].name, 'Checkout application project repository')
|
|
59
|
+
equal(steps[1].name, 'npm install --omit=dev')
|
|
60
|
+
equal(steps[2].name, 'Build project')
|
|
61
|
+
equal(steps[3].name, 'Deploy project')
|
|
62
|
+
equal(steps[3].env.DATABASE_URL, 'mydbconnectionstring')
|
|
63
|
+
equal(steps[3].env.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
37
64
|
})
|
|
38
65
|
|
|
39
66
|
test('do not create gitignore file because already present', async ({ end, equal }) => {
|