diff --git a/.gitignore b/.gitignore index 878d75c8..2575f1d3 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ node_modules yarn.lock package-lock.json + +# Release +dist diff --git a/package.json b/package.json index 742b9bcd..9c291cfa 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": {} } diff --git a/scripts/release.js b/scripts/release.js new file mode 100644 index 00000000..2a76786a --- /dev/null +++ b/scripts/release.js @@ -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()