Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
check-latest: true

- name: Install NPM dependencies and build
run: npm ci
run: npm install

- name: Run tests
run: npm run test
44 changes: 44 additions & 0 deletions lib/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const chalk = require( 'chalk' );

const ERROR = chalk.reset.inverse.bold.red( ' ERROR ' );

const grunt = require( 'grunt' );

const logger = function () {
this.isVerbose = () => {
// Eventually replace this
return grunt.log._options.verbose || grunt.log._options.debug;
};

this.isDebug = () => {
return grunt.log._options.verbose || grunt.log._options.debug;
};

this.write = ( msg ) => {
process.stdout.write( msg );
};

this.debug = ( msg ) => {
if ( this.isDebug ) {
this.write( `DEBUG: ${ msg } ` );
}
};

this.error = ( msg ) => {
this.write( `${ ERROR } ${ msg }` );
};

this.notice = ( msg ) => {
this.write( msg );
};

this.verbose = ( msg ) => {
if ( this.isVerbose ) {
this.write( msg );
}
};
};

const log = new logger();

module.exports = log;
3 changes: 2 additions & 1 deletion lib/map_old_to_new_file_path.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const grunt = require( 'grunt' );
const log = require( './log' );

/**
* Replaces file names in the passed filePath with the file names in the fileMappings.
Expand Down Expand Up @@ -41,7 +42,7 @@ function mapOldToNewFilePath( filePath, fileMappings ) {

// Logs the mapping.
if ( body !== newBody ) {
grunt.log.writeln(
log.notice(
'Old file path ' +
oldPath +
' found in patch. This path has been automatically replaced by ' +
Expand Down
6 changes: 3 additions & 3 deletions lib/trac.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const url = require( 'url' );
const grunt = require( 'grunt' );
const log = require( './log' );

module.exports = {
convertToRaw( parsedUrl ) {
grunt.log.debug( 'convertToRaw: ' + JSON.stringify( parsedUrl ) );
log.debug( 'convertToRaw: ' + JSON.stringify( parsedUrl ) );
parsedUrl.pathname = parsedUrl.pathname.replace(
/attachment/,
'raw-attachment'
);
grunt.log.debug( 'converted_from_raw: ' + url.format( parsedUrl ) );
log.debug( 'converted_from_raw: ' + url.format( parsedUrl ) );
return url.format( parsedUrl );
},
};
Loading