Skip to content

Commit a121c61

Browse files
committed
feat(build): add zip packing script
1 parent 96151e3 commit a121c61

File tree

6 files changed

+51
-1
lines changed

6 files changed

+51
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/build/*.zip
12
/node_modules
23
/dist
34
.DS_Store

build/.gitkeep

Whitespace-only changes.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"description": "Daily sign in 94 EZ.",
55
"scripts": {
66
"dev": "webpack --env development --watch --config config/webpack.config.ts",
7-
"build": "webpack --env production --config config/webpack.config.ts",
7+
"build": "yarn build:ext && yarn build:zip",
8+
"build:ext": "webpack --env production --config config/webpack.config.ts",
9+
"build:zip": "ts-node scripts/buildZip.ts",
810
"lint": "eslint src/**/* --ext .ts"
911
},
1012
"repository": {
@@ -19,9 +21,11 @@
1921
"homepage": "https://github.com/brownsugar/baha-auto-sign#readme",
2022
"private": true,
2123
"devDependencies": {
24+
"@types/adm-zip": "^0.5.0",
2225
"@types/chrome": "^0.0.188",
2326
"@typescript-eslint/eslint-plugin": "^5.26.0",
2427
"@typescript-eslint/parser": "^5.26.0",
28+
"adm-zip": "^0.5.9",
2529
"copy-webpack-plugin": "^11.0.0",
2630
"css-loader": "^6.7.1",
2731
"eslint": "^8.16.0",
@@ -34,6 +38,7 @@
3438
"sass-loader": "^13.0.0",
3539
"ts-loader": "^9.3.0",
3640
"ts-node": "^10.8.0",
41+
"type-fest": "^2.13.0",
3742
"typescript": "^4.7.2",
3843
"webpack": "^5.72.1",
3944
"webpack-cli": "^4.9.2",

scripts/buildZip.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { readFileSync, writeFileSync, existsSync } from 'fs'
2+
import * as Zip from 'adm-zip'
3+
import { PackageJson } from 'type-fest'
4+
5+
const packageJsonPath = './package.json'
6+
const packageJson: PackageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))
7+
const version = packageJson.version
8+
if (version === undefined) {
9+
console.error('Could not fetch package version.')
10+
process.exit(1)
11+
}
12+
13+
const manifestPath = './dist/manifest.json'
14+
if (!existsSync(manifestPath)) {
15+
console.error('Could not find manifest file, please run `yarn build` first.')
16+
process.exit(1)
17+
}
18+
19+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'))
20+
manifest.version = version
21+
writeFileSync(manifestPath, JSON.stringify(manifest, null, 2))
22+
23+
const zip = new Zip()
24+
zip.addLocalFolder('./dist', '')
25+
const zipName = `${packageJson.name as string}-v${version}`
26+
zip.writeZip(`./build/${zipName}.zip`)

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
".eslintrc.js",
1313
"config/*.ts",
1414
"src/**/*.ts",
15+
"scripts/*.ts",
1516
"types/*.ts"
1617
]
1718
}

yarn.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@
132132
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e"
133133
integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==
134134

135+
"@types/adm-zip@^0.5.0":
136+
version "0.5.0"
137+
resolved "https://registry.yarnpkg.com/@types/adm-zip/-/adm-zip-0.5.0.tgz#94c90a837ce02e256c7c665a6a1eb295906333c1"
138+
integrity sha512-FCJBJq9ODsQZUNURo5ILAQueuA8WJhRvuihS3ke2iI25mJlfV2LK8jG2Qj2z2AWg8U0FtWWqBHVRetceLskSaw==
139+
dependencies:
140+
"@types/node" "*"
141+
135142
"@types/chrome@^0.0.188":
136143
version "0.0.188"
137144
resolved "https://registry.yarnpkg.com/@types/chrome/-/chrome-0.0.188.tgz#ed73feca28a6d84f796ec50a2dbe7e41510175b3"
@@ -485,6 +492,11 @@ acorn@^8.4.1, acorn@^8.5.0, acorn@^8.7.1:
485492
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.1.tgz#0197122c843d1bf6d0a5e83220a788f278f63c30"
486493
integrity sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==
487494

495+
adm-zip@^0.5.9:
496+
version "0.5.9"
497+
resolved "https://registry.yarnpkg.com/adm-zip/-/adm-zip-0.5.9.tgz#b33691028333821c0cf95c31374c5462f2905a83"
498+
integrity sha512-s+3fXLkeeLjZ2kLjCBwQufpI5fuN+kIGBxu6530nVQZGVol0d7Y/M88/xw9HGGUcJjKf8LutN3VPRUBq6N7Ajg==
499+
488500
ajv-formats@^2.1.1:
489501
version "2.1.1"
490502
resolved "https://registry.yarnpkg.com/ajv-formats/-/ajv-formats-2.1.1.tgz#6e669400659eb74973bbf2e33327180a0996b520"
@@ -2325,6 +2337,11 @@ type-fest@^0.20.2:
23252337
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4"
23262338
integrity sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==
23272339

2340+
type-fest@^2.13.0:
2341+
version "2.13.0"
2342+
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.13.0.tgz#d1ecee38af29eb2e863b22299a3d68ef30d2abfb"
2343+
integrity sha512-lPfAm42MxE4/456+QyIaaVBAwgpJb6xZ8PRu09utnhPdWwcyj9vgy6Sq0Z5yNbJ21EdxB5dRU/Qg8bsyAMtlcw==
2344+
23282345
typescript@^4.7.2:
23292346
version "4.7.2"
23302347
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.2.tgz#1f9aa2ceb9af87cca227813b4310fff0b51593c4"

0 commit comments

Comments
 (0)