Skip to content

Commit

Permalink
Refactor release and publish tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
simonepri committed Nov 30, 2017
1 parent 980d568 commit e9a322d
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 33 deletions.
9 changes: 1 addition & 8 deletions gulp/tasks/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const maps = require('../maps');
* Generates one map for each different resolution available of the maps in the
* maps folder.
*/
gulp.task('simplify', async () => {
gulp.task('compress', async () => {
for (const map of maps) {
const bar = utils.processProgress(map, Object.keys(sizes).length);

Expand All @@ -40,10 +40,3 @@ gulp.task('simplify', async () => {
}
}
});

/**
* Execute the whole compress process.
*/
gulp.task('compress', gulp.series(
'simplify',
));
46 changes: 46 additions & 0 deletions gulp/tasks/npm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

const path = require('path');
const execa = require('execa');

const gulp = require('gulp');
const gutil = require('gulp-util');

const Confirm = require('prompt-confirm');

const folders = require('../folders');

const sizes = require('../resolutions');
const maps = require('../maps');

/**
* Publish on npm.
*/
gulp.task('npm', async () => {
let ans;
const pkn = maps.length * Object.keys(sizes).length;
await new Confirm('Are you sure to want to publish all the ' + pkn + ' npm packages?')
.run().then(answer => {
ans = answer;
});

if (!ans) {
gutil.log('Release process interrupted!');
return;
}

for (const map of maps) {
const mapDir = path.join(folders.pkgsDir, 'npm', map);
for (const size of Object.keys(sizes)) {
gutil.log('Publishing @geo-maps/' + [map, size].join('-'));

const packageDir = path.join(mapDir, size);
const cmd = 'npm pack --access public';
const proc = execa.shell(cmd, {cwd: packageDir});
proc.stdout.pipe(process.stdout);
process.stdin.pipe(proc.stdin);
// eslint-disable-next-line no-await-in-loop
await proc;
}
}
});
9 changes: 5 additions & 4 deletions gulp/tasks/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ gulp.task('packages', async () => {
await fs.ensureDir(folders.pkgsDir);
const npmDir = path.join(folders.pkgsDir, 'npm');

await fs.copy(folders.buildDir, npmDir);

const managers = ['npm'];

for (const manager of managers) {
for (const map of maps) {
const bar = utils.processProgress(map, Object.keys(sizes).length);
const bar = utils.processProgress([manager, map].join('-'), Object.keys(sizes).length);

const tplMapDir = path.join(folders.tplDir, manager, map);
for (const size of Object.keys(sizes)) {
const buildMapDir = path.join(folders.buildDir, map, size);
const outMapDir = path.join(npmDir, map, size);

// eslint-disable-next-line no-await-in-loop
await fs.copy(tplMapDir, outMapDir);
// eslint-disable-next-line no-await-in-loop
await fs.copy(buildMapDir, outMapDir);

const replOpts = {
to: size,
Expand All @@ -54,7 +55,7 @@ gulp.task('packages', async () => {
// eslint-disable-next-line no-await-in-loop
await replace(replOpts);

bar();
bar.tick();
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions gulp/tasks/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const gulp = require('gulp');

/**
* Execute the whole publish process.
*/
gulp.task('publish', gulp.series(
'packages',
'npm'
));
11 changes: 11 additions & 0 deletions gulp/tasks/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const gulp = require('gulp');

/**
* Execute the whole release process.
*/
gulp.task('release', gulp.series(
'artifacts',
'upload'
));
29 changes: 29 additions & 0 deletions gulp/tasks/upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const path = require('path');
const version = require('project-version');

const gulp = require('gulp');
const release = require('gulp-github-release');

const folders = require('../folders');

/**
* Upload artifacts on GitHub
*/
gulp.task('upload', () => {
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;

if (!GITHUB_TOKEN) {
throw new Error('Environment variable GITHUB_TOKEN is required for GitHub releases.');
}
gulp.src(path.join(folders.distDir, '*'))
.pipe(
release({
token: GITHUB_TOKEN,
name: 'Release ' + version,
draft: true,
manifest: require('../../package.json')
})
);
});
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
"app-root-path": "^2.0.1",
"del": "^3.0.0",
"download": "^6.2.5",
"execa": "^0.8.0",
"fs-extra": "^4.0.2",
"gulp": "github:gulpjs/gulp#4.0",
"gulp-github-release": "^1.2.1",
"gulp-util": "^3.0.8",
"mapshaper": "^0.4.57",
"osm-countries": "^1.0.1",
"osm-geojson": "^0.6.0",
"pify": "^3.0.0",
"progress": "^2.0.0",
"project-version": "^1.0.0",
"release-it": "^4.4.1",
"prompt-confirm": "^1.2.0",
"replace-in-files": "^1.1.0",
"require-dir": "^0.3.2",
"undertaker-forward-reference": "^1.0.2",
Expand All @@ -31,8 +34,8 @@
"gulp": "node --expose-gc --max-old-space-size=65536 ./node_modules/.bin/gulp",
"build": "npm run gulp build",
"previews": "npm run gulp previews",
"release": "npm run gulp artifacts&& release-it",
"publish": "npm run gulp packages&& bash publish.sh"
"release": "npm run gulp release",
"publish": "npm run gulp publish"
},
"repository": {
"type": "git",
Expand Down
18 changes: 0 additions & 18 deletions publish.sh

This file was deleted.

0 comments on commit e9a322d

Please sign in to comment.