From e1dee8a50c79582b9077bd52c3885f226f78d81d Mon Sep 17 00:00:00 2001 From: Ferdinand Prantl Date: Wed, 27 Jul 2022 08:40:33 +0200 Subject: [PATCH] fix: Replace chalk with colorette, modernise Chalk stopped supporting CJS projects. * Replace grunt-istanbul with c8 * Remove unnecessary files * Add VS Code settings BREAKING CHANGE: Dropped support of Node.js 6. Node.js 10 or newer is required. (Needed by colorette.) --- .gitattributes | 1 - .gitignore | 1 + .npmignore | 12 -------- Gruntfile.js | 78 +++++++++-------------------------------------- package.json | 51 ++++++++++++++++++++++++------- tasks/move.js | 21 ++++++------- test/move_test.js | 2 -- 7 files changed, 65 insertions(+), 101 deletions(-) delete mode 100644 .gitattributes delete mode 100644 .npmignore diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 2125666..0000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -* text=auto \ No newline at end of file diff --git a/.gitignore b/.gitignore index 77a85db..bb02d7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +,DS_Store .idea coverage node_modules diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 761b673..0000000 --- a/.npmignore +++ /dev/null @@ -1,12 +0,0 @@ -.coveralls.yml -.git -.gitignore -.editorconfig -.idea -.npmignore -.travis.yml -Gruntfile.js -coverage -node_modules -npm-debug.log -test \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 897d6b3..1a6d453 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,14 +1,11 @@ 'use strict'; -var fs = require('fs'), - os = require('os'), +var os = require('os'), path = require('path'), - chalk = require('chalk'); + colorette = require('colorette'); module.exports = function (grunt) { - - var coverage = process.env.GRUNT_MOVE_COVERAGE, - tmp = os.tmpdir(), + var tmp = os.tmpdir(), succeedingTasks = [ 'move:empty', 'move:missing', 'move:rename', 'move:move_with_rename', 'move:move_without_rename', @@ -24,12 +21,12 @@ module.exports = function (grunt) { failingWarnings = [ 'No files or directories specified.', 'No files or directories found at ' + - chalk.cyan('test/work/missing/old') + '.', + colorette.cyan('test/work/missing/old') + '.', 'Error: Unable to create directory "test/work/failed_invalid_destination/blocked" (Error code: EEXIST).' ], tasks; - if (!process.env.TRAVIS) { + if (false) { failingTasks.push('move:failed_move_across_volumes'); failingWarnings.push('Moving files across devices has not been enabled.'); } @@ -37,7 +34,6 @@ module.exports = function (grunt) { require('time-grunt')(grunt); grunt.initConfig({ - jshint: { all: [ 'Gruntfile.js', @@ -158,54 +154,16 @@ module.exports = function (grunt) { }, nodeunit: { - tests: ['test/*_test.js'], - options: { - reporter: coverage ? 'lcov' : 'verbose', - reporterOutput: coverage ? 'coverage/tests.lcov' : undefined - } + tests: ['test/*_test.js'] }, clean: { - options: { - force: true - }, - tests: ['test/work', path.join(tmp, 'grunt-move')], - coverage: ['coverage'] - }, - - instrument: { - files: 'tasks/*.js', - options: { - lazy: true, - basePath: 'coverage/' - } - }, - - storeCoverage: { - options: { - dir: 'coverage' - } - }, - - makeReport: { - src: 'coverage/coverage.json', - options: { - type: 'lcov', - dir: 'coverage', - print: 'detail' - } - }, - - coveralls: { - tests: { - src: 'coverage/lcov.info' - } + options: { force: true }, + tests: ['test/work', path.join(tmp, 'grunt-move')] } - }); - grunt.loadTasks(coverage && fs.existsSync('coverage/tasks') ? - 'coverage/tasks' : 'tasks'); + grunt.loadTasks('tasks'); grunt.loadNpmTasks('grunt-continue-ext'); grunt.loadNpmTasks('grunt-contrib-clean'); @@ -215,19 +173,11 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-coveralls'); grunt.loadNpmTasks('grunt-istanbul'); - tasks = ['copy'].concat(succeedingTasks) - .concat(['continue:on']) - .concat(failingTasks) - .concat(['continue:off', 'continue:check-warnings', - 'nodeunit']); - if (coverage) { - tasks = ['clean', 'instrument'].concat(tasks) - .concat(['storeCoverage', 'makeReport']); - } else { - tasks = ['clean:tests'].concat(tasks); - } - tasks = ['jshint'].concat(tasks); + tasks = ['jshint', 'clean', 'copy'] + .concat(succeedingTasks) + .concat(['continue:on']) + .concat(failingTasks) + .concat(['continue:off', 'continue:check-warnings', 'nodeunit']); grunt.registerTask('default', tasks); - }; diff --git a/package.json b/package.json index 7ea3d22..f95f9fd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grunt-move", "description": "Grunt task for moving and renaming files and directories", - "version": "0.0.0-development", + "version": "1.0.3", "homepage": "https://github.com/prantlf/grunt-move", "author": { "name": "Ferdinand Prantl", @@ -23,27 +23,59 @@ } ], "engines": { - "node": ">=12" + "node": ">=10" }, "main": "tasks/move.js", + "files": [ + "tasks" + ], "scripts": { - "test": "grunt", - "check_coverage": "GRUNT_MOVE_COVERAGE=1 grunt", - "post_coverage": "GRUNT_MOVE_COVERAGE=1 grunt default coveralls" + "check": "grunt", + "test": "c8 grunt" + }, + "c8": { + "check-coverage": true, + "include": [ + "tasks/move.js" + ], + "reporter": [ + "text", + "lcov" + ], + "branches": 100, + "lines": 100, + "functions": 100, + "statements": 100 + }, + "release": { + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + "@semantic-release/changelog", + "@semantic-release/npm", + [ + "@semantic-release/github", + { + "failComment": false + } + ], + "@semantic-release/git" + ] }, "dependencies": { "async": "~3.2.4", - "chalk": "^4.1.2" + "colorette": "^2.0.19" }, "devDependencies": { + "@semantic-release/changelog": "^6.0.1", + "@semantic-release/git": "^10.0.1", + "c8": "^7.12.0", "grunt": "^1.5.3", "grunt-continue-ext": "^2.0.0", "grunt-contrib-clean": "^2.0.1", "grunt-contrib-copy": "^1.0.0", "grunt-contrib-jshint": "^3.2.0", "grunt-contrib-nodeunit": "^4.0.0", - "grunt-coveralls": "^2.0.0", - "grunt-istanbul": "^0.8.0", "jshint-stylish": "^2.2.1", "time-grunt": "^2.0.0" }, @@ -55,8 +87,5 @@ "file", "folder", "filesystem" - ], - "files": [ - "tasks" ] } diff --git a/tasks/move.js b/tasks/move.js index 596f6e9..c426fb6 100644 --- a/tasks/move.js +++ b/tasks/move.js @@ -1,7 +1,7 @@ // grunt-move // https://github.com/prantlf/grunt-move // -// Copyright (c) 2017 Ferdinand Prantl +// Copyright (c) 2017-2022 Ferdinand Prantl // Licensed under the MIT license. // // Grunt task for moving and renaming files and directories @@ -10,11 +10,10 @@ var fs = require('fs'), path = require('path'), - chalk = require('chalk'), + colorette = require('colorette'), async = require('async'); module.exports = function (grunt) { - grunt.registerMultiTask('move', 'Moves and renames files and directories.', function () { var done = this.async(), options = this.options({ @@ -36,7 +35,7 @@ module.exports = function (grunt) { if (!file.src.length) { if (!options.ignoreMissing) { grunt.fail.warn('No files or directories found at ' + - chalk.cyan(file.orig.src) + '.'); + colorette.cyan(file.orig.src) + '.'); } return allDone(); } @@ -57,21 +56,22 @@ module.exports = function (grunt) { grunt.file.mkdir(dir); if (dir === path.dirname(src)) { - grunt.verbose.writeln('Renaming ' + chalk.cyan(src) + ' to ' + - chalk.cyan(path.basename(dest)) + '.'); + grunt.verbose.writeln('Renaming ' + colorette.cyan(src) + ' to ' + + colorette.cyan(path.basename(dest)) + '.'); } else { - grunt.verbose.writeln('Moving ' + chalk.cyan(src) + ' to ' + - chalk.cyan(dest) + '.'); + grunt.verbose.writeln('Moving ' + colorette.cyan(src) + ' to ' + + colorette.cyan(dest) + '.'); } fs.rename(src, dest, function (err) { + /* c8 ignore next 21 */ if (err) { if (err.code === 'EXDEV') { if (options.moveAcrossVolumes) { - grunt.verbose.writeln('Copying ' + chalk.cyan(src) + ' across devices.'); + grunt.verbose.writeln('Copying ' + colorette.cyan(src) + ' across devices.'); grunt.file.copy(src, dest); - grunt.verbose.writeln('Deleting ' + chalk.cyan(src) + '.'); + grunt.verbose.writeln('Deleting ' + colorette.cyan(src) + '.'); grunt.file.delete(src); ++moved; } else { @@ -103,5 +103,4 @@ module.exports = function (grunt) { done(err); }); }); - }; diff --git a/test/move_test.js b/test/move_test.js index ba92e98..27d9737 100644 --- a/test/move_test.js +++ b/test/move_test.js @@ -5,7 +5,6 @@ var grunt = require('grunt'), path = require('path'); exports.move = { - empty: function (test) { test.expect(1); test.ok(true, 'No input produces no output'); @@ -136,5 +135,4 @@ exports.move = { 'Fourth file is moved to other directory'); test.done(); } - };