├── .gitignore
├── .jshintrc
├── README.md
├── index.js
├── karma.conf.js
├── package-lock.json
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | node_modules/
3 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "bitwise": false, // Prohibit bitwise operators (&, |, ^, etc.).
3 | "browser": true, // Standard browser globals e.g. `window`, `document`.
4 | "camelcase": false, // Permit only camelcase for `var` and `object indexes`.
5 | "curly": true, // Require {} for every new block or scope.
6 | "devel": false, // Allow development statements e.g. `console.log();`.
7 | "eqeqeq": true, // Require triple equals i.e. `===`.
8 | "esnext": true, // Allow ES.next specific features such as `const` and `let`.
9 | "freeze": true, // Forbid overwriting prototypes of native objects such as Array, Date and so on.
10 | "immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
11 | "indent": 2, // Specify indentation spacing
12 | "latedef": true, // Prohibit variable use before definition.
13 | "newcap": false, // Require capitalization of all constructor functions e.g. `new F()`.
14 | "noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`.
15 | "node": true, // Enable globals available when code is running inside of the NodeJS runtime environment.
16 | "noempty": true, // Prohibit use of empty blocks.
17 | "nonew": true, // Prohibits the use of constructor functions for side-effects
18 | "quotmark": "single", // Define quotes to string values.
19 | "regexp": true, // Prohibit `.` and `[^...]` in regular expressions.
20 | "smarttabs": false, // Supress warnings about mixed tabs and spaces
21 | "strict": true, // Require `use strict` pragma in every file.
22 | "trailing": true, // Prohibit trailing whitespaces.
23 | "undef": true, // Require all non-global variables be declared before they are used.
24 | "unused": true, // Warn unused variables.
25 |
26 | "maxparams": 4, // Maximum number of parameters for a function
27 | "maxstatements": 15, // Maximum number of statements in a function
28 | "maxcomplexity": 6, // Cyclomatic complexity (http://en.wikipedia.org/wiki/Cyclomatic_complexity)
29 | "maxdepth": 4, // Maximum depth of nested control structures
30 | "maxlen": 120, // Maximum number of cols in a line
31 | "multistr": true, // Allow use of multiline EOL escaping
32 |
33 | "predef": [ // Extra globals.
34 | "after",
35 | "afterEach",
36 | "before",
37 | "beforeEach",
38 | "define",
39 | "describe",
40 | "exports",
41 | "it",
42 | "module",
43 | "require"
44 | ]
45 | }
46 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # bitcore-build-axe
2 |
3 | A helper to add tasks to gulp.
4 |
5 | ## Getting started
6 |
7 | Install with:
8 |
9 | ```sh
10 | npm install bitcore-build-axe
11 | ```
12 |
13 | and use and require in your gulp file:
14 |
15 | ```javascript
16 | var gulp = require('gulp');
17 | var bitcoreTasks = require('bitcore-build-axe');
18 |
19 | bitcoreTasks('submodule');
20 | gulp.task('default', ['lint', 'test', 'browser', 'coverage']);
21 | ```
22 |
23 | ### Notes
24 |
25 | * There's no default task to allow for each submodule to set up their own configuration
26 | * If the module is node-only, avoid adding the browser tasks with:
27 | ```javascript
28 | var bitcoreTasks = require('bitcore-build-axe');
29 | bitcoreTasks('submodule', {skipBrowsers: true});
30 | ```
31 |
32 | ## Contributing
33 |
34 | See [CONTRIBUTING.md](https://github.com/bitpay/bitcore) on the main bitcore repo for information about how to contribute.
35 |
36 | ## License
37 |
38 | Code released under [the MIT license](https://github.com/bitpay/bitcore/blob/master/LICENSE).
39 |
40 | Copyright 2015 BitPay, Inc. Bitcore is a trademark maintained by BitPay, Inc.
41 |
42 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @file gulpfile.js
3 | *
4 | * Defines tasks that can be run on gulp.
5 | *
6 | * Summary:
7 | * - `test` - runs all the tests on node and the browser (mocha and karma)
8 | *
9 | * - `test:node`
10 | *
- `test:node:nofail` - internally used for watching (due to bug on gulp-mocha)
11 | *
- `test:browser`
12 | *
`
13 | * - `watch:test` - watch for file changes and run tests
14 | *
15 | * - `watch:test:node`
16 | *
- `watch:test:browser`
17 | *
`
18 | * - `browser` - generate files needed for browser (browserify)
19 | *
20 | * - `browser:uncompressed` - build uncomprssed browser bundle (`bitcore-*.js`)
21 | *
- `browser:compressed` - build compressed browser bundle (`bitcore-*.min.js`)
22 | *
- `browser:maketests` - build `tests.js`, needed for testing without karma
23 | *
`
24 | * - `lint` - run `jshint`
25 | *
- `coverage` - run `istanbul` with mocha to generate a report of test coverage
26 | *
- `coveralls` - updates coveralls info
27 | *
- `release` - automates release process (only for maintainers)
28 | *
29 | */
30 | 'use strict';
31 |
32 | var gulp = require('gulp');
33 |
34 | var coveralls = require('gulp-coveralls');
35 | var gutil = require('gulp-util');
36 | var jshint = require('gulp-jshint');
37 | var mocha = require('gulp-mocha');
38 | var rename = require('gulp-rename');
39 | var runsequence = require('run-sequence');
40 | runsequence.use(gulp);
41 | var shell = require('gulp-shell');
42 | var uglify = require('gulp-uglify');
43 | var bump = require('gulp-bump');
44 | var git = require('gulp-git');
45 | var fs = require('fs');
46 |
47 | function ignoreerror() {
48 | /* jshint ignore:start */ // using `this` in this context is weird
49 | this.emit('end');
50 | /* jshint ignore:end */
51 | }
52 |
53 | function startGulp(name, opts) {
54 |
55 | opts = opts || {};
56 | var browser = !opts.skipBrowser;
57 | var fullname = name ? 'bitcore-' + name : 'bitcore';
58 | var files = ['lib/**/*.js'];
59 | var tests = ['test/**/*.js'];
60 | var alljs = files.concat(tests);
61 |
62 | var buildPath = './node_modules/bitcore-build-axe/';
63 | var buildModulesPath = buildPath + 'node_modules/';
64 | var buildBinPath = buildPath + 'node_modules/.bin/';
65 |
66 | var browserifyPath = buildBinPath + 'browserify';
67 | var karmaPath = buildBinPath + 'karma';
68 | var platoPath = buildBinPath + 'plato';
69 | var istanbulPath = buildBinPath + 'istanbul';
70 | var mochaPath = buildBinPath + '_mocha';
71 |
72 | // newer version of node? binaries are in lower level of node_module path
73 | if (!fs.existsSync(browserifyPath)) {
74 | browserifyPath = './node_modules/.bin/browserify';
75 | }
76 |
77 | if (!fs.existsSync(karmaPath)) {
78 | karmaPath = './node_modules/.bin/karma';
79 | }
80 |
81 | if (!fs.existsSync(istanbulPath)) {
82 | istanbulPath = './node_modules/.bin/istanbul';
83 | }
84 |
85 | if (!fs.existsSync(platoPath)) {
86 | platoPath = './node_modules/.bin/plato';
87 | }
88 |
89 | if (!fs.existsSync(mochaPath)) {
90 | mochaPath = './node_modules/.bin/_mocha';
91 | }
92 |
93 | /**
94 | * testing
95 | */
96 | var testmocha = function() {
97 | return gulp.src(tests).pipe(mocha({
98 | reporter: 'spec'
99 | }));
100 | };
101 |
102 | var testkarma = shell.task([
103 | karmaPath + ' start ' + buildPath + 'karma.conf.js'
104 | ]);
105 |
106 | gulp.task('test:node', testmocha);
107 |
108 | gulp.task('test:node:nofail', function() {
109 | return testmocha().on('error', ignoreerror);
110 | });
111 |
112 | gulp.task('test:browser', ['browser:uncompressed', 'browser:maketests'], testkarma);
113 |
114 | if (browser) {
115 | gulp.task('test', function(callback) {
116 | runsequence(['test:node'], ['test:browser'], callback);
117 | });
118 | } else {
119 | gulp.task('test', ['test:node']);
120 | }
121 |
122 | gulp.task('noop', function() {});
123 |
124 | /**
125 | * file generation
126 | */
127 | if (browser) {
128 |
129 | var browserifyCommand;
130 |
131 | if (name !== 'lib') {
132 | browserifyCommand = browserifyPath + ' --require ./index.js:' + fullname + ' --external bitcore-lib-axe -o ' + fullname + '.js';
133 | } else {
134 | browserifyCommand = browserifyPath + ' --require ./index.js:bitcore-lib-axe -o bitcore-lib-axe.js';
135 | }
136 |
137 | gulp.task('browser:uncompressed', shell.task([
138 | browserifyCommand
139 | ]));
140 |
141 | gulp.task('browser:compressed', ['browser:uncompressed'], function() {
142 | return gulp.src(fullname + '.js')
143 | .pipe(uglify({
144 | mangle: true,
145 | compress: true
146 | }))
147 | .pipe(rename(fullname + '.min.js'))
148 | .pipe(gulp.dest('.'))
149 | .on('error', gutil.log);
150 | });
151 |
152 | gulp.task('browser:maketests', shell.task([
153 | 'find test/ -type f -name "*.js" | xargs ' + browserifyPath + ' -t brfs -o tests.js'
154 | ]));
155 |
156 | gulp.task('browser', function(callback) {
157 | runsequence(['browser:compressed'], callback);
158 | });
159 | }
160 |
161 | /**
162 | * code quality and documentation
163 | */
164 |
165 | gulp.task('lint', function() {
166 | return gulp.src(alljs)
167 | .pipe(jshint())
168 | .pipe(jshint.reporter('default'));
169 | });
170 |
171 | gulp.task('plato', shell.task([platoPath + ' -d report -r -l .jshintrc -t ' + fullname + ' lib']));
172 |
173 | gulp.task('coverage', shell.task([istanbulPath + ' cover ' + mochaPath + ' -- --recursive']));
174 |
175 | gulp.task('coveralls', ['coverage'], function() {
176 | gulp.src('coverage/lcov.info').pipe(coveralls());
177 | });
178 |
179 | /**
180 | * watch tasks
181 | */
182 |
183 | gulp.task('watch:test', function() {
184 | // todo: only run tests that are linked to file changes by doing
185 | // something smart like reading through the require statements
186 | return gulp.watch(alljs, ['test']);
187 | });
188 |
189 | gulp.task('watch:test:node', function() {
190 | // todo: only run tests that are linked to file changes by doing
191 | // something smart like reading through the require statements
192 | return gulp.watch(alljs, ['test:node']);
193 | });
194 |
195 | if (browser) {
196 | gulp.task('watch:test:browser', function() {
197 | // todo: only run tests that are linked to file changes by doing
198 | // something smart like reading through the require statements
199 | return gulp.watch(alljs, ['test:browser']);
200 | });
201 | }
202 |
203 | gulp.task('watch:coverage', function() {
204 | // todo: only run tests that are linked to file changes by doing
205 | // something smart like reading through the require statements
206 | return gulp.watch(alljs, ['coverage']);
207 | });
208 |
209 | gulp.task('watch:lint', function() {
210 | // todo: only lint files that are linked to file changes by doing
211 | // something smart like reading through the require statements
212 | return gulp.watch(alljs, ['lint']);
213 | });
214 |
215 | if (browser) {
216 | gulp.task('watch:browser', function() {
217 | return gulp.watch(alljs, ['browser']);
218 | });
219 | }
220 |
221 | /**
222 | * Release automation
223 | */
224 |
225 | gulp.task('release:install', function() {
226 | return shell.task([
227 | 'npm install',
228 | ]);
229 | });
230 |
231 | var releaseFiles = ['./package.json'];
232 | if (browser) {
233 | releaseFiles.push('./bower.json');
234 | }
235 |
236 | var bump_version = function(importance) {
237 | return gulp.src(releaseFiles)
238 | .pipe(bump({
239 | type: importance
240 | }))
241 | .pipe(gulp.dest('./'));
242 | };
243 |
244 | var tempBranch = 'releases/' + new Date().getTime() + '-build';
245 | gulp.task('release:checkout-releases', function(cb) {
246 | git.branch(tempBranch, {
247 | args: ''
248 | }, function() {
249 | git.checkout(tempBranch, {
250 | args: ''
251 | }, cb);
252 | });
253 | });
254 |
255 | gulp.task('release:cleanup', function(cb) {
256 | git.branch(tempBranch, {
257 | args: '-D'
258 | }, cb);
259 | });
260 |
261 | gulp.task('release:checkout-master', function(cb) {
262 | git.checkout('master', {
263 | args: ''
264 | }, cb);
265 | });
266 |
267 | gulp.task('release:sign-built-files', shell.task([
268 | 'gpg --yes --out ' + fullname + '.js.sig --detach-sig ' + fullname + '.js',
269 | 'gpg --yes --out ' + fullname + '.min.js.sig --detach-sig ' + fullname + '.min.js'
270 | ]));
271 |
272 | var buildFiles = ['./package.json'];
273 | var signatureFiles = [];
274 | if (browser) {
275 | buildFiles.push(fullname + '.js');
276 | buildFiles.push(fullname + '.js.sig');
277 | buildFiles.push(fullname + '.min.js');
278 | buildFiles.push(fullname + '.min.js.sig');
279 |
280 | buildFiles.push('./bower.json');
281 |
282 | signatureFiles.push(fullname + '.js.sig');
283 | signatureFiles.push(fullname + '.min.js.sig');
284 | }
285 | var addFiles = function() {
286 | var pjson = require('../../package.json');
287 | return gulp.src(buildFiles)
288 | .pipe(git.add({
289 | args: '-f'
290 | }));
291 | };
292 |
293 | var buildCommit = function() {
294 | var pjson = require('../../package.json');
295 | return gulp.src(buildFiles)
296 | .pipe(git.commit('Build: ' + pjson.version, {
297 | args: ''
298 | }));
299 | };
300 |
301 | gulp.task('release:add-signed-files', ['release:sign-built-files'], addFiles);
302 | gulp.task('release:add-built-files', addFiles);
303 |
304 | if (browser) {
305 | gulp.task('release:build-commit', [
306 | 'release:add-signed-files'
307 | ], buildCommit);
308 | } else {
309 | gulp.task('release:build-commit', [
310 | 'release:add-built-files'
311 | ], buildCommit);
312 | }
313 |
314 | gulp.task('release:version-commit', function() {
315 | var pjson = require('../../package.json');
316 | return gulp.src(releaseFiles)
317 | .pipe(git.commit('Bump package version to ' + pjson.version, {
318 | args: ''
319 | }));
320 | });
321 |
322 | gulp.task('release:push', function(cb) {
323 | git.push('bitpay', 'master', {
324 | args: ''
325 | }, cb);
326 | });
327 |
328 | gulp.task('release:push-tag', function(cb) {
329 | var pjson = require('../../package.json');
330 | var name = 'v' + pjson.version;
331 | git.tag(name, 'Release ' + name, function() {
332 | git.push('bitpay', name, cb);
333 | });
334 | });
335 |
336 | gulp.task('release:publish', shell.task([
337 | 'npm publish'
338 | ]));
339 |
340 |
341 | // requires https://hub.github.com/
342 | var release = function(importance, cb) {
343 | var bumper = 'release:bump:' + importance;
344 | return runsequence(
345 | // Checkout the release temporal branch
346 | 'release:checkout-releases',
347 | // Run npm install
348 | 'release:install',
349 | // Run tests with gulp test
350 | 'test',
351 | // Update package.json and bower.json
352 | bumper,
353 | // build browser files
354 | browser ? 'browser' : 'noop',
355 | // Commit
356 | 'release:build-commit',
357 | // Run git push bitpay $VERSION
358 | 'release:push-tag',
359 | // Run npm publish
360 | 'release:publish',
361 | // Checkout the `master` branch
362 | 'release:checkout-master',
363 | // Bump package.json and bower.json, again
364 | bumper,
365 | // Version commit with no binary files to master
366 | 'release:version-commit',
367 | // Push to master
368 | 'release:push',
369 | // remove release branch
370 | 'release:cleanup',
371 | cb);
372 | };
373 |
374 | ['patch', 'minor', 'major'].forEach(function(importance) {
375 | gulp.task('release:' + importance, function(cb) {
376 | release(importance, cb);
377 | });
378 | gulp.task('release:bump:' + importance, function() {
379 | bump_version(importance);
380 | });
381 | });
382 | gulp.task('release', ['release:patch']);
383 |
384 |
385 |
386 | }
387 |
388 | module.exports = startGulp;
389 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // karma.conf.js
4 | module.exports = function(config) {
5 |
6 | config.set({
7 | browsers: ['PhantomJS'],
8 | frameworks: ['mocha'],
9 | singleRun: true,
10 | files: [
11 | './../../tests.js' // project root
12 | ],
13 | plugins: [
14 | 'karma-mocha',
15 | 'karma-phantomjs-launcher'
16 | ]
17 | });
18 |
19 | };
20 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "bitcore-build-axe",
3 | "version": "0.9.1",
4 | "description": "A helper for common tasks to build bitcore-axe modules'",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "gulp test"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git://github.com/axerunners/bitcore-build-axe"
12 | },
13 | "keywords": [
14 | "bitcore"
15 | ],
16 | "contributors": [
17 | {
18 | "name": "Esteban Ordano",
19 | "email": "esteban@bitpay.com"
20 | },
21 | {
22 | "name": "Manuel Araoz",
23 | "email": "maraoz@bitpay.com"
24 | },
25 | {
26 | "name": "Braydon Fuller",
27 | "email": "braydon@bitpay.com"
28 | },
29 | {
30 | "name": "Yemel Jardi",
31 | "email": "yemel@bitpay.com"
32 | },
33 | {
34 | "name": "Matias Alejo Garcia",
35 | "email": "ematiu@gmail.com"
36 | }
37 | ],
38 | "license": "MIT",
39 | "bugs": {
40 | "url": "https://github.com/axerunners/bitcore-build-axe/issues"
41 | },
42 | "homepage": "https://github.com/axerunners/bitcore-build-axe",
43 | "dependencies": {
44 | "brfs": "^1.4.3",
45 | "browserify": "^13.1.1",
46 | "chai": "^3.5.0",
47 | "gulp": "^3.9.1",
48 | "gulp-bump": "^2.7.0",
49 | "gulp-coveralls": "^0.1.4",
50 | "gulp-git": "^2.0.1",
51 | "gulp-jshint": "^2.0.4",
52 | "gulp-mocha": "^4.1.0",
53 | "gulp-rename": "^1.2.2",
54 | "gulp-shell": "^0.6.3",
55 | "gulp-uglify": "^2.1.0",
56 | "gulp-util": "^3.0.8",
57 | "istanbul": "^0.4.5",
58 | "karma": "^1.7.1",
59 | "karma-detect-browsers": "^2.2.4",
60 | "karma-mocha": "^1.3.0",
61 | "karma-phantomjs-launcher": "^1.0.4",
62 | "lodash": "^4.17.4",
63 | "mocha": "^3.2.0",
64 | "plato": "^1.7.0",
65 | "run-sequence": "^1.2.2"
66 | }
67 | }
68 |
--------------------------------------------------------------------------------