Skip to content

Commit

Permalink
Merge pull request #52 from bcho/wip/coffee
Browse files Browse the repository at this point in the history
使用 coffeescript 重写了脚本, v0.5.0
  • Loading branch information
bcho committed Jun 27, 2014
2 parents c67ae50 + aa559e4 commit d64fa04
Show file tree
Hide file tree
Showing 38 changed files with 1,670 additions and 1,390 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
*~
*pyc

converter.py
ext/
*.pem
gdut-library-helper.*
!*.gm.js
!*.crx

venv/
static/
node_modules/
dist/
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "gm2chrome"]
path = gm2chrome
url = git@github.com:bcho/gm2chrome.git
url = https://github.com/bcho/gm2chrome.git
61 changes: 61 additions & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module.exports = (grunt) ->
grunt.initConfig
# Package meta

pkg: grunt.file.readJSON 'package.json'
srcDir: './src'
buildDir: './dist'
coffeeCompiledDir: '<%= buildDir %>/cjs'

# Tasks Settings

coffee:
build:
options:
# Remove unnecessary function call wrap.
bare: true
expand: true
flattern: true
cwd: '<%= srcDir %>'
src: ['**/*.coffee']
dest: '<%= coffeeCompiledDir %>'
ext: '.js'

browserify:
build:
files:
'<%= buildDir %>/<%= pkg.main %>': ['<%= coffeeCompiledDir %>/**/*.js']

shell:
convert:
command: 'make convert_crx'

watch:
scripts:
files: ['<%= srcDir %>/**/*.coffee']
tasks: ['shell:convert']

clean:
build: ['<%= buildDir %>']

grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-browserify'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-shell'

# Compile script with coffee & browserify
grunt.registerTask 'compile', [
'coffee:build'
'browserify:build'
]

grunt.registerTask 'default', [
'clean:build'
'compile'
]

grunt.registerTask 'develop', [
'default'
'watch'
]
53 changes: 0 additions & 53 deletions Gruntfile.js

This file was deleted.

58 changes: 34 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
.PHONY: clean
.PHONY: clean main combile_js build_js convert_crx build_crx

name=gdut-library-helper
extension_src_path=ext
converter=gm2chrome/converter.py
# get the chrome in your machine
chrome=`ls /usr/bin | grep 'chrom' | head -1`
SCRIPT_NAME=gdut-library-helper
JS_NAME=$(SCRIPT_NAME).js
GM_SCRIPT_NAME=$(SCRIPT_NAME).gm.js
CRX_NAME=$(SCRIPT_NAME).crx
CRX_PEM=$(SCRIPT_NAME).pem

build: grunt convert packit
BUILD_DIR=`pwd`/dist
JS_BUILD_SCRIPT=`pwd`/dist/$(JS_NAME)
CRX_BUILD_DIR=$(BUILD_DIR)/crx

dev: convert packit
GM_CONVERTER=python3 `pwd`/gm2chrome/converter.py
CHROME=/usr/bin/chromium
GRUNT=grunt

grunt:
grunt default

convert:
python ${converter} ${name}.js
main: build_crx build_js

zipit:
zip ${name}.zip ${extension_src_path}/*

packit:
if [ -a ${name}.pem ]; \
# 打包脚本成 crx 格式
build_crx: $(CRX_NAME) convert_crx
if [ -a $(CRX_PEM) ]; \
then \
${chrome} --pack-extension=${extension_src_path} --pack-extension-key=${name}.pem; \
$(CHROME) --pack-extension=$(CRX_BUILD_DIR) --pack-extension-key=$(CRX_PEM); \
else \
${chrome} --pack-extension=${extension_src_path}; \
mv -f ${extension_src_path}.pem ${name}.pem; \
$(CHROME) --pack-extension=$(CRX_BUILD_DIR); \
mv -f ${CRX_BUILD_DIR}.pem $(CRX_PEM); \
fi;
mv -f ${extension_src_path}.crx ${name}.crx
mv -f ${CRX_BUILD_DIR}.crx $(CRX_NAME)

clean:
rm -f *.zip
rm -f ${name}.js
rm -f *.map

# 调用 ``gm2chrome`` 脚本将油猴脚本转换成标准的 chrome 插件脚本
convert_crx: compile_js
$(GM_CONVERTER) $(JS_BUILD_SCRIPT) $(CRX_BUILD_DIR)


# 打包脚本为油猴脚本
build_js: compile_js
cp $(JS_BUILD_SCRIPT) $(GM_SCRIPT_NAME)


# 使用 ``browserify`` 编译脚本
compile_js: $(BUILD_JS)
$(GRUNT)
Loading

0 comments on commit d64fa04

Please sign in to comment.