create-platformatic 0.24.0 → 0.25.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 +10 -10
- package/src/ghaction.mjs +12 -36
- package/test/ghaction-dynamic.test.mjs +9 -24
- package/test/ghaction-static.test.mjs +9 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-platformatic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Create platformatic-db interactive tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,30 +22,30 @@
|
|
|
22
22
|
"execa": "^7.1.1",
|
|
23
23
|
"fastify": "^4.17.0",
|
|
24
24
|
"help-me": "^4.2.0",
|
|
25
|
-
"inquirer": "^9.2.
|
|
25
|
+
"inquirer": "^9.2.6",
|
|
26
26
|
"log-update": "^5.0.1",
|
|
27
27
|
"minimist": "^1.2.8",
|
|
28
28
|
"mkdirp": "^2.1.6",
|
|
29
|
-
"ora": "^6.3.
|
|
30
|
-
"pino": "^8.
|
|
29
|
+
"ora": "^6.3.1",
|
|
30
|
+
"pino": "^8.14.1",
|
|
31
31
|
"pino-pretty": "^10.0.0",
|
|
32
32
|
"pupa": "^3.1.0",
|
|
33
|
-
"semver": "^7.5.
|
|
34
|
-
"undici": "^5.22.
|
|
35
|
-
"@platformatic/config": "0.
|
|
33
|
+
"semver": "^7.5.1",
|
|
34
|
+
"undici": "^5.22.1",
|
|
35
|
+
"@platformatic/config": "0.25.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"ajv": "^8.12.0",
|
|
39
39
|
"c8": "^7.13.0",
|
|
40
40
|
"cross-env": "^7.0.3",
|
|
41
41
|
"dotenv": "^16.0.3",
|
|
42
|
-
"esmock": "^2.2.
|
|
42
|
+
"esmock": "^2.2.3",
|
|
43
43
|
"snazzy": "^9.0.0",
|
|
44
44
|
"standard": "^17.0.0",
|
|
45
45
|
"tap": "^16.3.4",
|
|
46
46
|
"yaml": "^2.2.2",
|
|
47
|
-
"@platformatic/db": "0.
|
|
48
|
-
"@platformatic/service": "0.
|
|
47
|
+
"@platformatic/db": "0.25.0",
|
|
48
|
+
"@platformatic/service": "0.25.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"test": "standard | snazzy && cross-env NODE_OPTIONS=\"--loader=esmock --no-warnings\" c8 --100 tap --no-coverage test/*test.mjs test/*/*test.mjs",
|
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 dynamicWorkspaceGHTemplate = (
|
|
7
|
+
export const dynamicWorkspaceGHTemplate = (env, config, buildTS = false) => {
|
|
8
8
|
const envAsStr = Object.keys(env).reduce((acc, key) => {
|
|
9
9
|
acc += ` ${key}: ${env[key]} \n`
|
|
10
10
|
return acc
|
|
@@ -36,7 +36,7 @@ jobs:
|
|
|
36
36
|
uses: platformatic/onestep@latest
|
|
37
37
|
with:
|
|
38
38
|
github_token: \${{ secrets.GITHUB_TOKEN }}
|
|
39
|
-
platformatic_workspace_id:
|
|
39
|
+
platformatic_workspace_id: \${{ secrets.PLATFORMATIC_DYNAMIC_WORKSPACE_ID }}
|
|
40
40
|
platformatic_workspace_key: \${{ secrets.PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY }}
|
|
41
41
|
platformatic_config_path: ${config}
|
|
42
42
|
env:
|
|
@@ -44,7 +44,7 @@ ${envAsStr}
|
|
|
44
44
|
`
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export const staticWorkspaceGHTemplate = (
|
|
47
|
+
export const staticWorkspaceGHTemplate = (env, config, buildTS = false) => {
|
|
48
48
|
const envAsStr = Object.keys(env).reduce((acc, key) => {
|
|
49
49
|
acc += ` ${key}: ${env[key]} \n`
|
|
50
50
|
return acc
|
|
@@ -77,7 +77,7 @@ jobs:
|
|
|
77
77
|
uses: platformatic/onestep@latest
|
|
78
78
|
with:
|
|
79
79
|
github_token: \${{ secrets.GITHUB_TOKEN }}
|
|
80
|
-
platformatic_workspace_id:
|
|
80
|
+
platformatic_workspace_id: \${{ secrets.PLATFORMATIC_STATIC_WORKSPACE_ID }}
|
|
81
81
|
platformatic_workspace_key: \${{ secrets.PLATFORMATIC_STATIC_WORKSPACE_API_KEY }}
|
|
82
82
|
platformatic_config_path: ${config}
|
|
83
83
|
env:
|
|
@@ -85,19 +85,14 @@ ${envAsStr}
|
|
|
85
85
|
`
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
export const createDynamicWorkspaceGHAction = async (logger,
|
|
88
|
+
export const createDynamicWorkspaceGHAction = async (logger, env, config, projectDir, buildTS) => {
|
|
89
89
|
const ghActionFileName = 'platformatic-dynamic-workspace-deploy.yml'
|
|
90
90
|
const ghActionFilePath = join(projectDir, '.github', 'workflows', ghActionFileName)
|
|
91
91
|
const isGithubActionExists = await isFileAccessible(ghActionFilePath)
|
|
92
92
|
if (!isGithubActionExists) {
|
|
93
|
-
if (!workspaceId) {
|
|
94
|
-
logger.info('No workspace ID provided, skipping creation of github action file.')
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
|
|
98
93
|
await mkdirp(join(projectDir, '.github', 'workflows'))
|
|
99
|
-
await writeFile(ghActionFilePath, dynamicWorkspaceGHTemplate(
|
|
100
|
-
logger.info('Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository
|
|
94
|
+
await writeFile(ghActionFilePath, dynamicWorkspaceGHTemplate(env, config, buildTS))
|
|
95
|
+
logger.info('Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_ID and PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secrets.')
|
|
101
96
|
const isGitDir = await isFileAccessible('.git', projectDir)
|
|
102
97
|
if (!isGitDir) {
|
|
103
98
|
logger.warn('No git repository found. The Github action won\'t be triggered.')
|
|
@@ -119,32 +114,20 @@ export const askDynamicWorkspaceCreateGHAction = async (logger, env, type, build
|
|
|
119
114
|
}
|
|
120
115
|
])
|
|
121
116
|
if (githubAction) {
|
|
122
|
-
const { workspaceId } = await inquirer.prompt([
|
|
123
|
-
{
|
|
124
|
-
type: 'input',
|
|
125
|
-
name: 'workspaceId',
|
|
126
|
-
message: 'Please enter the workspace ID:'
|
|
127
|
-
}
|
|
128
|
-
])
|
|
129
117
|
const config = `./platformatic.${type}.json`
|
|
130
|
-
await createDynamicWorkspaceGHAction(logger,
|
|
118
|
+
await createDynamicWorkspaceGHAction(logger, env, config, projectDir, buildTS)
|
|
131
119
|
}
|
|
132
120
|
/* c8 ignore next */
|
|
133
121
|
}
|
|
134
122
|
|
|
135
|
-
export const createStaticWorkspaceGHAction = async (logger,
|
|
123
|
+
export const createStaticWorkspaceGHAction = async (logger, env, config, projectDir, buildTS) => {
|
|
136
124
|
const ghActionFileName = 'platformatic-static-workspace-deploy.yml'
|
|
137
125
|
const ghActionFilePath = join(projectDir, '.github', 'workflows', ghActionFileName)
|
|
138
126
|
const isGithubActionExists = await isFileAccessible(ghActionFilePath)
|
|
139
127
|
if (!isGithubActionExists) {
|
|
140
|
-
if (!workspaceId) {
|
|
141
|
-
logger.info('No workspace ID provided, skipping creation of github action file.')
|
|
142
|
-
return
|
|
143
|
-
}
|
|
144
|
-
|
|
145
128
|
await mkdirp(join(projectDir, '.github', 'workflows'))
|
|
146
|
-
await writeFile(ghActionFilePath, staticWorkspaceGHTemplate(
|
|
147
|
-
logger.info('Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
129
|
+
await writeFile(ghActionFilePath, staticWorkspaceGHTemplate(env, config, buildTS))
|
|
130
|
+
logger.info('Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_ID and PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
148
131
|
const isGitDir = await isFileAccessible('.git', projectDir)
|
|
149
132
|
if (!isGitDir) {
|
|
150
133
|
logger.warn('No git repository found. The Github action won\'t be triggered.')
|
|
@@ -166,15 +149,8 @@ export const askStaticWorkspaceGHAction = async (logger, env, type, buildTS, pro
|
|
|
166
149
|
}
|
|
167
150
|
])
|
|
168
151
|
if (githubAction) {
|
|
169
|
-
const { workspaceId } = await inquirer.prompt([
|
|
170
|
-
{
|
|
171
|
-
type: 'input',
|
|
172
|
-
name: 'workspaceId',
|
|
173
|
-
message: 'Please enter the workspace ID:'
|
|
174
|
-
}
|
|
175
|
-
])
|
|
176
152
|
const config = `./platformatic.${type}.json`
|
|
177
|
-
await createStaticWorkspaceGHAction(logger,
|
|
153
|
+
await createStaticWorkspaceGHAction(logger, env, config, projectDir, buildTS)
|
|
178
154
|
}
|
|
179
155
|
/* c8 ignore next */
|
|
180
156
|
}
|
|
@@ -31,9 +31,8 @@ const env = {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
test('creates gh action', async ({ end, equal }) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secret.')
|
|
34
|
+
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, false)
|
|
35
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_ID and PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secrets.')
|
|
37
36
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
38
37
|
equal(accessible, true)
|
|
39
38
|
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'), 'utf8')
|
|
@@ -51,9 +50,8 @@ test('creates gh action', async ({ end, equal }) => {
|
|
|
51
50
|
})
|
|
52
51
|
|
|
53
52
|
test('creates gh action with TS build step', async ({ end, equal }) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secret.')
|
|
53
|
+
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, true)
|
|
54
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_ID and PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secrets.')
|
|
57
55
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
58
56
|
equal(accessible, true)
|
|
59
57
|
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'), 'utf8')
|
|
@@ -75,15 +73,13 @@ test('do not create gitignore file because already present', async ({ end, equal
|
|
|
75
73
|
await mkdirp(join(tmpDir, '.github', 'workflows'))
|
|
76
74
|
const ghaction = join(tmpDir, '.github', 'workflows', 'platformatic-dynamic-workspace-deploy.yml')
|
|
77
75
|
await writeFile(ghaction, 'TEST')
|
|
78
|
-
|
|
79
|
-
await createDynamicWorkspaceGHAction(fakeLogger, workspaceId, env, 'db', tmpDir)
|
|
76
|
+
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
80
77
|
equal(log[0], `Github action file ${join(tmpDir, '.github', 'workflows', 'platformatic-dynamic-workspace-deploy.yml')} found, skipping creation of github action file.`)
|
|
81
78
|
})
|
|
82
79
|
|
|
83
80
|
test('creates gh action with a warn if a .git folder is not present', async ({ end, equal }) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secret.')
|
|
81
|
+
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
82
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_ID and PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secrets.')
|
|
87
83
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
88
84
|
equal(accessible, true)
|
|
89
85
|
equal(log[1], 'No git repository found. The Github action won\'t be triggered.')
|
|
@@ -91,20 +87,9 @@ test('creates gh action with a warn if a .git folder is not present', async ({ e
|
|
|
91
87
|
|
|
92
88
|
test('creates gh action without a warn if a .git folder is present', async ({ end, equal }) => {
|
|
93
89
|
await mkdirp(join(tmpDir, '.git'))
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secret.')
|
|
90
|
+
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
91
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_DYNAMIC_WORKSPACE_ID and PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY as repository secrets.')
|
|
97
92
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
98
93
|
equal(accessible, true)
|
|
99
94
|
equal(log.length, 1)
|
|
100
95
|
})
|
|
101
|
-
|
|
102
|
-
test('do not creates gh action if workspace is empty', async ({ end, equal }) => {
|
|
103
|
-
await mkdirp(join(tmpDir, '.git'))
|
|
104
|
-
const workspaceId = ''
|
|
105
|
-
await createDynamicWorkspaceGHAction(fakeLogger, workspaceId, env, 'db', tmpDir)
|
|
106
|
-
equal(log[0], 'No workspace ID provided, skipping creation of github action file.')
|
|
107
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
108
|
-
equal(accessible, false)
|
|
109
|
-
equal(log.length, 1)
|
|
110
|
-
})
|
|
@@ -31,9 +31,8 @@ const env = {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
test('creates gh action', async ({ end, equal }) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
34
|
+
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, false)
|
|
35
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_ID and PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
37
36
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
38
37
|
equal(accessible, true)
|
|
39
38
|
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'), 'utf8')
|
|
@@ -50,9 +49,8 @@ test('creates gh action', async ({ end, equal }) => {
|
|
|
50
49
|
})
|
|
51
50
|
|
|
52
51
|
test('creates gh action with TS build step', async ({ end, equal }) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
52
|
+
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, true)
|
|
53
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_ID and PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
56
54
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
57
55
|
equal(accessible, true)
|
|
58
56
|
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'), 'utf8')
|
|
@@ -73,15 +71,13 @@ test('do not create gitignore file because already present', async ({ end, equal
|
|
|
73
71
|
await mkdirp(join(tmpDir, '.github', 'workflows'))
|
|
74
72
|
const ghaction = join(tmpDir, '.github', 'workflows', 'platformatic-static-workspace-deploy.yml')
|
|
75
73
|
await writeFile(ghaction, 'TEST')
|
|
76
|
-
|
|
77
|
-
await createStaticWorkspaceGHAction(fakeLogger, workspaceId, env, 'db', tmpDir)
|
|
74
|
+
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
78
75
|
equal(log[0], `Github action file ${join(tmpDir, '.github', 'workflows', 'platformatic-static-workspace-deploy.yml')} found, skipping creation of github action file.`)
|
|
79
76
|
})
|
|
80
77
|
|
|
81
78
|
test('creates gh action with a warn if a .git folder is not present', async ({ end, equal }) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
79
|
+
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
80
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_ID and PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
85
81
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
86
82
|
equal(accessible, true)
|
|
87
83
|
equal(log[1], 'No git repository found. The Github action won\'t be triggered.')
|
|
@@ -89,20 +85,9 @@ test('creates gh action with a warn if a .git folder is not present', async ({ e
|
|
|
89
85
|
|
|
90
86
|
test('creates gh action without a warn if a .git folder is present', async ({ end, equal }) => {
|
|
91
87
|
await mkdirp(join(tmpDir, '.git'))
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
88
|
+
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
89
|
+
equal(log[0], 'Github action successfully created, please add PLATFORMATIC_STATIC_WORKSPACE_ID and PLATFORMATIC_STATIC_WORKSPACE_API_KEY as repository secret.')
|
|
95
90
|
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
96
91
|
equal(accessible, true)
|
|
97
92
|
equal(log.length, 1)
|
|
98
93
|
})
|
|
99
|
-
|
|
100
|
-
test('do not creates gh action if workspace is empty', async ({ end, equal }) => {
|
|
101
|
-
await mkdirp(join(tmpDir, '.git'))
|
|
102
|
-
const workspaceId = ''
|
|
103
|
-
await createStaticWorkspaceGHAction(fakeLogger, workspaceId, env, 'db', tmpDir)
|
|
104
|
-
equal(log[0], 'No workspace ID provided, skipping creation of github action file.')
|
|
105
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
106
|
-
equal(accessible, false)
|
|
107
|
-
equal(log.length, 1)
|
|
108
|
-
})
|