create-platformatic 0.29.0 → 0.30.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/create-platformatic.mjs +2 -0
- package/package.json +5 -4
- package/src/get-tsconfig.mjs +2 -1
- package/src/ghaction.mjs +44 -11
- package/test/ghaction-dynamic.test.mjs +14 -10
- package/test/ghaction-static.test.mjs +14 -10
package/create-platformatic.mjs
CHANGED
|
@@ -36,4 +36,6 @@ export {
|
|
|
36
36
|
createStaticWorkspaceGHAction,
|
|
37
37
|
createDynamicWorkspaceGHAction
|
|
38
38
|
} from './src/ghaction.mjs'
|
|
39
|
+
|
|
39
40
|
export { createGitignore, createPackageJson, getDependencyVersion, getVersion } from './src/index.mjs'
|
|
41
|
+
export { default as createService } from './src/service/create-service.mjs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-platformatic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.1",
|
|
4
4
|
"description": "Create platformatic-db interactive tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"boring-name-generator": "^1.0.3",
|
|
19
19
|
"chalk": "^5.2.0",
|
|
20
|
+
"columnify": "^1.6.0",
|
|
20
21
|
"commist": "^3.2.0",
|
|
21
22
|
"desm": "^1.3.0",
|
|
22
23
|
"es-main": "^1.2.0",
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
"semver": "^7.5.1",
|
|
34
35
|
"undici": "^5.22.1",
|
|
35
36
|
"which": "^3.0.1",
|
|
36
|
-
"@platformatic/config": "0.
|
|
37
|
+
"@platformatic/config": "0.30.1"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"ajv": "^8.12.0",
|
|
@@ -45,8 +46,8 @@
|
|
|
45
46
|
"standard": "^17.1.0",
|
|
46
47
|
"tap": "^16.3.6",
|
|
47
48
|
"yaml": "^2.3.1",
|
|
48
|
-
"@platformatic/db": "0.
|
|
49
|
-
"@platformatic/service": "0.
|
|
49
|
+
"@platformatic/db": "0.30.1",
|
|
50
|
+
"@platformatic/service": "0.30.1"
|
|
50
51
|
},
|
|
51
52
|
"scripts": {
|
|
52
53
|
"test": "standard | snazzy && cross-env NODE_OPTIONS=\"--loader=esmock --no-warnings\" c8 tap --no-coverage test/*test.mjs test/*/*test.mjs",
|
package/src/get-tsconfig.mjs
CHANGED
|
@@ -3,10 +3,11 @@ export function getTsConfig (outDir) {
|
|
|
3
3
|
compilerOptions: {
|
|
4
4
|
module: 'commonjs',
|
|
5
5
|
esModuleInterop: true,
|
|
6
|
-
target: '
|
|
6
|
+
target: 'es2020',
|
|
7
7
|
sourceMap: true,
|
|
8
8
|
pretty: true,
|
|
9
9
|
noEmitOnError: true,
|
|
10
|
+
incremental: true,
|
|
10
11
|
outDir
|
|
11
12
|
},
|
|
12
13
|
watchOptions: {
|
package/src/ghaction.mjs
CHANGED
|
@@ -2,12 +2,36 @@ import { join } from 'path'
|
|
|
2
2
|
import inquirer from 'inquirer'
|
|
3
3
|
import { isFileAccessible } from './utils.mjs'
|
|
4
4
|
import { writeFile, mkdir } from 'fs/promises'
|
|
5
|
+
import columnify from 'columnify'
|
|
6
|
+
function envAsString (env) {
|
|
7
|
+
return Object.keys(env).reduce((acc, key) => {
|
|
8
|
+
if (key === 'DATABASE_URL') {
|
|
9
|
+
acc += ` ${key}: \${{ secrets.DATABASE_URL }}\n`
|
|
10
|
+
} else {
|
|
11
|
+
acc += ` ${key}: ${env[key]} \n`
|
|
12
|
+
}
|
|
5
13
|
|
|
6
|
-
export const dynamicWorkspaceGHTemplate = (env, config, buildTS = false) => {
|
|
7
|
-
const envAsStr = Object.keys(env).reduce((acc, key) => {
|
|
8
|
-
acc += ` ${key}: ${env[key]} \n`
|
|
9
14
|
return acc
|
|
10
15
|
}, '')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function formatSecretsToAdd (secrets) {
|
|
19
|
+
const output = columnify(secrets, {
|
|
20
|
+
showHeaders: false,
|
|
21
|
+
columnSplitter: ': ',
|
|
22
|
+
config: {
|
|
23
|
+
key: {
|
|
24
|
+
align: 'right'
|
|
25
|
+
},
|
|
26
|
+
value: {
|
|
27
|
+
align: 'left'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
return output
|
|
32
|
+
}
|
|
33
|
+
export const dynamicWorkspaceGHTemplate = (env, config, buildTS = false) => {
|
|
34
|
+
const envString = envAsString(env)
|
|
11
35
|
|
|
12
36
|
return `name: Deploy Platformatic application to the cloud
|
|
13
37
|
on:
|
|
@@ -39,15 +63,12 @@ jobs:
|
|
|
39
63
|
platformatic_workspace_key: \${{ secrets.PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY }}
|
|
40
64
|
platformatic_config_path: ${config}
|
|
41
65
|
env:
|
|
42
|
-
${
|
|
66
|
+
${envString}
|
|
43
67
|
`
|
|
44
68
|
}
|
|
45
69
|
|
|
46
70
|
export const staticWorkspaceGHTemplate = (env, config, buildTS = false) => {
|
|
47
|
-
const
|
|
48
|
-
acc += ` ${key}: ${env[key]} \n`
|
|
49
|
-
return acc
|
|
50
|
-
}, '')
|
|
71
|
+
const envString = envAsString(env)
|
|
51
72
|
|
|
52
73
|
return `name: Deploy Platformatic application to the cloud
|
|
53
74
|
on:
|
|
@@ -80,7 +101,7 @@ jobs:
|
|
|
80
101
|
platformatic_workspace_key: \${{ secrets.PLATFORMATIC_STATIC_WORKSPACE_API_KEY }}
|
|
81
102
|
platformatic_config_path: ${config}
|
|
82
103
|
env:
|
|
83
|
-
${
|
|
104
|
+
${envString}
|
|
84
105
|
`
|
|
85
106
|
}
|
|
86
107
|
|
|
@@ -91,7 +112,13 @@ export const createDynamicWorkspaceGHAction = async (logger, env, config, projec
|
|
|
91
112
|
if (!isGithubActionExists) {
|
|
92
113
|
await mkdir(join(projectDir, '.github', 'workflows'), { recursive: true })
|
|
93
114
|
await writeFile(ghActionFilePath, dynamicWorkspaceGHTemplate(env, config, buildTS))
|
|
94
|
-
logger.info('Github action successfully created, please add
|
|
115
|
+
logger.info('Github action successfully created, please add the following secrets as repository secrets: ')
|
|
116
|
+
const secretsString = formatSecretsToAdd({
|
|
117
|
+
PLATFORMATIC_DYNAMIC_WORKSPACE_ID: 'your workspace id',
|
|
118
|
+
PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY: 'your workspace API key',
|
|
119
|
+
DATABASE_URL: env.DATABASE_URL
|
|
120
|
+
})
|
|
121
|
+
logger.info(`\n ${secretsString}`)
|
|
95
122
|
const isGitDir = await isFileAccessible('.git', projectDir)
|
|
96
123
|
if (!isGitDir) {
|
|
97
124
|
logger.warn('No git repository found. The Github action won\'t be triggered.')
|
|
@@ -126,7 +153,13 @@ export const createStaticWorkspaceGHAction = async (logger, env, config, project
|
|
|
126
153
|
if (!isGithubActionExists) {
|
|
127
154
|
await mkdir(join(projectDir, '.github', 'workflows'), { recursive: true })
|
|
128
155
|
await writeFile(ghActionFilePath, staticWorkspaceGHTemplate(env, config, buildTS))
|
|
129
|
-
logger.info('Github action successfully created, please add
|
|
156
|
+
logger.info('Github action successfully created, please add the following secrets as repository secrets: ')
|
|
157
|
+
const secretsString = formatSecretsToAdd({
|
|
158
|
+
PLATFORMATIC_STATIC_WORKSPACE_ID: 'your workspace id',
|
|
159
|
+
PLATFORMATIC_STATIC_WORKSPACE_API_KEY: 'your workspace API key',
|
|
160
|
+
DATABASE_URL: env.DATABASE_URL
|
|
161
|
+
})
|
|
162
|
+
logger.info(`\n ${secretsString}`)
|
|
130
163
|
const isGitDir = await isFileAccessible('.git', projectDir)
|
|
131
164
|
if (!isGitDir) {
|
|
132
165
|
logger.warn('No git repository found. The Github action won\'t be triggered.')
|
|
@@ -29,9 +29,9 @@ const env = {
|
|
|
29
29
|
PLT_SERVER_LOGGER_LEVEL: 'info'
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
test('creates gh action', async ({
|
|
32
|
+
test('creates gh action', async ({ equal, match }) => {
|
|
33
33
|
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, false)
|
|
34
|
-
equal(log[0], 'Github action successfully created, please add
|
|
34
|
+
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
35
35
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
36
36
|
equal(accessible, true)
|
|
37
37
|
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'), 'utf8')
|
|
@@ -41,16 +41,16 @@ test('creates gh action', async ({ end, equal }) => {
|
|
|
41
41
|
equal(steps[0].name, 'Checkout application project repository')
|
|
42
42
|
equal(steps[1].name, 'npm install --omit=dev')
|
|
43
43
|
equal(steps[2].name, 'Deploy project')
|
|
44
|
-
|
|
44
|
+
match(steps[2].env.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
|
|
45
45
|
equal(steps[2].env.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
46
46
|
|
|
47
47
|
equal(permissions.contents, 'read')
|
|
48
48
|
equal(permissions['pull-requests'], 'write')
|
|
49
49
|
})
|
|
50
50
|
|
|
51
|
-
test('creates gh action with TS build step', async ({
|
|
51
|
+
test('creates gh action with TS build step', async ({ equal, match }) => {
|
|
52
52
|
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, true)
|
|
53
|
-
equal(log[0], 'Github action successfully created, please add
|
|
53
|
+
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
54
54
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
55
55
|
equal(accessible, true)
|
|
56
56
|
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'), 'utf8')
|
|
@@ -61,7 +61,7 @@ test('creates gh action with TS build step', async ({ end, equal }) => {
|
|
|
61
61
|
equal(steps[1].name, 'npm install --omit=dev')
|
|
62
62
|
equal(steps[2].name, 'Build project')
|
|
63
63
|
equal(steps[3].name, 'Deploy project')
|
|
64
|
-
|
|
64
|
+
match(steps[3].env.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
|
|
65
65
|
equal(steps[3].env.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
66
66
|
|
|
67
67
|
equal(permissions.contents, 'read')
|
|
@@ -78,17 +78,21 @@ test('do not create gitignore file because already present', async ({ end, equal
|
|
|
78
78
|
|
|
79
79
|
test('creates gh action with a warn if a .git folder is not present', async ({ end, equal }) => {
|
|
80
80
|
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
81
|
-
equal(log[0], 'Github action successfully created, please add
|
|
81
|
+
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
82
82
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
83
83
|
equal(accessible, true)
|
|
84
|
-
|
|
84
|
+
const secretsLogLine = log[1].split('\n')
|
|
85
|
+
equal(secretsLogLine[1].trim(), 'PLATFORMATIC_DYNAMIC_WORKSPACE_ID: your workspace id')
|
|
86
|
+
equal(secretsLogLine[2].trim(), 'PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY: your workspace API key')
|
|
87
|
+
equal(secretsLogLine[3].trim(), 'DATABASE_URL: mydbconnectionstring')
|
|
88
|
+
equal(log[2], 'No git repository found. The Github action won\'t be triggered.')
|
|
85
89
|
})
|
|
86
90
|
|
|
87
91
|
test('creates gh action without a warn if a .git folder is present', async ({ end, equal }) => {
|
|
88
92
|
await mkdir(join(tmpDir, '.git'), { recursive: true })
|
|
89
93
|
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
90
|
-
equal(log[0], 'Github action successfully created, please add
|
|
94
|
+
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
91
95
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
92
96
|
equal(accessible, true)
|
|
93
|
-
equal(log.length,
|
|
97
|
+
equal(log.length, 2)
|
|
94
98
|
})
|
|
@@ -29,9 +29,9 @@ const env = {
|
|
|
29
29
|
PLT_SERVER_LOGGER_LEVEL: 'info'
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
test('creates gh action', async ({
|
|
32
|
+
test('creates gh action', async ({ equal, match }) => {
|
|
33
33
|
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, false)
|
|
34
|
-
equal(log[0], 'Github action successfully created, please add
|
|
34
|
+
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
35
35
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
36
36
|
equal(accessible, true)
|
|
37
37
|
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'), 'utf8')
|
|
@@ -41,15 +41,15 @@ test('creates gh action', async ({ end, equal }) => {
|
|
|
41
41
|
equal(steps[0].name, 'Checkout application project repository')
|
|
42
42
|
equal(steps[1].name, 'npm install --omit=dev')
|
|
43
43
|
equal(steps[2].name, 'Deploy project')
|
|
44
|
-
|
|
44
|
+
match(steps[2].env.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
|
|
45
45
|
equal(steps[2].env.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
46
46
|
|
|
47
47
|
equal(permissions.contents, 'read')
|
|
48
48
|
})
|
|
49
49
|
|
|
50
|
-
test('creates gh action with TS build step', async ({
|
|
50
|
+
test('creates gh action with TS build step', async ({ equal, match }) => {
|
|
51
51
|
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, true)
|
|
52
|
-
equal(log[0], 'Github action successfully created, please add
|
|
52
|
+
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
53
53
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
54
54
|
equal(accessible, true)
|
|
55
55
|
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'), 'utf8')
|
|
@@ -60,7 +60,7 @@ test('creates gh action with TS build step', async ({ end, equal }) => {
|
|
|
60
60
|
equal(steps[1].name, 'npm install --omit=dev')
|
|
61
61
|
equal(steps[2].name, 'Build project')
|
|
62
62
|
equal(steps[3].name, 'Deploy project')
|
|
63
|
-
|
|
63
|
+
match(steps[3].env.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
|
|
64
64
|
equal(steps[3].env.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
65
65
|
|
|
66
66
|
equal(permissions.contents, 'read')
|
|
@@ -76,17 +76,21 @@ test('do not create gitignore file because already present', async ({ end, equal
|
|
|
76
76
|
|
|
77
77
|
test('creates gh action with a warn if a .git folder is not present', async ({ end, equal }) => {
|
|
78
78
|
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
79
|
-
equal(log[0], 'Github action successfully created, please add
|
|
79
|
+
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
80
80
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
81
81
|
equal(accessible, true)
|
|
82
|
-
|
|
82
|
+
const secretsLogLine = log[1].split('\n')
|
|
83
|
+
equal(secretsLogLine[1].trim(), 'PLATFORMATIC_STATIC_WORKSPACE_ID: your workspace id')
|
|
84
|
+
equal(secretsLogLine[2].trim(), 'PLATFORMATIC_STATIC_WORKSPACE_API_KEY: your workspace API key')
|
|
85
|
+
equal(secretsLogLine[3].trim(), 'DATABASE_URL: mydbconnectionstring')
|
|
86
|
+
equal(log[2], 'No git repository found. The Github action won\'t be triggered.')
|
|
83
87
|
})
|
|
84
88
|
|
|
85
89
|
test('creates gh action without a warn if a .git folder is present', async ({ end, equal }) => {
|
|
86
90
|
await mkdir(join(tmpDir, '.git'), { recursive: true })
|
|
87
91
|
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
88
|
-
equal(log[0], 'Github action successfully created, please add
|
|
92
|
+
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
89
93
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
90
94
|
equal(accessible, true)
|
|
91
|
-
equal(log.length,
|
|
95
|
+
equal(log.length, 2)
|
|
92
96
|
})
|