11'use strict' ;
22
3- var SemVer = require ( 'semver' ) ,
4- spawnSync = require ( 'child_process' ) . spawnSync ,
5- fs = require ( 'fs' ) ,
6- path = require ( 'path' ) ,
7- glob = require ( 'glob' ) ,
8- indent = require ( 'detect-indent' ) ,
9- logSymbols = require ( 'log-symbols' ) ,
10- chalk = require ( 'chalk' ) ,
11- cwd = process . cwd ( ) ,
12- oldVersion , newVersion ;
3+ const SemVer = require ( 'semver' ) ;
4+ const spawnSync = require ( 'child_process' ) . spawnSync ;
5+ const fs = require ( 'fs' ) ;
6+ const path = require ( 'path' ) ;
7+ const glob = require ( 'glob' ) ;
8+ const indent = require ( 'detect-indent' ) ;
9+ const logSymbols = require ( 'log-symbols' ) ;
10+ const chalk = require ( 'chalk' ) ;
11+ const cwd = process . cwd ( ) ;
12+
13+ let oldVersion , newVersion ;
1314
1415module . exports = {
15- manifests : manifests ,
16- versionInfo : versionInfo ,
17- bump : bump ,
18- runNpmScriptIfExists : runNpmScriptIfExists ,
19- grep : grep ,
20- git : git
16+ manifests,
17+ versionInfo,
18+ bump,
19+ runNpmScriptIfExists,
20+ grep,
21+ git
2122} ;
2223
2324/**
@@ -26,11 +27,11 @@ module.exports = {
2627 *
2728 * @returns {string[] }
2829 */
29- function manifests ( ) {
30- return [ 'package.json' , 'bower.json' , 'component.json' ] . filter ( function ( manifest ) {
31- var pkgPath = path . join ( cwd , manifest ) ;
30+ function manifests ( ) {
31+ return [ 'package.json' , 'bower.json' , 'component.json' ] . filter ( ( manifest ) => {
32+ let pkgPath = path . join ( cwd , manifest ) ;
3233 try {
33- var pkg = require ( pkgPath ) ;
34+ const pkg = require ( pkgPath ) ;
3435 return pkg . hasOwnProperty ( 'version' ) ;
3536 }
3637 catch ( err ) {
@@ -46,12 +47,12 @@ function manifests() {
4647 * @param {object } options - CLI options
4748 * @returns {VersionInfo }
4849 */
49- function versionInfo ( manifest , options ) {
50- var pkgPath = path . join ( cwd , manifest ) ;
51- var pkg = require ( pkgPath ) ;
50+ function versionInfo ( manifest , options ) {
51+ let pkgPath = path . join ( cwd , manifest ) ;
52+ const pkg = require ( pkgPath ) ;
5253
53- var current = new SemVer ( pkg . version || '0.0.0' ) ;
54- var identifier = options . preid || current . prerelease [ 0 ] || 'beta' ;
54+ let current = new SemVer ( pkg . version || '0.0.0' ) ;
55+ let identifier = options . preid || current . prerelease [ 0 ] || 'beta' ;
5556
5657 /** @name VersionInfo **/
5758 return {
@@ -73,18 +74,18 @@ function versionInfo(manifest, options) {
7374 * @param {string } type - The type of bump to do ("major", "minor", "patch", "premajor", etc.)
7475 * @param {object } options - CLI options
7576 */
76- function bump ( manifest , type , options ) {
77- var pkgPath = path . join ( cwd , manifest ) ;
78- var pkg = require ( pkgPath ) ;
77+ function bump ( manifest , type , options ) {
78+ let pkgPath = path . join ( cwd , manifest ) ;
79+ const pkg = require ( pkgPath ) ;
7980
8081 // Increment the version number
8182 oldVersion = pkg . version || '0.0.0' ;
82- var current = new SemVer ( oldVersion ) ;
83+ let current = new SemVer ( oldVersion ) ;
8384 current . inc ( type , options . preid || current . prerelease [ 0 ] || 'beta' ) ;
8485 newVersion = pkg . version = current . version ;
8586
8687 // Save the file
87- var usedIndent = indent ( fs . readFileSync ( pkgPath , 'utf8' ) ) . indent || ' ' ;
88+ let usedIndent = indent ( fs . readFileSync ( pkgPath , 'utf8' ) ) . indent || ' ' ;
8889
8990 fs . writeFileSync ( pkgPath , JSON . stringify ( pkg , null , usedIndent ) ) ;
9091
@@ -97,13 +98,13 @@ function bump(manifest, type, options) {
9798 * @param {string } manifest - The name of the manifest file (e.g. "package.json")
9899 * @param {string } script - Name of the script ("preversion", "postversion", etc.)
99100 */
100- function runNpmScriptIfExists ( manifest , script ) {
101+ function runNpmScriptIfExists ( manifest , script ) {
101102 if ( manifest !== 'package.json' ) {
102103 return ;
103104 }
104- var pkgPath = path . join ( cwd , manifest ) ;
105- var pkg = require ( pkgPath ) ;
106- var pkgScripts = pkg . scripts ;
105+ let pkgPath = path . join ( cwd , manifest ) ;
106+ const pkg = require ( pkgPath ) ;
107+ let pkgScripts = pkg . scripts ;
107108
108109 if ( pkgScripts && pkgScripts [ script ] ) {
109110 exec ( 'npm' , [ 'run' , script ] ) ;
@@ -119,11 +120,11 @@ function runNpmScriptIfExists(manifest, script) {
119120 *
120121 * @param {object } options - CLI options
121122 */
122- function grep ( manifests , options ) {
123+ function grep ( manifests , options ) {
123124 if ( options . grep ) {
124125 // Separate the glob patterns into two lists: included and excluded
125- var included = [ ] , excluded = [ ] ;
126- options . grep . forEach ( function ( pattern ) {
126+ let included = [ ] , excluded = [ ] ;
127+ options . grep . forEach ( ( pattern ) => {
127128 if ( pattern [ 0 ] === '!' ) {
128129 excluded . push ( pattern ) ;
129130 }
@@ -133,17 +134,17 @@ function grep(manifests, options) {
133134 } ) ;
134135
135136 // Process each glob pattern
136- included . forEach ( function ( pattern ) {
137- var files = glob . sync ( pattern , { nodir : true , ignore : excluded } ) ;
137+ included . forEach ( ( pattern ) => {
138+ let files = glob . sync ( pattern , { nodir : true , ignore : excluded } ) ;
138139
139140 // Process each matched file
140- files . forEach ( function ( file ) {
141+ files . forEach ( ( file ) => {
141142 // Read the file
142- var fileContents = fs . readFileSync ( file , { encoding : 'utf8' } ) ;
143+ let fileContents = fs . readFileSync ( file , { encoding : 'utf8' } ) ;
143144
144145 // Replace the old version number with the new version number
145- var oldVersionPattern = new RegExp ( oldVersion . replace ( / \. / g, '\\.' ) , 'g' ) ;
146- var newFileContents = fileContents . replace ( oldVersionPattern , newVersion ) ;
146+ let oldVersionPattern = new RegExp ( oldVersion . replace ( / \. / g, '\\.' ) , 'g' ) ;
147+ let newFileContents = fileContents . replace ( oldVersionPattern , newVersion ) ;
147148
148149 // Only save the file if there were changes
149150 if ( newFileContents !== fileContents ) {
@@ -162,12 +163,12 @@ function grep(manifests, options) {
162163 * @param {string[] } manifests - An array of manifest files to bump
163164 * @param {object } options - CLI options
164165 */
165- function git ( manifests , options ) {
166+ function git ( manifests , options ) {
166167 if ( options . commit || options . tag || options . push ) {
167168 // Git Commit
168- var commitArgs = [ 'commit' ] ;
169+ let commitArgs = [ 'commit' ] ;
169170 commitArgs = commitArgs . concat ( options . all ? '-a' : manifests ) ;
170- var commitMessage = 'release v' + newVersion ;
171+ let commitMessage = 'release v' + newVersion ;
171172 if ( options . commitMessage ) {
172173 commitMessage = 'v' + newVersion + ' ' + options . commitMessage ;
173174 }
@@ -181,7 +182,7 @@ function git(manifests, options) {
181182 console . log ( logSymbols . success , 'Git tag' ) ;
182183 }
183184
184- manifests . forEach ( function ( manifest ) {
185+ manifests . forEach ( ( manifest ) => {
185186 runNpmScriptIfExists ( manifest , 'postversion' ) ;
186187 } ) ;
187188
@@ -203,15 +204,15 @@ function git(manifests, options) {
203204 * @param {object } [opts] - Options to pass to spawnSync
204205 * @param {boolean } [opts.skipCustomErrorLog] - Use to skip logging the error when using try-catch
205206 */
206- function exec ( command , args , opts ) {
207+ function exec ( command , args , opts ) {
207208 opts = opts || { } ;
208- var skipCustomErrorLog = opts . skipCustomErrorLog ;
209+ let skipCustomErrorLog = opts . skipCustomErrorLog ;
209210 delete opts . skipCustomErrorLog ;
210- //use which to make sure that node spawn can find correct executable, at the moment this is used as
211- //a windows fallback, until https://github.com/libuv/libuv/pull/358 is fixed
212- var which = require ( 'npm-which' ) ( process . cwd ( ) ) ;
213- var pathToCommand = which . sync ( command ) ;
214- var result = spawnSync ( pathToCommand , args , opts ) ;
211+ // use which to make sure that node spawn can find correct executable, at the moment this is used as
212+ // a windows fallback, until https://github.com/libuv/libuv/pull/358 is fixed
213+ const which = require ( 'npm-which' ) ( process . cwd ( ) ) ;
214+ let pathToCommand = which . sync ( command ) ;
215+ let result = spawnSync ( pathToCommand , args , opts ) ;
215216 if ( result . status || result . error ) {
216217 if ( ! skipCustomErrorLog ) {
217218 console . error (
@@ -220,9 +221,9 @@ function exec(command, args, opts) {
220221 ) ;
221222 }
222223
223- var err = result . error ;
224+ let err = result . error ;
224225 if ( ! result . error ) {
225- var output = result . stdout . toString ( ) || result . stderr . toString ( ) ;
226+ let output = result . stdout . toString ( ) || result . stderr . toString ( ) ;
226227 err = new Error ( output ) ;
227228 }
228229 err . status = result . status ;
0 commit comments