Skip to content

Commit 9686b6b

Browse files
committed
restructure project and add dependencies for automatic packaging of crx file via grunt
1 parent f57589d commit 9686b6b

15 files changed

Lines changed: 74 additions & 19 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
bower_components
3+
.grunt

Gruntfile.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,38 @@ module.exports = function(grunt) {
33
// Project configuration.
44
grunt.initConfig({
55
pkg: grunt.file.readJSON('package.json'),
6+
manifest: grunt.file.readJSON('extension/manifest.json'),
67
jshint: {
7-
files: ['*.js', 'views/*.js'],
8+
files: ['extension/*.js'],
89
options: {
910
jshintrc: true
1011
}
1112
},
1213
jasmine: {
13-
src: ['background.js', 'main.js', 'views/*.js'],
14+
src: ['extension/*.js'],
1415
options: {
1516
specs: 'tests/spec/*.spec.js',
1617
helpers: 'tests/spec/*.helper.js'
1718
}
19+
},
20+
run: {
21+
crxmake: {
22+
exec: [
23+
'./crxmake.sh extension/ cert/key.pem',
24+
'mv extension.crx dist/<%= pkg.name %>-<%= manifest.version %>.crx'
25+
].join(' && ')
26+
}
1827
}
1928
});
2029

2130
grunt.loadNpmTasks('grunt-contrib-jshint');
2231
grunt.loadNpmTasks('grunt-contrib-jasmine');
32+
grunt.loadNpmTasks('grunt-run');
2333

2434
grunt.registerTask('default', ['jshint', 'jasmine']);
2535
grunt.registerTask('test', ['jshint', 'jasmine']);
2636

37+
//TODO: Add Jasmine tests to build task
38+
grunt.registerTask('build', ['jshint', 'run:crxmake']);
39+
2740
};

crxmake.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash -e
2+
#
3+
# Purpose: Pack a Chromium extension directory into crx format
4+
5+
if test $# -ne 2; then
6+
echo "Usage: crxmake.sh <extension dir> <pem path>"
7+
exit 1
8+
fi
9+
10+
dir=$1
11+
key=$2
12+
name=$(basename "$dir")
13+
crx="$name.crx"
14+
pub="$name.pub"
15+
sig="$name.sig"
16+
zip="$name.zip"
17+
trap 'rm -f "$pub" "$sig" "$zip"' EXIT
18+
19+
# zip up the crx dir
20+
cwd=$(pwd -P)
21+
(cd "$dir" && zip -qr -9 -X "$cwd/$zip" .)
22+
23+
# signature
24+
openssl sha1 -sha1 -binary -sign "$key" < "$zip" > "$sig"
25+
26+
# public key
27+
openssl rsa -pubout -outform DER < "$key" > "$pub" 2>/dev/null
28+
29+
byte_swap () {
30+
# Take "abcdefgh" and return it as "ghefcdab"
31+
echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}"
32+
}
33+
34+
crmagic_hex="4372 3234" # Cr24
35+
version_hex="0200 0000" # 2
36+
pub_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$pub" | awk '{print $5}')))
37+
sig_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$sig" | awk '{print $5}')))
38+
(
39+
echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p
40+
cat "$pub" "$sig" "$zip"
41+
) > "$crx"
42+
echo "Wrote $crx"

dist/devtools-solidus-0.1.0.crx

2.79 MB
Binary file not shown.
File renamed without changes.

bower.json renamed to extension/bower.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"Eric Lanehart <eric@sparkart.com>"
88
],
99
"description": "Adds Solidus debugging tools to the Chrome Developer Tools.",
10-
"main": "views/devpanel.html",
10+
"main": "app/devpanel.html",
1111
"moduleType": [
1212
"node"
1313
],
@@ -29,7 +29,8 @@
2929
"bootstrap": "~3.2.0",
3030
"Inspector-JSON": "SparkartGroupInc/Inspector-JSON#e6bec9fe4cc7551cd46f44bafed6891620a5e47d",
3131
"bootstrap-vertical-tabs": "~1.1.0",
32-
"jquery-ui": "~1.11.0"
32+
"jquery-ui": "~1.11.0",
33+
"socket.io-client": "^1.0.6"
3334
},
3435
"resolutions": {
3536
"bootstrap": "~3.2.0"
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
<html>
33
<head>
44

5-
<link rel="stylesheet" href="../bower_components/jquery-ui/themes/smoothness/jquery-ui.css">
5+
<link rel="stylesheet" href="bower_components/jquery-ui/themes/smoothness/jquery-ui.css">
66

7-
<script src="../bower_components/jquery/dist/jquery.min.js"></script>
8-
<script src="../bower_components/jquery-ui/jquery-ui.js"></script>
9-
<script src="../node_modules/socket.io-client/socket.io.js"></script>
7+
<script src="bower_components/jquery/dist/jquery.min.js"></script>
8+
<script src="bower_components/jquery-ui/jquery-ui.js"></script>
9+
<script src="bower_components/socket.io-client/socket.io.js"></script>
1010
<script src="devpanel.js"></script>
11-
<script src="../bower_components/Inspector-JSON/inspector-json.js"></script>
12-
<script src="../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
11+
<script src="bower_components/Inspector-JSON/inspector-json.js"></script>
12+
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
1313

14-
<link href="../bower_components/bootstrap/dist/css/bootstrap.min.css" media="all" rel="stylesheet" type="text/css">
15-
<link href="../bower_components/bootstrap-vertical-tabs/bootstrap.vertical-tabs.min.css" media="all" rel="stylesheet" type="text/css">
14+
<link href="bower_components/bootstrap/dist/css/bootstrap.min.css" media="all" rel="stylesheet" type="text/css">
15+
<link href="bower_components/bootstrap-vertical-tabs/bootstrap.vertical-tabs.min.css" media="all" rel="stylesheet" type="text/css">
1616
<link href="devpanel.css" media="all" rel="stylesheet" type="text/css">
1717
</head>
1818
<body>
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)