From 1e2bfd02ce10de22aa829722a393b3f3e2728ce7 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Fri, 20 Jul 2018 12:27:33 -0500 Subject: [PATCH] Add zip script --- .gitignore | 1 + package.json | 4 +++- tools/zip.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tools/zip.js diff --git a/.gitignore b/.gitignore index 71278d14..29432c99 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ pull_locales_login.rb node_modules/ package-lock.json yarn.lock +*.zip diff --git a/package.json b/package.json index 94049bb1..ff019780 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "repository": "openstyles/stylus", "author": "Stylus Team", "devDependencies": { + "archiver": "^2.1.1", "codemirror": "^5.39.2", "eslint": "^5.1.0", "fs-extra": "^7.0.0", @@ -21,6 +22,7 @@ "build": "npm run update && npm run build:cm", "build:cm": "node tools/update-libraries.js && node tools/update-codemirror-themes.js", "lint": "eslint **/*.js || true", - "update": "updates -u && npm update" + "update": "updates -u && npm update", + "zip": "node tools/zip.js" } } diff --git a/tools/zip.js b/tools/zip.js new file mode 100644 index 00000000..995539e5 --- /dev/null +++ b/tools/zip.js @@ -0,0 +1,59 @@ +#!/usr/bin/env node +'use strict'; + +const fs = require('fs'); +const archiver = require('archiver'); + +function createZip() { + const fileName = 'stylus.zip'; + const includes = [ + '_locales/*', + 'background/*', + 'content/*', + 'edit/*', + 'images/*', + 'install-usercss/*', + 'js/*', + 'manage/*', + 'msgbox/*', + 'options/*', + 'popup/*', + 'vendor/*', + 'vendor-overwrites/*', + '*.html', + '*.css', + 'manifest.json', + 'LICENSE', + 'README.md' + ]; + + const file = fs.createWriteStream(fileName); + const archive = archiver('zip'); + return new Promise((resolve, reject) => { + archive.on('finish', () => { + resolve(); + }); + archive.on('warning', err => { + if (err.code === 'ENOENT') { + console.log('\x1b[33m%s\x1b[0m', 'Warning', err.message); + } else { + reject(); + throw err; + } + }); + archive.on('error', err => { + reject(); + throw err; + }); + + archive.pipe(file); + includes.forEach(file => archive.glob(file)); + archive.finalize(); + }); +} + +createZip() + .then(() => console.log('\x1b[32m%s\x1b[0m', 'Stylus zip complete')) + .catch(err => { + throw err; + });