-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
113 lines (94 loc) · 4.27 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* eslint-disable sonarjs/no-duplicate-string, jsdoc/newline-after-description, jsdoc/require-param */
/** References ...
* https://semaphoreci.com/community/tutorials/getting-started-with-gulp-js
* https://gulpjs.com/plugins/
* https://gulpjs.com/docs/en/api/concepts/
* Plugins
* https://www.npmjs.com/package/gulp-include - source file inline replacements
* https://www.npmjs.com/package/gulp-uglify - Minify
* https://www.npmjs.com/package/gulp-rename - Rename source filename on output
* https://www.npmjs.com/package/gulp-once - Only do things if files have changed
* https://www.npmjs.com/package/gulp-replace - String replacer
* https://www.npmjs.com/package/gulp-debug
*
* https://www.npmjs.com/package/gulp-concat
* https://www.npmjs.com/package/gulp-sourcemaps
* https://www.npmjs.com/package/gulp-prompt - get input from user
* https://www.npmjs.com/package/gulp-if-else
* https://www.npmjs.com/package/gulp-minify-inline
* https://www.npmjs.com/package/gulp-tap - Easily tap into a pipeline. Could replace gulp-replace
* https://www.npmjs.com/package/webpack-stream - Use WebPack with gulp
* https://www.npmjs.com/package/tinyify - runs various optimizations
*
* ❌https://www.npmjs.com/package/gulp-changed - Does not work as expected
*/
'use strict'
//#region ---- Require dependent modules ---- //
// const { src, dest, /*series,*/ watch, parallel, } = require('gulp')
// const uglify = require('gulp-uglify')
// const rename = require('gulp-rename')
// const include = require('gulp-include')
// const once = require('gulp-once')
//const prompt = require('gulp-prompt')
// const replace = require('gulp-replace')
// const debug = require('gulp-debug')
const execa = require('execa')
const fs = require('fs')
//const { promisify } = require('util')
//const dotenv = require('dotenv')
//#endregion ---- ---- ---- ---- //
//#region >>>> Vars - change as needed <<<< //
// What release/version do we want to end up with?
const release = '1.0.0'
//#endregion ------------------------------ //
/**
* TODO
* - Add text replace to ensure 2021 in (c) blocks is current year
* - Add improvements to build so that we can have a generic name in the src code as a template
*/
// print output of commands into the terminal
const stdio = 'inherit'
// @ts-ignore
const { version } = JSON.parse( fs.readFileSync('package.json') )
console.log(`Current Version: ${version}. Requested Version: ${release}`)
/** Update module version in package.json */
async function setPackageVersion() {
if (version !== release) {
// bump version without committing and tagging: npm version 4.2.1 --no-git-tag-version --allow-same-version
await execa('npm', ['version', release, '--no-git-tag-version'], {stdio})
} else {
console.log('Requested version is same as current version - nothing will change')
}
}
/** Create a new GitHub tag for a release (only if release ver # different to last committed tag) */
async function createTag(cb) {
//Get the last committed tag: git describe --tags --abbrev=0
let lastTag
try {
lastTag = (await execa('git', ['describe', '--tags', '--abbrev=0'])).stdout
} catch (e) {
lastTag = ''
}
console.log(`Last committed tag: ${lastTag}`)
// If the last committed tag is different to the required release ...
if ( lastTag.replace('v','') !== release ) {
//const commitMsg = `chore: release ${release}`
//await execa('git', ['add', '.'], { stdio })
//await execa('git', ['commit', '--message', commitMsg], { stdio })
await execa('git', ['tag', `v${release}`], { stdio })
await execa('git', ['push', '--follow-tags'], { stdio })
await execa('git', ['push', 'origin', '--tags'], { stdio })
} else {
console.log('Requested release version is same as the latest tag - not creating tag')
}
cb()
}
/** Publish to npmjs.org registry as a public package */
async function publish(cb) {
await execa('npm', ['publish', '--access', 'public'], { stdio })
cb()
}
//exports.default = series( packfe, combineHtml ) // series(runLinter,parallel(generateCSS,generateHTML),runTests)
exports.createTag = createTag
exports.publish = publish
exports.setVersion = setPackageVersion //series( setPackageVersion, setFeVersion, setFeVersionMin )