Skip to content

Commit d9d4824

Browse files
author
Allen Hai
authored
Move Parcel to ZEIT Now v2 (parcel-bundler#537)
1 parent 32396c6 commit d9d4824

File tree

9 files changed

+106
-59
lines changed

9 files changed

+106
-59
lines changed

.github/workflows/main.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
on: [push]
2+
3+
jobs:
4+
deploy_to_now:
5+
runs-on: ubuntu-latest
6+
env:
7+
NOW_TOKEN: ${{ secrets.NOW_TOKEN }}
8+
name: Deploy to ZEIT Now
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v1
12+
- name: Deploy
13+
id: deploy
14+
uses: ./

Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:10-jessie
2+
3+
LABEL com.github.actions.name="Deploy Parcel To ZEIT"
4+
LABEL com.github.actions.description="Deploy static v2 sites for each Parcel locale"
5+
LABEL repository="https://github.com/coetry/parceljs-www"
6+
7+
WORKDIR /usr/src/app
8+
9+
COPY src/ ./src
10+
COPY package.json build.sh deploy.js ./
11+
12+
RUN yarn && ./build.sh
13+
14+
15+
COPY entrypoint.sh /entrypoint.sh
16+
ENTRYPOINT ["/entrypoint.sh"]

action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: 'Deploy Parcel to ZEIT'
2+
description: 'Create ZEIT v2 production deployment on push'
3+
runs:
4+
using: 'docker'
5+
image: 'Dockerfile'

build.sh

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ for lang in src/i18n/*; do
99
cp -R src/assets tmp/layout/assets;
1010
./node_modules/.bin/generate-md --layout tmp/layout --input tmp/docs --output "dist/$(basename "$lang")";
1111
cp "$lang/index.html" "dist/$(basename "$lang")/index.html";
12+
if [ "$lang" = "en" ]; then
13+
echo "{
14+
\"version\": 2,
15+
\"alias\": [\"$(basename "$lang").parceljs.org\", \"parceljs.org\"]
16+
}" >> "dist/$(basename "$lang")/now.json";
17+
else echo "{
18+
\"version\": 2,
19+
\"alias\": [\"$(basename "$lang").parceljs.org\"]
20+
}" >> "dist/$(basename "$lang")/now.json";
21+
fi;
22+
cat "dist/$(basename "$lang")/now.json";
1223
done
1324

1425
rm -rf tmp

deploy.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const path = require('path')
2+
const { createDeployment } = require('now-client')
3+
const { readdir } = require('fs')
4+
5+
try {
6+
readdir(`${__dirname}/dist`, (err, locales) => {
7+
console.log({ locales })
8+
if (err) throw new Error(err)
9+
let start = Date.now()
10+
Promise.all(
11+
locales.map(async locale => {
12+
let sitePath = path.join(__dirname, 'dist', locale)
13+
console.log({ sitePath })
14+
console.log(`deploying ... ${locale}`)
15+
try {
16+
let deployment = await deploy(sitePath)
17+
console.log({ [locale]: deployment })
18+
return deployment
19+
} catch (e) {
20+
throw new Error(e)
21+
}
22+
})
23+
)
24+
.then(deployments => {
25+
let time = Date.now() - start
26+
console.log('total deployment time: ', time)
27+
})
28+
.catch(console.error)
29+
})
30+
} catch ({ message }) {
31+
console.error(message)
32+
}
33+
34+
async function deploy(sitePath) {
35+
console.log(`${sitePath}`)
36+
let deployment
37+
for await (const event of createDeployment(sitePath, {
38+
token: process.env.NOW_TOKEN
39+
})) {
40+
if (event.type === 'ready') {
41+
deployment = event.payload
42+
break
43+
} else {
44+
console.log({ event })
45+
}
46+
}
47+
return deployment
48+
}

entrypoint.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh -l
2+
3+
set -eu # stop on error
4+
node /usr/src/app/deploy.js

now.json

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
{
2-
"alias": [
3-
"parceljs.org",
4-
"en.parceljs.org",
5-
"es.parceljs.org",
6-
"fr.parceljs.org",
7-
"it.parceljs.org",
8-
"ja.parceljs.org",
9-
"ko.parceljs.org",
10-
"pl.parceljs.org",
11-
"pt.parceljs.org",
12-
"ru.parceljs.org",
13-
"zh.parceljs.org",
14-
"uk.parceljs.org",
15-
"zh-tw.parceljs.org"
16-
]
2+
"version": 2,
3+
"github": {
4+
"enabled": false
5+
}
176
}

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"license": "MIT",
99
"scripts": {
1010
"build": "./build.sh",
11+
"dev": "if [ -d \"dist\" ]; then cd dist; serve; else ./build.sh; cd dist; serve; fi;",
1112
"clean": "rm -rf dist",
12-
"start": "node src/server.js",
1313
"format": "prettier --write 'src/**/*.{md,js,css,json}'",
1414
"deploy": "now"
1515
},
@@ -19,13 +19,14 @@
1919
}
2020
},
2121
"dependencies": {
22-
"express": "^4.16.2"
22+
"now-client": "5.2.0"
2323
},
2424
"devDependencies": {
2525
"husky": "^1.1.2",
2626
"markdown-styles": "^3.1.10",
2727
"now": "^11.2.4",
2828
"prettier": "^1.14.3",
29-
"pretty-quick": "^1.8.0"
29+
"pretty-quick": "^1.8.0",
30+
"serve": "^11.2.0"
3031
}
3132
}

src/server.js

-41
This file was deleted.

0 commit comments

Comments
 (0)