aboutsummaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-05-01 15:51:40 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-05-01 15:51:40 +0900
commit9da2f5fd786ff7ef64eca0a86efb1c0b9a164244 (patch)
treeb888349817d0016dc1499932671bbe6cd95efdaa /script
parentf9889b7f2b634bfe5a540633d8952f4a6f900658 (diff)
parent89d6afecfd257ff4fc62748f771abf37ef3a2852 (diff)
Merge remote-tracking branch 'origin/master' into patch-1
Diffstat (limited to 'script')
-rw-r--r--script/package.js55
-rwxr-xr-xscript/package.sh20
2 files changed, 75 insertions, 0 deletions
diff --git a/script/package.js b/script/package.js
new file mode 100644
index 0000000..0128f0f
--- /dev/null
+++ b/script/package.js
@@ -0,0 +1,55 @@
+let path = require('path');
+let fs = require('fs');
+let AdmZip = require('adm-zip');
+let manifest = require('../manifest');
+
+manifest.iconFiles = function() {
+ return Object.keys(this.icons).map(key => this.icons[key]);
+};
+
+manifest.contentScriptFiles = function() {
+ let files = this.content_scripts.map(entry => entry.js);
+ return [].concat.apply([], files);
+};
+
+manifest.backgroundScriptFiles = function() {
+ return this.background.scripts;
+
+};
+
+manifest.webAccessibleResourceFiles = function() {
+ return this.web_accessible_resources;
+};
+
+manifest.optionFiles = function() {
+ let uiFile = this.options_ui.page;
+ let dir = path.dirname(uiFile);
+ let html = fs.readFileSync(uiFile, 'utf-8');
+
+ let files = [uiFile];
+ let regex = /<\s*script\s+src\s*=\s*'(.*)'\s*>/g;
+ let match = regex.exec(html);
+ while (match) {
+ files.push(path.join(dir, match[1]));
+ match = regex.exec(html);
+ }
+ return files;
+};
+
+let files = []
+ .concat('manifest.json')
+ .concat(manifest.iconFiles())
+ .concat(manifest.contentScriptFiles())
+ .concat(manifest.backgroundScriptFiles())
+ .concat(manifest.webAccessibleResourceFiles())
+ .concat(manifest.optionFiles());
+let zip = new AdmZip();
+let output = `${manifest.version}.zip`;
+console.log(output);
+for (let f of files) {
+ let dir = path.dirname(f);
+ zip.addLocalFile(f, dir);
+ console.log('=>', path.join(dir, f));
+}
+
+zip.writeZip(output);
diff --git a/script/package.sh b/script/package.sh
new file mode 100755
index 0000000..34535ba
--- /dev/null
+++ b/script/package.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+MANIFEST="manifest.json"
+
+version=$(jq -r '.version' $MANIFEST)
+
+icons=$(jq -r '.icons[]' $MANIFEST)
+content_scripts=$(jq -r '.content_scripts[].js[]' $MANIFEST)
+background_scripts=$(jq -r '.background.scripts[]' $MANIFEST)
+web_accessible_resources=$(jq -r '.web_accessible_resources[]' $MANIFEST)
+options_ui=$(jq -r '.options_ui.page' $MANIFEST)
+options_scripts=""
+for html in $options_ui; do
+ scripts=$(grep -Po "(?<=src=['\"])[^'\"]*" "$html")
+ for js in $scripts; do
+ options_scripts="$options_scripts $(dirname $html)/$js"
+ done
+done
+
+zip ${version}.zip $MANIFEST $icons $content_scripts $background_scripts $web_accessible_resources $options_ui $options_scripts