create-platformatic 1.49.0 → 1.50.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/create-platformatic.mjs +2 -5
- package/package.json +16 -12
- package/src/colors.mjs +4 -0
- package/src/create-git-repository.mjs +108 -0
- package/src/index.mjs +317 -0
- package/src/say.mjs +20 -0
- package/src/utils.mjs +130 -2
- package/test/cli/.gitkeep +0 -0
- package/test/cli/README.md +8 -0
- package/test/cli/composer.test.mjs +80 -0
- package/test/cli/db.test.mjs +86 -0
- package/test/cli/helper.mjs +159 -0
- package/test/cli/runtime.test.mjs +104 -0
- package/test/cli/service.test.mjs +200 -0
- package/test/cli/stackable.test.mjs +101 -0
- package/test/cli/timeout.mjs +3 -0
- package/test/unit/create-git-repository.test.mjs +61 -0
- package/test/unit/fetch-stackables.mjs +84 -0
- package/test/unit/utils.test.mjs +291 -0
- package/help/db.txt +0 -11
- package/help/help.txt +0 -8
- package/help/service.txt +0 -7
- package/src/ghaction.mjs +0 -185
package/src/ghaction.mjs
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { join } from 'path'
|
|
2
|
-
import { isFileAccessible, safeMkdir } from './utils.mjs'
|
|
3
|
-
import { writeFile } from 'fs/promises'
|
|
4
|
-
import columnify from 'columnify'
|
|
5
|
-
|
|
6
|
-
function envAsString (env, indent) {
|
|
7
|
-
const spaces = ' '.repeat(indent * 2)
|
|
8
|
-
return Object.keys(env).reduce((acc, key) => {
|
|
9
|
-
if (key.match('DATABASE_URL')) {
|
|
10
|
-
acc += `${spaces}${key}: \${{ secrets.${key} }}\n`
|
|
11
|
-
} else {
|
|
12
|
-
acc += `${spaces}${key}: ${env[key]}\n`
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return acc
|
|
16
|
-
}, '')
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function formatSecretsToAdd (secrets) {
|
|
20
|
-
const output = columnify(secrets, {
|
|
21
|
-
showHeaders: false,
|
|
22
|
-
columnSplitter: ': ',
|
|
23
|
-
config: {
|
|
24
|
-
key: {
|
|
25
|
-
align: 'right'
|
|
26
|
-
},
|
|
27
|
-
value: {
|
|
28
|
-
align: 'left'
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
return output
|
|
33
|
-
}
|
|
34
|
-
export const dynamicWorkspaceGHTemplate = (env, config, buildTS = false) => {
|
|
35
|
-
const envString = envAsString(env, 3)
|
|
36
|
-
let envBlock = ''
|
|
37
|
-
if (envString.length) {
|
|
38
|
-
envBlock = `
|
|
39
|
-
env:
|
|
40
|
-
${envString}
|
|
41
|
-
`
|
|
42
|
-
}
|
|
43
|
-
return `name: Deploy Platformatic application to the cloud
|
|
44
|
-
on:
|
|
45
|
-
pull_request:
|
|
46
|
-
paths-ignore:
|
|
47
|
-
- 'docs/**'
|
|
48
|
-
- '**.md'
|
|
49
|
-
workflow_dispatch:
|
|
50
|
-
inputs:
|
|
51
|
-
label:
|
|
52
|
-
description: "Preview Label"
|
|
53
|
-
required: true
|
|
54
|
-
default: ""
|
|
55
|
-
|
|
56
|
-
jobs:
|
|
57
|
-
build_and_deploy:
|
|
58
|
-
permissions:
|
|
59
|
-
contents: read
|
|
60
|
-
pull-requests: write
|
|
61
|
-
runs-on: ubuntu-latest
|
|
62
|
-
${envBlock}
|
|
63
|
-
steps:
|
|
64
|
-
- name: Checkout application project repository
|
|
65
|
-
uses: actions/checkout@v3
|
|
66
|
-
- name: npm install --omit=dev
|
|
67
|
-
run: npm install --omit=dev${buildTS
|
|
68
|
-
? `
|
|
69
|
-
- name: Build project
|
|
70
|
-
run: npm run build`
|
|
71
|
-
: ''}
|
|
72
|
-
- name: Deploy project
|
|
73
|
-
id: deploy-project
|
|
74
|
-
uses: platformatic/onestep@latest
|
|
75
|
-
with:
|
|
76
|
-
github_token: \${{ secrets.GITHUB_TOKEN }}
|
|
77
|
-
platformatic_workspace_id: \${{ secrets.PLATFORMATIC_DYNAMIC_WORKSPACE_ID }}
|
|
78
|
-
platformatic_workspace_key: \${{ secrets.PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY }}
|
|
79
|
-
platformatic_config_path: ${config}
|
|
80
|
-
label: \${{ github.event.inputs.label }}
|
|
81
|
-
outputs:
|
|
82
|
-
deployment_id: \${{ steps.deploy-project.outputs.deployment_id }}
|
|
83
|
-
calculate_risk:
|
|
84
|
-
permissions:
|
|
85
|
-
contents: read
|
|
86
|
-
pull-requests: write
|
|
87
|
-
needs: build_and_deploy
|
|
88
|
-
runs-on: ubuntu-latest
|
|
89
|
-
steps:
|
|
90
|
-
- name: Calculate risk
|
|
91
|
-
uses: platformatic/onestep/actions/calculate-risk@latest
|
|
92
|
-
if: github.event_name == 'pull_request'
|
|
93
|
-
with:
|
|
94
|
-
github_token: \${{ secrets.GITHUB_TOKEN }}
|
|
95
|
-
platformatic_workspace_id: \${{ secrets.PLATFORMATIC_DYNAMIC_WORKSPACE_ID }}
|
|
96
|
-
platformatic_workspace_key: \${{ secrets.PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY }}
|
|
97
|
-
platformatic_deployment_id: \${{ needs.build_and_deploy.outputs.deployment_id }}
|
|
98
|
-
`
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export const staticWorkspaceGHTemplate = (env, config, buildTS = false) => {
|
|
102
|
-
const envString = envAsString(env, 3)
|
|
103
|
-
let envBlock = ''
|
|
104
|
-
if (envString.length) {
|
|
105
|
-
envBlock = `
|
|
106
|
-
env:
|
|
107
|
-
${envString}
|
|
108
|
-
`
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return `name: Deploy Platformatic application to the cloud
|
|
112
|
-
on:
|
|
113
|
-
push:
|
|
114
|
-
branches:
|
|
115
|
-
- main
|
|
116
|
-
paths-ignore:
|
|
117
|
-
- 'docs/**'
|
|
118
|
-
- '**.md'
|
|
119
|
-
workflow_dispatch:
|
|
120
|
-
inputs:
|
|
121
|
-
|
|
122
|
-
jobs:
|
|
123
|
-
build_and_deploy:
|
|
124
|
-
permissions:
|
|
125
|
-
contents: read
|
|
126
|
-
runs-on: ubuntu-latest
|
|
127
|
-
${envBlock}
|
|
128
|
-
steps:
|
|
129
|
-
- name: Checkout application project repository
|
|
130
|
-
uses: actions/checkout@v3
|
|
131
|
-
- name: npm install --omit=dev
|
|
132
|
-
run: npm install --omit=dev${buildTS
|
|
133
|
-
? `
|
|
134
|
-
- name: Build project
|
|
135
|
-
run: npm run build`
|
|
136
|
-
: ''}
|
|
137
|
-
- name: Deploy project
|
|
138
|
-
uses: platformatic/onestep@latest
|
|
139
|
-
with:
|
|
140
|
-
github_token: \${{ secrets.GITHUB_TOKEN }}
|
|
141
|
-
platformatic_workspace_id: \${{ secrets.PLATFORMATIC_STATIC_WORKSPACE_ID }}
|
|
142
|
-
platformatic_workspace_key: \${{ secrets.PLATFORMATIC_STATIC_WORKSPACE_API_KEY }}
|
|
143
|
-
platformatic_config_path: ${config}
|
|
144
|
-
`
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export const createDynamicWorkspaceGHAction = async (logger, env, config, projectDir, buildTS) => {
|
|
148
|
-
const ghActionFileName = 'platformatic-dynamic-workspace-deploy.yml'
|
|
149
|
-
const ghActionFilePath = join(projectDir, '.github', 'workflows', ghActionFileName)
|
|
150
|
-
await safeMkdir(join(projectDir, '.github', 'workflows'), { recursive: true })
|
|
151
|
-
await writeFile(ghActionFilePath, dynamicWorkspaceGHTemplate(env, config, buildTS))
|
|
152
|
-
logger.info('PR Previews are enabled for your app and the Github action was successfully created, please add the following secrets as repository secrets: ')
|
|
153
|
-
const envToBeAdded = { ...env }
|
|
154
|
-
delete envToBeAdded.PORT
|
|
155
|
-
const secretsString = formatSecretsToAdd({
|
|
156
|
-
PLATFORMATIC_DYNAMIC_WORKSPACE_ID: 'your workspace id',
|
|
157
|
-
PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY: 'your workspace API key',
|
|
158
|
-
...envToBeAdded
|
|
159
|
-
})
|
|
160
|
-
logger.info(`\n ${secretsString}`)
|
|
161
|
-
const isGitDir = await isFileAccessible('.git', projectDir)
|
|
162
|
-
if (!isGitDir) {
|
|
163
|
-
logger.warn('No git repository found. The Github action won\'t be triggered.')
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export const createStaticWorkspaceGHAction = async (logger, env, config, projectDir, buildTS) => {
|
|
168
|
-
const ghActionFileName = 'platformatic-static-workspace-deploy.yml'
|
|
169
|
-
const ghActionFilePath = join(projectDir, '.github', 'workflows', ghActionFileName)
|
|
170
|
-
await safeMkdir(join(projectDir, '.github', 'workflows'), { recursive: true })
|
|
171
|
-
await writeFile(ghActionFilePath, staticWorkspaceGHTemplate(env, config, buildTS))
|
|
172
|
-
logger.info('Github action successfully created, please add the following secrets as repository secrets: ')
|
|
173
|
-
const envToBeAdded = { ...env }
|
|
174
|
-
delete envToBeAdded.PORT
|
|
175
|
-
const secretsString = formatSecretsToAdd({
|
|
176
|
-
PLATFORMATIC_STATIC_WORKSPACE_ID: 'your workspace id',
|
|
177
|
-
PLATFORMATIC_STATIC_WORKSPACE_API_KEY: 'your workspace API key',
|
|
178
|
-
...envToBeAdded
|
|
179
|
-
})
|
|
180
|
-
logger.info(`\n ${secretsString}`)
|
|
181
|
-
const isGitDir = await isFileAccessible('.git', projectDir)
|
|
182
|
-
if (!isGitDir) {
|
|
183
|
-
logger.warn('No git repository found. The Github action won\'t be triggered.')
|
|
184
|
-
}
|
|
185
|
-
}
|