Skip to content

Commit

Permalink
chore 添加 release 命令
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueSky-07 committed Mar 2, 2022
1 parent 2b79310 commit 613be94
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
node_modules
yarn.lock
package-lock.json

# Release
dist
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"debug:js": "node scripts/copy.js src build",
"debug:css": "node scripts/copy.js src/style.css build/style.min.css",
"debug:html": "node scripts/copy.js index.src.html index.html",
"start": "npx serve"
"start": "npx serve",
"release": "node scripts/release.js"
},
"repository": {
"type": "git",
Expand All @@ -33,14 +34,15 @@
},
"homepage": "https://api.ihint.me/shuang",
"devDependencies": {
"@babel/cli": "^7",
"@babel/core": "^7",
"@babel/preset-env": "^7",
"babel-preset-minify": "^0",
"clean-css-cli": "^4",
"html-minifier": "^4",
"fs-extra": "^9",
"serve": "^11.3.2"
"@babel/cli": "latest",
"@babel/core": "latest",
"@babel/preset-env": "latest",
"babel-preset-minify": "latest",
"clean-css-cli": "latest",
"html-minifier": "latest",
"fs-extra": "latest",
"serve": "latest",
"archiver": "latest"
},
"dependencies": {}
}
56 changes: 56 additions & 0 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const fs = require('fs')
const fse = require('fs-extra')
const path = require('path')
const archiver = require('archiver')

const VERSION = require(path.resolve(__dirname, '../package.json')).version.split('.').slice(0, 2).join('.')
const DIST_DIR = path.resolve(__dirname, `../dist`)
const DIST_FILE = path.resolve(DIST_DIR, `Shuang_${VERSION}.zip`)

const FILE_LIST = [
'img',
'build',
'README.md',
'LICENSE',
'index.html',
]

console.log(`creating release dist for ${VERSION}`)

fse.mkdirpSync(DIST_DIR)
try {
fse.rmSync(DIST_FILE)
} catch (e) {}

const output = fs.createWriteStream(DIST_FILE)
const zip = archiver('zip')

output.on('close', function () {
console.log(`=> ${DIST_FILE} (${Math.ceil(zip.pointer() / 1024)} kb)`)
})

zip.on('error', function (err) {
throw err
})

zip.pipe(output)

for (const filename of FILE_LIST) {
const filepath = path.resolve(__dirname, `../${filename}`)
if (!fs.existsSync(filepath)) {
console.error(`? ${filename}`)
}
try {
if (fs.lstatSync(filepath).isDirectory()) {
zip.directory(filepath,filename)
console.log(`+ ${filename}/*`)
} else {
zip.file(filepath, { name: filename })
console.log(`+ ${filename}`)
}
} catch (e) {
throw e
}
}

zip.finalize()

0 comments on commit 613be94

Please sign in to comment.