Skip to content

Commit

Permalink
Merge branch 'release/1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
jdevalk committed Jun 25, 2020
2 parents 5153b10 + 6c7dd95 commit db143bc
Show file tree
Hide file tree
Showing 12 changed files with 361 additions and 514 deletions.
49 changes: 0 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ This adds the following tasks to your plugin's repo (see below for usage):
* [makepot](https://github.com/Yoast/plugin-grunt-tasks#the-makepot-task)
* [postcss](https://github.com/Yoast/plugin-grunt-tasks#the-postcss-task)
* [rtlcss](https://github.com/Yoast/plugin-grunt-tasks#the-rtlcss-task)
* [sass](https://github.com/Yoast/plugin-grunt-tasks#the-sass-task)
* [set-version](https://github.com/Yoast/plugin-grunt-tasks#the-set-version-task)
* [shell](https://github.com/Yoast/plugin-grunt-tasks#the-shell-task)
* [uglify](https://github.com/Yoast/plugin-grunt-tasks#the-uglify-task)
Expand Down Expand Up @@ -1184,53 +1183,6 @@ rtlcss: {
}
```


### The `sass` task
See: [sindresorhus/grunt-sass](https://github.com/sindresorhus/grunt-sass)

#### Using our configuration
We implement a `build` task:
- The `options.implementation` value is set to `require( "node-sass" )`.
- The `options.sourceMap` value is read from the Grunt configuration: `developmentBuild`.
- The `files` value is read from the Grunt configuration: `sassFiles`.

#### Overview
In your project's Gruntfile, add a section named `imagemin` to the data object passed into `grunt.initConfig()`.
```js
grunt.initConfig( {
sass: {
options: {}, // Task-specific options.
dist: {
files: {} // Target-specific file lists.
},
},
} );
```

#### Options
See the Node Sass [options](https://github.com/sass/node-sass#options), except for `file`, `outFile`, `success`, `error`.

The default value for the `precision` option is `10`, so you don't have to change it when using Bootstrap.

#### Usage Examples
```js
const sass = require('node-sass');

grunt.initConfig( {
sass: {
options: {
implementation: sass,
sourceMap: true
},
dist: {
files: {
'main.css': 'main.scss'
}
}
}
} );
```

### The 'set-version' task
#### Using our configuration
We implement a `packageJSON` task:
Expand Down Expand Up @@ -1398,7 +1350,6 @@ grunt.initConfig( {
} );
```


### The `uglify` task
See: [gruntjs/grunt-contrib-uglify](https://github.com/gruntjs/grunt-contrib-uglify)

Expand Down
2 changes: 1 addition & 1 deletion config/aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Build CSS from SCSS to production
'build:css':
- 'clean:build-assets-css'
- 'sass:build'
- 'copy:css-files'
- 'postcss:build'
- 'rtlcss:build'

Expand Down
15 changes: 15 additions & 0 deletions config/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// See https://github.com/gruntjs/grunt-contrib-copy
module.exports = {
"css-files": {
files: [
{
expand: true,
cwd: "css/src",
// TO DO: remove the exclude when ready
src: ["**/**.css"],
flatten: false,
dest: "css/dist/",
},
],
}
}
10 changes: 0 additions & 10 deletions config/sass.js

This file was deleted.

17 changes: 0 additions & 17 deletions config/uglify.js

This file was deleted.

12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@yoast/grunt-plugin-tasks",
"description": "Custom Yoast grunt tasks",
"version": "1.6.2",
"version": "1.7",
"homepage": "https://github.com/Yoast/",
"repository": {
"type": "git",
Expand All @@ -27,26 +27,22 @@
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-yoast": "^1.0.1",
"grunt": "^1.0.4",
"grunt": "^1.1",
"grunt-checktextdomain": "^1.0.1",
"grunt-contrib-clean": "~1.0.0",
"grunt-contrib-compress": "^1.6.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-cssmin": "^3.0.0",
"grunt-contrib-imagemin": "^3.1.0",
"grunt-contrib-uglify": "^4.0.1",
"grunt-contrib-watch": "^1.0.0",
"grunt-eslint": "^21.0.0",
"grunt-glotpress": "https://github.com/Yoast/grunt-glotpress.git#master",
"grunt-postcss": "^0.8.0",
"grunt-postcss": "^0.9.0",
"grunt-replace": "^1.0.1",
"grunt-rtlcss": "^2.0.1",
"grunt-sass": "^3.0.2",
"grunt-rtlcss": "^2.0.2",
"grunt-shell": "^1.1.2",
"grunt-wp-deploy": "^2.0.0",
"grunt-wp-i18n": "^1.0.3",
"load-grunt-config": "^1.0.1",
"node-sass": "^4.12.0",
"time-grunt": "^1.0.0"
},
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions tasks/set-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ module.exports = function( grunt ) {
"set-version",
"Sets a new version number.",
function() {
let options = this.options(
const options = this.options(
{
base: "The JSON file base object for the target to be in.",
target: "The child of the base object to replace the version string in.",
}
);

let version = grunt.option( "new-version" ) || "";
const version = grunt.option( "new-version" ) || "";
if ( version.toString().trim().length === 0 ) {
grunt.fail.fatal( "Missing --new-version argument" );
}

// Foreach file in this.files
let numberOfFiles = this.files.length;
const numberOfFiles = this.files.length;
for ( let i = 0; i < numberOfFiles; i++ ) {
// Foreach src in file
let numberOfSrcFiles = this.files[ i ].src.length;
const numberOfSrcFiles = this.files[ i ].src.length;
for ( let j = 0; j < numberOfSrcFiles; j++ ) {
let path = this.files[ i ].src[ j ];
let contents = grunt.file.readJSON( path );
const path = this.files[ i ].src[ j ];
const contents = grunt.file.readJSON( path );
contents[ options.base ][ options.target ] = version.toString();
grunt.file.write( path, JSON.stringify( contents, null, " " ) + "\n" );
}
Expand Down
6 changes: 3 additions & 3 deletions tasks/update-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function( grunt ) {
"update-version",
"Updates the version tags in all the right places.",
function() {
let options = this.options(
const options = this.options(
{
version: "version",
regEx: "regEx",
Expand All @@ -20,10 +20,10 @@ module.exports = function( grunt ) {

this.files.forEach( ( file ) => {
// If options.regEx is a string, create a regex from it. If it's already a regex, use it as is.
const regex = ( typeof options.regEx === 'string' ) ? new RegExp ( options.regEx ) : options.regEx;
const regex = ( typeof options.regEx === "string" ) ? new RegExp( options.regEx ) : options.regEx;

file.src.forEach( ( path ) => {
let contents = grunt.file.read( path ).replace(
const contents = grunt.file.read( path ).replace(
regex,
options.preVersionMatch + options.version + options.postVersionMatch
);
Expand Down
20 changes: 14 additions & 6 deletions test/set-version-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@

const grunt = require( "grunt" );
const runTask = require( "grunt-run-task" );
let tempFilePath = [ "tmp/testPackage.json" ];
let expectedFilePath = [ "test/expected/testPackage.json" ];
let noOfFiles = Math.min( tempFilePath.length, expectedFilePath.length );
const tempFilePath = [ "tmp/testPackage.json" ];
const expectedFilePath = [ "test/expected/testPackage.json" ];
const noOfFiles = Math.min( tempFilePath.length, expectedFilePath.length );
let setVersionTask;

exports.testSetVersionCommand = {
/**
* @param {function} done Function to execute when done.
* @returns {void}
*/
setUp: function( done ) {
// Load the tasks so they can be run
runTask.loadTasks( "tasks" );

// Setup the file's to run the test on
for ( let i = 0; i < noOfFiles; i++ ) {
let fixturePath = expectedFilePath[ i ].replace( "expected", "fixtures" );
const fixturePath = expectedFilePath[ i ].replace( "expected", "fixtures" );
grunt.log.writeln( "\n [" + ( i + 1 ) + "/" + noOfFiles + "] Copying '" + fixturePath + "' to '" + tempFilePath[ i ] + "'" );
grunt.file.copy( fixturePath, tempFilePath[ i ] );
}
Expand All @@ -41,6 +45,10 @@ exports.testSetVersionCommand = {
done();
} );
},
/**
* @param {object} test Test object
* @returns {void}
*/
testSetVersion: function( test ) {
/**
* Runs the test assertions to verify the 2 files are identical if the files given as parameters exist.
Expand All @@ -52,8 +60,8 @@ exports.testSetVersionCommand = {
*/
function compareFiles( file1, file2 ) {
if ( grunt.file.exists( file1 ) && grunt.file.exists( file2 ) ) {
let actual = grunt.file.read( file1 );
let expected = grunt.file.read( file2 );
const actual = grunt.file.read( file1 );
const expected = grunt.file.read( file2 );
test.deepEqual( actual, expected, "Compare the file '" + file1 + "' with '" + file2 + "'" );
return;
}
Expand Down
24 changes: 17 additions & 7 deletions test/update-version-pluginFile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@

const grunt = require( "grunt" );
const runTask = require( "grunt-run-task" );
let tempFilePath = [ "tmp/test.php" ];
let expectedFilePath = [ "test/expected/test.php" ];
let noOfFiles = Math.min( tempFilePath.length, expectedFilePath.length );
const tempFilePath = [ "tmp/test.php" ];
const expectedFilePath = [ "test/expected/test.php" ];
const noOfFiles = Math.min( tempFilePath.length, expectedFilePath.length );
let pluginFileUpdateTask;

exports.testUpdateVersionCommand = {
/**
* @param {function} done Function to execute when done.
*
* @returns {void}
*/
setUp: function( done ) {
// Load the tasks so they can be run
runTask.loadTasks( "tasks" );

// Setup the file's to run the test on
for ( let i = 0; i < noOfFiles; i++ ) {
let fixturePath = expectedFilePath[ i ].replace( "expected", "fixtures" );
const fixturePath = expectedFilePath[ i ].replace( "expected", "fixtures" );
grunt.log.writeln( " [" + ( i + 1 ) + "/" + noOfFiles + "] Copying '" + fixturePath + "' to '" + tempFilePath[ i ] + "'" );
grunt.file.copy( fixturePath, tempFilePath[ i ] );
}
Expand All @@ -30,7 +35,7 @@ exports.testUpdateVersionCommand = {
pluginFile: {
options: {
version: "1.1",
regEx: /(Version: )(\d+(\.\d+){0,3})([^\n^\.\d]?.*?)(\n)/,
regEx: /(Version: )(\d+(\.\d+){0,3})([^\n^.\d]?.*?)(\n)/,
preVersionMatch: "$1",
postVersionMatch: "$5",
},
Expand All @@ -42,6 +47,11 @@ exports.testUpdateVersionCommand = {
done();
} );
},
/**
* @param {object} test Test object
*
* @returns {void}
*/
testUpdateVersion: function( test ) {
/**
* Runs the test assertions to verify the 2 files are identical if the files given as parameters exist.
Expand All @@ -53,8 +63,8 @@ exports.testUpdateVersionCommand = {
*/
function runTest( file1, file2 ) {
if ( grunt.file.exists( file1 ) && grunt.file.exists( file2 ) ) {
let actual = grunt.file.read( file1 );
let expected = grunt.file.read( file2 );
const actual = grunt.file.read( file1 );
const expected = grunt.file.read( file2 );
test.deepEqual( actual, expected, "Compare the file '" + file1 + "' with '" + file2 + "'" );
return;
}
Expand Down
33 changes: 26 additions & 7 deletions test/update-version-readme-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,32 @@

const grunt = require( "grunt" );
const runTask = require( "grunt-run-task" );
let tempFilePath = [ "tmp/test.php", "tmp/README.MD" ];
let expectedFilePath = [ "test/expected/test.php", "test/expected/README.MD" ];
let noOfFiles = Math.min( tempFilePath.length, expectedFilePath.length );
const tempFilePath = [ "tmp/test.php", "tmp/README.MD" ];
const expectedFilePath = [ "test/expected/test.php", "test/expected/README.MD" ];
const noOfFiles = Math.min( tempFilePath.length, expectedFilePath.length );
let pluginFileUpdateTask;

/**
* Runs the test
*
* @type {{testUpdateVersion: testUpdateVersion, setUp: setUp}}
*
* @returns {void}
*/
exports.testUpdateVersionCommand = {
/**
* Set up our test
*
* @param {function} done Function to run when done.
*
* @returns {void}
*/
setUp: function( done ) {
// Load the tasks so they can be run
runTask.loadTasks( "tasks" );
// Setup the file's to run the test on
for ( let i = 0; i < noOfFiles; i++ ) {
let fixturePath = expectedFilePath[ i ].replace( "expected", "fixtures" );
const fixturePath = expectedFilePath[ i ].replace( "expected", "fixtures" );
grunt.log.writeln( " [" + ( i + 1 ) + "/" + noOfFiles + "] Copying '" + fixturePath + "' to '" + tempFilePath[ i ] + "'" );
grunt.file.copy( fixturePath, tempFilePath[ i ] );
}
Expand All @@ -29,7 +43,7 @@ exports.testUpdateVersionCommand = {
pluginFile: {
options: {
version: "1.1",
regEx: /(Stable tag: )(\d+(\.\d+){0,3})([^\n^\.\d]?.*?)(\n)/,
regEx: /(Stable tag: )(\d+(\.\d+){0,3})([^\n^.\d]?.*?)(\n)/,
preVersionMatch: "$1",
postVersionMatch: "$5",
},
Expand All @@ -41,6 +55,11 @@ exports.testUpdateVersionCommand = {
done();
} );
},
/**
* Runs the test.
* @param {object} test The test object.
* @returns {void}
*/
testUpdateVersion: function( test ) {
/**
* Runs the test assertions to verify the 2 files are identical if the files given as parameters exist.
Expand All @@ -52,8 +71,8 @@ exports.testUpdateVersionCommand = {
*/
function runTest( file1, file2 ) {
if ( grunt.file.exists( file1 ) && grunt.file.exists( file2 ) ) {
let actual = grunt.file.read( file1 );
let expected = grunt.file.read( file2 );
const actual = grunt.file.read( file1 );
const expected = grunt.file.read( file2 );
test.deepEqual( actual, expected, "Compare the file '" + file1 + "' with '" + file2 + "'" );
return;
}
Expand Down
Loading

0 comments on commit db143bc

Please sign in to comment.