diff --git a/gulp/tasks/compress.js b/gulp/tasks/compress.js index e90359f..9e4920f 100644 --- a/gulp/tasks/compress.js +++ b/gulp/tasks/compress.js @@ -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); @@ -40,10 +40,3 @@ gulp.task('simplify', async () => { } } }); - -/** - * Execute the whole compress process. - */ -gulp.task('compress', gulp.series( - 'simplify', -)); diff --git a/gulp/tasks/npm.js b/gulp/tasks/npm.js new file mode 100644 index 0000000..2584369 --- /dev/null +++ b/gulp/tasks/npm.js @@ -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; + } + } +}); diff --git a/gulp/tasks/packages.js b/gulp/tasks/packages.js index 00f4c41..6190234 100644 --- a/gulp/tasks/packages.js +++ b/gulp/tasks/packages.js @@ -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, @@ -54,7 +55,7 @@ gulp.task('packages', async () => { // eslint-disable-next-line no-await-in-loop await replace(replOpts); - bar(); + bar.tick(); } } } diff --git a/gulp/tasks/publish.js b/gulp/tasks/publish.js new file mode 100644 index 0000000..600f631 --- /dev/null +++ b/gulp/tasks/publish.js @@ -0,0 +1,11 @@ +'use strict'; + +const gulp = require('gulp'); + +/** + * Execute the whole publish process. + */ +gulp.task('publish', gulp.series( + 'packages', + 'npm' +)); diff --git a/gulp/tasks/release.js b/gulp/tasks/release.js new file mode 100644 index 0000000..5806529 --- /dev/null +++ b/gulp/tasks/release.js @@ -0,0 +1,11 @@ +'use strict'; + +const gulp = require('gulp'); + +/** + * Execute the whole release process. + */ +gulp.task('release', gulp.series( + 'artifacts', + 'upload' +)); diff --git a/gulp/tasks/upload.js b/gulp/tasks/upload.js new file mode 100644 index 0000000..57efc3a --- /dev/null +++ b/gulp/tasks/upload.js @@ -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') + }) + ); +}); diff --git a/package.json b/package.json index eba918f..bb52739 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/publish.sh b/publish.sh deleted file mode 100644 index 4a7bc14..0000000 --- a/publish.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -printf "Are you sure to want to publish the packages [N/y]? " -read -r ans -if [[ $ans =~ ^[Yy]$ ]] -then - cd pkgs - for m in *; do - cd $m - for r in *; do - cd $r - npm publish --access public & - cd .. - done - cd .. - done -fi -wait