From 2a8b900de36f67114fdccda784cc28a430e38cf4 Mon Sep 17 00:00:00 2001 From: Joakim Carlstein Date: Thu, 23 Mar 2017 09:58:20 +0100 Subject: [PATCH 1/3] chore(release): 1.1.0 --- CHANGELOG.md | 10 ++++++++++ index.js | 34 ++++++++++++++++++++++++++++++---- package.json | 5 +++-- test/install-test.js | 4 ++-- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c711fc..c789c62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +# [1.1.0](https://github.com/slushjs/gulp-install/compare/v1.0.1...v1.1.0) (2017-03-23) + + +### Features + +* add callback support (closes [#17](https://github.com/slushjs/gulp-install/issues/17) [#31](https://github.com/slushjs/gulp-install/issues/31)) ([2e58f84](https://github.com/slushjs/gulp-install/commit/2e58f84)) + + + ## [1.0.1](https://github.com/slushjs/gulp-install/compare/v1.0.0...v1.0.1) (2017-03-23) diff --git a/index.js b/index.js index ded69ce..415a1a8 100644 --- a/index.js +++ b/index.js @@ -2,10 +2,12 @@ const path = require('path'); const through2 = require('through2'); const dargs = require('dargs'); -const gutil = require('gulp-util'); +const logger = require('fancy-log'); +const chalk = require('chalk'); const groupBy = require('lodash.groupby'); const PQueue = require('p-queue'); const commandRunner = require('./lib/command-runner'); +const fs = require('fs'); const commands = { tsd: ['reinstall', '--save'], @@ -45,6 +47,30 @@ module.exports = function (opts = {}, done = noop) { if (!file.path) { return cb(); } + + if (opts.compare) { + var cdir = path.join(__dirname, '/compares/', path.dirname(file.path)); + var cfile = path.join(cdir, path.basename(file.path)); + try { + require(cfile); + } catch (e) { + if (!fs.existsSync(cdir)) { + cdir.split(path.sep).reduce((curPath, folder) => { + curPath += folder + path.sep; + if (!fs.existsSync(curPath)) fs.mkdirSync(curPath); + return curPath; + }, ''); + }; + if (e.code === 'MODULE_NOT_FOUND') fs.writeFileSync(cfile, JSON.stringify({})); + } + let moduleJSON = JSON.stringify(require(file.path), null, ' '); + if (JSON.stringify(require(cfile), null, ' ') !== moduleJSON) { + fs.writeFileSync(cfile, moduleJSON); + } else { + return cb(); + } + } + if (fileToCommand[path.basename(file.path)]) { const cmd = { cmd: fileToCommand[path.basename(file.path)], @@ -85,7 +111,7 @@ module.exports = function (opts = {}, done = noop) { return cb(); } if (skipInstall()) { - log('Skipping install.', 'Run `' + gutil.colors.yellow(formatCommands(toRun)) + '` manually'); + log('Skipping install.', 'Run `' + chalk.yellow(formatCommands(toRun)) + '` manually'); return cb(); } const groupedCommands = groupBy(toRun, 'cmd'); @@ -103,7 +129,7 @@ module.exports = function (opts = {}, done = noop) { function logFailure(command) { return promise => { return promise.catch(err => { - log(err.message, ', run `' + gutil.colors.yellow(formatCommand(command)) + '` manually'); + log(err.message, ', run `' + chalk.yellow(formatCommand(command)) + '` manually'); throw err; }); }; @@ -113,7 +139,7 @@ function log(...args) { if (isTest()) { return; } - gutil.log(...args); + logger(...args); } function formatCommands(cmds) { diff --git a/package.json b/package.json index df3c447..2c2a1c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-install", - "version": "1.0.1", + "version": "1.1.0", "description": "Automatically install npm, bower, tsd, and pip packages/dependencies if the relative configurations are found in the gulp file stream respectively", "main": "index.js", "scripts": { @@ -23,8 +23,9 @@ }, "homepage": "https://github.com/slushjs/gulp-install", "dependencies": { + "chalk": "^2.3.0", + "fancy-log": "^1.3.2", "dargs": "^5.1.0", - "gulp-util": "^3.0.7", "lodash.groupby": "^4.6.0", "p-queue": "^1.0.0", "through2": "^2.0.3", diff --git a/test/install-test.js b/test/install-test.js index e35bf78..99cde5a 100644 --- a/test/install-test.js +++ b/test/install-test.js @@ -3,7 +3,7 @@ 'use strict'; const path = require('path'); const chai = require('chai'); -const gutil = require('gulp-util'); +const vinyl = require('vinyl'); const commandRunner = require('../lib/command-runner'); const install = require('../.'); @@ -12,7 +12,7 @@ const args = process.argv.slice(); function fixture(file) { const filepath = path.join(__dirname, file); - return new gutil.File({ + return new vinyl({ path: filepath, cwd: __dirname, base: path.join(__dirname, path.dirname(file)), From 6c20872ca1cd3bb114e3950c61bde21ab9871891 Mon Sep 17 00:00:00 2001 From: ksteckert Date: Sat, 3 Feb 2018 15:15:48 -0500 Subject: [PATCH 2/3] new compare flag (only run if file has changed), gulp-util is depricated --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 2c2a1c7..4629cf8 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "dependencies": { "chalk": "^2.3.0", "fancy-log": "^1.3.2", + "vinyl": "^2.1.0", "dargs": "^5.1.0", "lodash.groupby": "^4.6.0", "p-queue": "^1.0.0", From db8438dd879f281105a5998d94474476e3a0db6f Mon Sep 17 00:00:00 2001 From: Keith Date: Sat, 3 Feb 2018 16:01:24 -0500 Subject: [PATCH 3/3] remove gutil (depricated), add compare option --- index.js | 34 ++++++++++++++++++++++++++++++---- package.json | 4 +++- test/install-test.js | 4 ++-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index ded69ce..415a1a8 100644 --- a/index.js +++ b/index.js @@ -2,10 +2,12 @@ const path = require('path'); const through2 = require('through2'); const dargs = require('dargs'); -const gutil = require('gulp-util'); +const logger = require('fancy-log'); +const chalk = require('chalk'); const groupBy = require('lodash.groupby'); const PQueue = require('p-queue'); const commandRunner = require('./lib/command-runner'); +const fs = require('fs'); const commands = { tsd: ['reinstall', '--save'], @@ -45,6 +47,30 @@ module.exports = function (opts = {}, done = noop) { if (!file.path) { return cb(); } + + if (opts.compare) { + var cdir = path.join(__dirname, '/compares/', path.dirname(file.path)); + var cfile = path.join(cdir, path.basename(file.path)); + try { + require(cfile); + } catch (e) { + if (!fs.existsSync(cdir)) { + cdir.split(path.sep).reduce((curPath, folder) => { + curPath += folder + path.sep; + if (!fs.existsSync(curPath)) fs.mkdirSync(curPath); + return curPath; + }, ''); + }; + if (e.code === 'MODULE_NOT_FOUND') fs.writeFileSync(cfile, JSON.stringify({})); + } + let moduleJSON = JSON.stringify(require(file.path), null, ' '); + if (JSON.stringify(require(cfile), null, ' ') !== moduleJSON) { + fs.writeFileSync(cfile, moduleJSON); + } else { + return cb(); + } + } + if (fileToCommand[path.basename(file.path)]) { const cmd = { cmd: fileToCommand[path.basename(file.path)], @@ -85,7 +111,7 @@ module.exports = function (opts = {}, done = noop) { return cb(); } if (skipInstall()) { - log('Skipping install.', 'Run `' + gutil.colors.yellow(formatCommands(toRun)) + '` manually'); + log('Skipping install.', 'Run `' + chalk.yellow(formatCommands(toRun)) + '` manually'); return cb(); } const groupedCommands = groupBy(toRun, 'cmd'); @@ -103,7 +129,7 @@ module.exports = function (opts = {}, done = noop) { function logFailure(command) { return promise => { return promise.catch(err => { - log(err.message, ', run `' + gutil.colors.yellow(formatCommand(command)) + '` manually'); + log(err.message, ', run `' + chalk.yellow(formatCommand(command)) + '` manually'); throw err; }); }; @@ -113,7 +139,7 @@ function log(...args) { if (isTest()) { return; } - gutil.log(...args); + logger(...args); } function formatCommands(cmds) { diff --git a/package.json b/package.json index df3c447..089d627 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,10 @@ }, "homepage": "https://github.com/slushjs/gulp-install", "dependencies": { + "chalk": "^2.3.0", + "fancy-log": "^1.3.2", + "vinyl": "^2.1.0", "dargs": "^5.1.0", - "gulp-util": "^3.0.7", "lodash.groupby": "^4.6.0", "p-queue": "^1.0.0", "through2": "^2.0.3", diff --git a/test/install-test.js b/test/install-test.js index e35bf78..99cde5a 100644 --- a/test/install-test.js +++ b/test/install-test.js @@ -3,7 +3,7 @@ 'use strict'; const path = require('path'); const chai = require('chai'); -const gutil = require('gulp-util'); +const vinyl = require('vinyl'); const commandRunner = require('../lib/command-runner'); const install = require('../.'); @@ -12,7 +12,7 @@ const args = process.argv.slice(); function fixture(file) { const filepath = path.join(__dirname, file); - return new gutil.File({ + return new vinyl({ path: filepath, cwd: __dirname, base: path.join(__dirname, path.dirname(file)),