commit
						c3d1535224
					
				
					 4 changed files with 63 additions and 21 deletions
				
			
		
							
								
								
									
										6
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										6
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							| 
						 | 
					@ -199,6 +199,12 @@
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    "adm-zip": {
 | 
				
			||||||
 | 
					      "version": "0.4.7",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.7.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha1-hgbCy/HEJs6MjsABdER/1Jtur8E=",
 | 
				
			||||||
 | 
					      "dev": true
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "after": {
 | 
					    "after": {
 | 
				
			||||||
      "version": "0.8.2",
 | 
					      "version": "0.8.2",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/after/-/after-0.8.2.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/after/-/after-0.8.2.tgz",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@
 | 
				
			||||||
  "scripts": {
 | 
					  "scripts": {
 | 
				
			||||||
    "start": "webpack -w --debug --devtool inline-source-map",
 | 
					    "start": "webpack -w --debug --devtool inline-source-map",
 | 
				
			||||||
    "build": "NODE_ENV=production webpack --progress --display-error-details",
 | 
					    "build": "NODE_ENV=production webpack --progress --display-error-details",
 | 
				
			||||||
    "package": "npm run build && ./package.sh",
 | 
					    "package": "npm run build && node script/package.js",
 | 
				
			||||||
    "lint": "eslint --ext .jsx,.js src",
 | 
					    "lint": "eslint --ext .jsx,.js src",
 | 
				
			||||||
    "test": "karma start"
 | 
					    "test": "karma start"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
| 
						 | 
					@ -19,6 +19,7 @@
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "homepage": "https://github.com/ueokande/vim-vixen",
 | 
					  "homepage": "https://github.com/ueokande/vim-vixen",
 | 
				
			||||||
  "devDependencies": {
 | 
					  "devDependencies": {
 | 
				
			||||||
 | 
					    "adm-zip": "^0.4.7",
 | 
				
			||||||
    "babel-cli": "^6.24.1",
 | 
					    "babel-cli": "^6.24.1",
 | 
				
			||||||
    "babel-eslint": "^8.0.2",
 | 
					    "babel-eslint": "^8.0.2",
 | 
				
			||||||
    "babel-loader": "^7.1.1",
 | 
					    "babel-loader": "^7.1.1",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										20
									
								
								package.sh
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								package.sh
									
										
									
									
									
								
							| 
						 | 
					@ -1,20 +0,0 @@
 | 
				
			||||||
#!/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
 | 
					 | 
				
			||||||
							
								
								
									
										55
									
								
								script/package.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								script/package.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -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);
 | 
				
			||||||
		Reference in a new issue