Skip to content

Commit 5438c4e

Browse files
jledentubenmccann
authored andcommitted
Copy dist files to root + add package/bower tasks (#202)
Copy dist files to root + add package/bower tasks
1 parent f1f0f63 commit 5438c4e

File tree

8 files changed

+564
-153
lines changed

8 files changed

+564
-153
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ custom/*
55

66
docs/index.md
77

8+
bower.json
89
bower_components/
910

1011
coverage/*
1112

1213
nbproject/*
1314
dist/
15+
chartjs-plugin-zoom.js
16+
chartjs-plugin-zoom.min.js

.npmignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/.git
2+
/.github
3+
/dist/*.zip
4+
/node_modules
5+
6+
.DS_Store
7+
.gitignore
8+
.idea
9+
.travis.yml

.travis.yml

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
language: node_js
22
node_js:
3-
- "6.2"
4-
5-
before_install:
6-
- "export CHROME_BIN=/usr/bin/google-chrome"
7-
- "export DISPLAY=:99.0"
8-
- "sh -e /etc/init.d/xvfb start"
9-
10-
before_script:
11-
- npm install
3+
- "lts/*"
124

135
script:
146
- gulp lint
7+
- gulp build
8+
- gulp package
9+
- gulp bower
1510

16-
sudo: required
17-
dist: trusty
11+
# IMPORTANT: scripts require GITHUB_AUTH_TOKEN and GITHUB_AUTH_EMAIL environment variables
12+
# IMPORTANT: scripts has to be set executables in the Git repository (error 127)
13+
# https://github.com/travis-ci/travis-ci/issues/5538#issuecomment-225025939
1814

19-
addons:
20-
firefox: latest
21-
apt:
22-
sources:
23-
- google-chrome
24-
packages:
25-
- google-chrome-stable
15+
deploy:
16+
- provider: script
17+
script: ./scripts/release.sh
18+
skip_cleanup: true
19+
on:
20+
branch: release
21+
- provider: releases
22+
api_key: $GITHUB_AUTH_TOKEN
23+
file:
24+
- "./dist/chartjs-plugin-zoom.js"
25+
- "./dist/chartjs-plugin-zoom.min.js"
26+
- "./dist/chartjs-plugin-zoom.zip"
27+
skip_cleanup: true
28+
on:
29+
tags: true
30+
- provider: npm
31+
email: $NPM_AUTH_EMAIL
32+
api_key: $NPM_AUTH_TOKEN
33+
skip_cleanup: true
34+
on:
35+
tags: true

MAINTAINING.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Maintaining
2+
3+
## Release Process
4+
5+
Chart.js relies on [Travis CI](https://travis-ci.org/) to automate the library [releases](https://github.com/chartjs/chartjs-plugin-zoom/releases).
6+
7+
### Releasing a New Version
8+
9+
1. draft release notes on [GitHub](https://github.com/chartjs/chartjs-plugin-zoom/releases/new) for the upcoming tag
10+
1. update `master` `package.json` version using [semver](https://semver.org/) semantic
11+
1. merge `master` into the `release` branch
12+
1. follow the build process on [Travis CI](https://travis-ci.org/chartjs/chartjs-plugin-zoom)
13+
14+
> **Note:** if `master` is merged in `release` with a `package.json` version that already exists, the tag creation fails and the release process is aborted.
15+
16+
### Automated Tasks
17+
18+
Merging into the `release` branch kicks off the automated release process:
19+
20+
* build of the `dist/*.js` files
21+
* `dist/*.js` are copied to the root directory
22+
* `bower.json` is generated from `package.json`
23+
* `dist/*.js` and `bower.json` are added to a detached branch
24+
* a tag is created from the `package.json` version
25+
* tag (with dist files) is pushed to GitHub
26+
27+
Creation of this tag triggers a new build:
28+
29+
* `chartjs-plugin-zoom.zip` package is generated, containing dist files and examples
30+
* `dist/*.js` and `chartjs-plugin-zoom.zip` are attached to the GitHub release (downloads)
31+
* a new npm package is published on [npmjs](https://www.npmjs.com/package/chartjs-plugin-zoom)
32+
33+
Finally, [cdnjs](https://cdnjs.com/libraries/chartjs-plugin-zoom) is automatically updated from the npm release.

gulpfile.js

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
var gulp = require('gulp'),
2-
eslint = require('gulp-eslint'),
3-
util = require('gulp-util'),
4-
htmllint = require('gulp-htmllint'),
5-
inquirer = require('inquirer'),
6-
semver = require('semver'),
7-
fs = require('fs'),
8-
{exec} = require('child_process'),
9-
package = require('./package.json');
1+
var gulp = require('gulp');
2+
var eslint = require('gulp-eslint');
3+
var file = require('gulp-file');
4+
var util = require('gulp-util');
5+
var htmllint = require('gulp-htmllint');
6+
var replace = require('gulp-replace');
7+
var streamify = require('gulp-streamify');
8+
var zip = require('gulp-zip');
9+
var inquirer = require('inquirer');
10+
var semver = require('semver');
11+
var fs = require('fs');
12+
var {exec} = require('child_process');
13+
var merge = require('merge-stream');
14+
var pkg = require('./package.json');
1015

1116
var srcDir = './src/';
1217
var srcFiles = srcDir + '**.js';
18+
var outDir = './dist/';
1319

1420
function run(bin, args, done) {
1521
var exe = '"' + process.execPath + '"';
@@ -21,27 +27,71 @@ function run(bin, args, done) {
2127
ps.on('close', () => done());
2228
}
2329

24-
gulp.task('build', buildTask);
30+
gulp.task('bower', bowerTask);
31+
gulp.task('build', gulp.series(rollupTask, copyDistFilesTask));
32+
gulp.task('package', packageTask);
2533
gulp.task('bump', bumpTask);
2634
gulp.task('lint-html', lintHtmlTask);
2735
gulp.task('lint-js', lintJsTask);
2836
gulp.task('lint', gulp.parallel('lint-html', 'lint-js'));
2937
gulp.task('watch', watchTask);
3038
gulp.task('default', gulp.parallel('lint', 'build', 'watch'));
3139

32-
function buildTask(done) {
40+
/**
41+
* Generates the bower.json manifest file which will be pushed along release tags.
42+
* Specs: https://github.com/bower/spec/blob/master/json.md
43+
*/
44+
function bowerTask() {
45+
var json = JSON.stringify({
46+
name: pkg.name,
47+
description: pkg.description,
48+
homepage: pkg.homepage,
49+
license: pkg.license,
50+
version: pkg.version,
51+
main: outDir + pkg.name + '.js'
52+
}, null, 2);
53+
54+
return file('bower.json', json, {src: true})
55+
.pipe(gulp.dest('./'));
56+
}
57+
58+
function rollupTask(done) {
3359
run('rollup/bin/rollup', ['-c'], done);
3460
}
3561

62+
/**
63+
* Copy the files from `/dist` to the root directory.
64+
* @todo remove at version 1.0
65+
*/
66+
function copyDistFilesTask() {
67+
return gulp.src(outDir + '*.js')
68+
.pipe(gulp.dest('./'));
69+
}
70+
71+
function packageTask() {
72+
return merge(
73+
// gather "regular" files landing in the package root
74+
gulp.src([outDir + '*.js', 'LICENSE.md']),
75+
76+
// since we moved the dist files one folder up (package root), we need to rewrite
77+
// samples src="../dist/ to src="../ and then copy them in the /samples directory.
78+
gulp.src('./samples/**/*', {base: '.'})
79+
.pipe(streamify(replace(/src="((?:\.\.\/)+)dist\//g, 'src="$1')))
80+
)
81+
// finally, create the zip archive
82+
.pipe(zip(pkg.name + '.zip'))
83+
.pipe(gulp.dest(outDir));
84+
}
85+
3686
/*
3787
* Usage : gulp bump
3888
* Prompts: Version increment to bump
3989
* Output: - New version number written into package.json
4090
*/
4191
function bumpTask(complete) {
42-
util.log('Current version:', util.colors.cyan(package.version));
92+
util.log('Current version:', util.colors.cyan(pkg.version));
4393
var choices = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'].map(function(versionType) {
44-
return versionType + ' (v' + semver.inc(package.version, versionType) + ')';
94+
return versionType + ' (v' + semver.inc(pkg.version, versionType) + ')';
4595
});
4696
inquirer.prompt({
4797
type: 'list',
@@ -50,13 +100,13 @@ function bumpTask(complete) {
50100
choices: choices
51101
}).then(function(res) {
52102
var increment = res.version.split(' ')[0],
53-
newVersion = semver.inc(package.version, increment);
103+
newVersion = semver.inc(pkg.version, increment);
54104

55105
// Set the new versions into the package object
56-
package.version = newVersion;
106+
pkg.version = newVersion;
57107

58108
// Write these to their own files, then build the output
59-
fs.writeFileSync('package.json', JSON.stringify(package, null, 2));
109+
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));
60110

61111
complete();
62112
});

0 commit comments

Comments
 (0)