Skip to content

Commit

Permalink
fix: Replace chalk with colorette, modernise
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
prantlf committed Jul 27, 2022
1 parent 34cfc45 commit e1dee8a
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 101 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
,DS_Store
.idea
coverage
node_modules
Expand Down
12 changes: 0 additions & 12 deletions .npmignore

This file was deleted.

78 changes: 14 additions & 64 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -24,20 +21,19 @@ 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.');
}

require('time-grunt')(grunt);

grunt.initConfig({

jshint: {
all: [
'Gruntfile.js',
Expand Down Expand Up @@ -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');
Expand All @@ -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);

};
51 changes: 40 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
},
Expand All @@ -55,8 +87,5 @@
"file",
"folder",
"filesystem"
],
"files": [
"tasks"
]
}
21 changes: 10 additions & 11 deletions tasks/move.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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({
Expand All @@ -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();
}
Expand All @@ -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 {
Expand Down Expand Up @@ -103,5 +103,4 @@ module.exports = function (grunt) {
done(err);
});
});

};
2 changes: 0 additions & 2 deletions test/move_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -136,5 +135,4 @@ exports.move = {
'Fourth file is moved to other directory');
test.done();
}

};

0 comments on commit e1dee8a

Please sign in to comment.