From 7205567cff165e8b8e21cf7e25e2296cb61cccb9 Mon Sep 17 00:00:00 2001 From: Damien Erambert Date: Sat, 10 Sep 2016 12:02:57 -0700 Subject: [PATCH] :wrench: --- .eslintignore | 1 - package.json | 14 +++++------ tools/pack.js | 46 ++++++++++++++++++++++++++++++++++++ tools/pack.sh | 49 -------------------------------------- tools/update_emojis.js | 53 +++++++++++++++++------------------------- 5 files changed, 74 insertions(+), 89 deletions(-) create mode 100644 tools/pack.js delete mode 100755 tools/pack.sh diff --git a/.eslintignore b/.eslintignore index 77ac16111..346f96e05 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,3 @@ gulpfile.* -tools/**/*.js tools/**/*.json src/emojis/emojis.js diff --git a/package.json b/package.json index 1075f4dac..a4b835338 100644 --- a/package.json +++ b/package.json @@ -15,20 +15,24 @@ "start": "cross-env NODE_ENV=dev && gulp", "build": "cross-env NODE_ENV=dev && gulp build", "build:prod": "rimraf dist/ && cross-env NODE_ENV=prod && gulp build --type production && zip -qr -9 -X dist.zip dist/", - "bs-options": "browser-sync start --server 'dist/options/' --files 'dist/options/**/*'" + "pack": "node tools/pack.js" }, "homepage": "https://github.com/eramdam/BetterTweetDeck", - "devDependencies": { + "dependencies": { "babel-core": ">=6.2.1", "babel-plugin-transform-es2015-modules-commonjs": ">=6.2.0", "babel-preset-es2015": ">=6.1.18", "babelify": ">=7.2.0", "browser-sync": "^2.12.10", "browserify": ">=11.0.1", + "chalk": "^1.1.3", "config": "^1.17.1", "config-browserify": "^1.0.5", + "cross-env": "^2.0.1", + "crx": "^3.0.3", "cssnano": "^3.5.2", "del": ">=1.2.1", + "domify": "^1.4.0", "eslint": "^2.9.0", "eslint-config-airbnb-base": "^3.0.0", "eslint-plugin-import": "^1.7.0", @@ -56,14 +60,10 @@ "promise-each": "^2.2.0", "query-string": "^4.2.1", "reuse-promise": "^1.0.1", + "rimraf": "^2.5.4", "run-sequence": ">=1.1.2", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": ">=1.1.0", "vinyl-transform": "^1.0.0" - }, - "dependencies": { - "cross-env": "^2.0.1", - "domify": "^1.4.0", - "rimraf": "^2.5.4" } } diff --git a/tools/pack.js b/tools/pack.js new file mode 100644 index 000000000..1519614d4 --- /dev/null +++ b/tools/pack.js @@ -0,0 +1,46 @@ +const chalk = require('chalk'); +const clog = (color, ...args) => console.log(chalk[color](...args)); +const fs = require('fs'); +const path = require('path'); + +if (!process.argv[2]) { + clog('red', 'Please provide a private key file'); + process.exit(); +} + +const privateKeyPath = path.resolve(process.argv[2]); +const extensionPath = path.resolve(__dirname, '../dist'); +const ChromeExtension = require('crx'); +const crx = new ChromeExtension({ + privateKey: fs.readFileSync(privateKeyPath), +}); + + +clog('blue', `Loading extension from ${extensionPath} with key from ${privateKeyPath}`); + +crx.load(extensionPath) + .then((d) => { + clog('blue', 'Loaded', d.manifest.short_name, d.manifest.version); + + return crx.pack().then(buffer => { + fs.writeFile(path.resolve(__dirname, '../packed/', 'better-tweetdeck.crx'), buffer, (err) => { + if (err) { + clog('red', err); + } + + clog('green', 'Saved better-tweetdeck.crx'); + }); + fs.writeFile(path.resolve(__dirname, '../packed/', 'better-tweetdeck.nex'), buffer, (err) => { + if (err) { + clog('red', err); + } + + clog('green', 'Saved better-tweetdeck.nex'); + }); + }); + }, (err) => { + if (err) { + clog('red', err); + clog('blue', 'Try to run `npm run build` before executing this script'); + } + }); diff --git a/tools/pack.sh b/tools/pack.sh deleted file mode 100755 index bc8334d74..000000000 --- a/tools/pack.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -e -# -# Purpose: Pack a Chromium extension directory into crx format - -if test $# -ne 2; then - echo "Usage: crxmake.sh " - exit 1 -fi - -dir=$1 -key=$2 -name='better_tweetdeck' -crx="$name.crx" -nex="$name.nex" -pub="$name.pub" -sig="$name.sig" -zip="$name.zip" -trap 'rm -f "$pub" "$sig" "$zip"' EXIT - -# zip up the crx dir -cwd=$(pwd -P) -(cd "$dir" && zip -qr -9 -X "$cwd/$zip" .) - -# signature -openssl sha1 -sha1 -binary -sign "$key" < "$zip" > "$sig" - -# public key -openssl rsa -pubout -outform DER < "$key" > "$pub" 2>/dev/null - -byte_swap () { - # Take "abcdefgh" and return it as "ghefcdab" - echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}" -} - -crmagic_hex="4372 3234" # Cr24 -version_hex="0200 0000" # 2 -pub_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$pub" | awk '{print $5}'))) -sig_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$sig" | awk '{print $5}'))) -( - echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p - cat "$pub" "$sig" "$zip" -) > "$crx" -echo "Wrote $crx" - -( - echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p - cat "$pub" "$sig" "$zip" -) > "$nex" -echo "Wrote $crx" diff --git a/tools/update_emojis.js b/tools/update_emojis.js index 9fd8d1b9b..48bee488f 100644 --- a/tools/update_emojis.js +++ b/tools/update_emojis.js @@ -1,5 +1,3 @@ -'use strict'; - const needle = require('needle'); const _ = require('lodash'); const jsEmoji = require('js-emoji'); @@ -12,41 +10,32 @@ function getUnified(emoji) { const converted = Emoji.replace_colons(`:${emoji.s}:`); - if (converted !== `:${emoji.s}:` && !converted.startsWith('${getImage(emoji)}`; -} - const catOrder = { - 'People': -80, - 'Nature': -70, - 'Foods': -60, - 'Activity': -50, - 'Places': -40, - 'Objects': -30, - 'Symbols': -20, - 'Flags': -10 + People: -80, + Nature: -70, + Foods: -60, + Activity: -50, + Places: -40, + Objects: -30, + Symbols: -20, + Flags: -10, }; -const getMissingCategory = (short_name) => { - if (short_name === 'keycap_star') +const getMissingCategory = (shortName) => { + if (shortName === 'keycap_star') { return 'Symbols'; + } - if (short_name.startsWith('flag-')) + if (shortName.startsWith('flag-')) { return 'Flags'; + } return null; }; @@ -60,16 +49,16 @@ needle.get('https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.jso .sortBy(emoji => catOrder[emoji.category]) .map(emoji => { return { - s: emoji.short_name, + s: emoji.shortName, n: emoji.name, hs: Boolean(emoji.skin_variations), - cat: emoji.category || getMissingCategory(emoji.s_name) - } + cat: emoji.category || getMissingCategory(emoji.s_name), + }; }) .value(); - const finalForTemplate = final.filter(emoji => getUnified(emoji)); - const outStr = `module.exports = ${JSON.stringify(finalForTemplate)}`; + const finalForTemplate = final.filter(emoji => getUnified(emoji)); + const outStr = `module.exports = ${JSON.stringify(finalForTemplate)}`; - fs.writeFileSync('./src/emojis/emojis.js', outStr, 'utf8'); + fs.writeFileSync('./src/emojis/emojis.js', outStr, 'utf8'); });