-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using grunt / npm as the build tool of choice.
Added the ability to automatically create chrome extension packages (for circleci) Added some structure to the project ;)
- Loading branch information
Marcel Pociot
committed
Mar 24, 2016
1 parent
58e4348
commit d4ede82
Showing
27 changed files
with
1,268 additions
and
40,121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
key.pem | ||
node_modules | ||
build/*.crx | ||
build/unpacked-dev | ||
build/unpacked-prod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
module.exports = function(grunt) { | ||
|
||
var pkg = grunt.file.readJSON('package.json'); | ||
var mnf = grunt.file.readJSON('code/manifest.json'); | ||
|
||
var fileMaps = { browserify: {}, uglify: {} }; | ||
var file, files = grunt.file.expand({cwd:'code/js'}, ['*.js']); | ||
for (var i = 0; i < files.length; i++) { | ||
file = files[i]; | ||
fileMaps.browserify['build/unpacked-dev/js/' + file] = 'code/js/' + file; | ||
fileMaps.uglify['build/unpacked-prod/js/' + file] = 'build/unpacked-dev/js/' + file; | ||
} | ||
|
||
// | ||
// config | ||
// | ||
|
||
grunt.initConfig({ | ||
|
||
clean: ['build/unpacked-dev', 'build/unpacked-prod', 'build/*.crx'], | ||
|
||
mkdir: { | ||
unpacked: { options: { create: ['build/unpacked-dev', 'build/unpacked-prod'] } }, | ||
js: { options: { create: ['build/unpacked-dev/js'] } } | ||
}, | ||
|
||
jshint: { | ||
options: grunt.file.readJSON('lint-options.json'), // see http://www.jshint.com/docs/options/ | ||
all: { src: ['package.json', 'lint-options.json', 'Gruntfile.js', 'code/**/*.js', | ||
'code/**/*.json', '!code/js/libs/*'] } | ||
}, | ||
|
||
copy: { | ||
main: { files: [ { | ||
expand: true, | ||
cwd: 'code/', | ||
src: ['**', '!js/**', '!**/*.md'], | ||
dest: 'build/unpacked-dev/' | ||
} ] }, | ||
prod: { files: [ { | ||
expand: true, | ||
cwd: 'build/unpacked-dev/', | ||
src: ['**', '!js/*.js'], | ||
dest: 'build/unpacked-prod/' | ||
} ] }, | ||
artifact: { files: [ { | ||
expand: true, | ||
cwd: 'build/', | ||
src: [pkg.name + '-' + pkg.version + '.crx'], | ||
dest: process.env.CIRCLE_ARTIFACTS | ||
} ] } | ||
}, | ||
|
||
crx: { | ||
package: { | ||
"src": "build/unpacked-prod/**/*", | ||
"dest": "build/", | ||
} | ||
}, | ||
|
||
browserify: { | ||
build: { | ||
files: fileMaps.browserify, | ||
options: { browserifyOptions: { | ||
debug: true, // for source maps | ||
} } | ||
} | ||
}, | ||
|
||
uglify: { | ||
min: { files: fileMaps.uglify } | ||
}, | ||
|
||
watch: { | ||
js: { | ||
files: ['package.json', 'lint-options.json', 'Gruntfile.js', 'code/**/*.js', | ||
'code/**/*.json', '!code/js/libs/*'], | ||
tasks: ['test'] | ||
} | ||
} | ||
|
||
}); | ||
|
||
grunt.loadNpmTasks('grunt-contrib-clean'); | ||
grunt.loadNpmTasks('grunt-mkdir'); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-copy'); | ||
grunt.loadNpmTasks('grunt-browserify'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.loadNpmTasks('grunt-crx'); | ||
|
||
// | ||
// custom tasks | ||
// | ||
|
||
grunt.registerTask( | ||
'manifest', 'Extend manifest.json with extra fields from package.json', | ||
function() { | ||
var fields = ['name', 'version', 'description']; | ||
for (var i = 0; i < fields.length; i++) { | ||
var field = fields[i]; | ||
mnf[field] = pkg[field]; | ||
} | ||
grunt.file.write('build/unpacked-dev/manifest.json', JSON.stringify(mnf, null, 4) + '\n'); | ||
grunt.log.ok('manifest.json generated'); | ||
} | ||
); | ||
|
||
grunt.registerTask( | ||
'circleci', 'Store built extension as CircleCI arfitact', | ||
function() { | ||
if (process.env.CIRCLE_ARTIFACTS) { grunt.task.run('copy:artifact'); } | ||
else { grunt.log.ok('Not on CircleCI, skipped'); } | ||
} | ||
); | ||
|
||
// | ||
// testing-related tasks | ||
// | ||
|
||
grunt.registerTask('test', ['jshint']); | ||
grunt.registerTask('test-cont', ['test', 'watch']); | ||
|
||
// | ||
// DEFAULT | ||
// | ||
|
||
grunt.registerTask('default', ['clean', 'test', 'mkdir:unpacked', 'copy:main', 'manifest', | ||
'mkdir:js', 'browserify', 'copy:prod', 'uglify', 'crx', 'circleci']); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.