Skip to content

Commit 902a04e

Browse files
committed
feat: create build workflow
1 parent 1adbe05 commit 902a04e

1 file changed

Lines changed: 71 additions & 3 deletions

File tree

lib/commands/create.js

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ async function create (opts) {
6868
config.path = appPath
6969

7070
await fs.ensureDir(appPath)
71+
72+
if (config.githubActions) {
73+
createBuildAction(config)
74+
}
75+
76+
await createConfigFile(config)
7177

7278
await createPackageJson({
7379
cwd: appPath,
@@ -91,8 +97,6 @@ async function create (opts) {
9197
}
9298
})
9399

94-
await createConfigFile(config)
95-
96100
gitInit(appPath)
97101
}
98102

@@ -107,7 +111,7 @@ async function createConfigFile (config) {
107111
config.projects.length >= 1
108112
? `\n projects: ${JSON.stringify(config.projects)},`
109113
: ''
110-
}
114+
}${config.githubActions ? `\n baseUrl: "/${config.name}",` : ''}
111115
github: {
112116
token: process.env.GITHUB_TOKEN
113117
}
@@ -125,4 +129,68 @@ function transformUserInput(input) {
125129
return input?.split(",").map((l) => l.trim()) || []
126130
}
127131

132+
function createBuildAction(config) {
133+
const workflowDir = path.join(config.path, '.github', 'workflows')
134+
fs.ensureDirSync(workflowDir)
135+
const configFile = path.join(workflowDir, 'build.yml')
136+
137+
const buildAction = `name: Generate Statusboard
138+
139+
on:
140+
push:
141+
branches:
142+
- main
143+
workflow_dispatch:
144+
145+
permissions:
146+
contents: read
147+
pages: write
148+
id-token: write
149+
150+
151+
concurrency:
152+
group: "pages"
153+
cancel-in-progress: false
154+
155+
jobs:
156+
index:
157+
environment:
158+
name: github-pages
159+
url: \${{ steps.deployment.outputs.page_url }}
160+
runs-on: ubuntu-latest
161+
steps:
162+
- name: Checkout
163+
uses: actions/checkout@v4
164+
- name: Setup Pages
165+
uses: actions/configure-pages@v5
166+
- uses: actions/setup-node@v4
167+
with:
168+
node-version: lts/*
169+
- uses: actions/cache@v4
170+
id: cache
171+
with:
172+
path: |
173+
~/.npm
174+
~/.cache
175+
./dist
176+
./node_modules
177+
key: \${{ runner.os }}-build-\${{ github.sha }}
178+
- if: steps.cache.outputs.cache-hit != 'true'
179+
run: npm install
180+
shell: bash
181+
- run: npm run build
182+
env:
183+
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
184+
- name: Upload artifact
185+
uses: actions/upload-pages-artifact@v3
186+
with:
187+
path: './build'
188+
- name: Deploy to GitHub Pages
189+
id: deployment
190+
uses: actions/deploy-pages@v4
191+
`
192+
193+
fs.writeFileSync(configFile, buildAction)
194+
}
195+
128196
module.exports = create

0 commit comments

Comments
 (0)