Skip to content

Commit

Permalink
Corrected Grunt and packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
seb86 committed Jan 24, 2018
1 parent 33d1977 commit f51141c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 221 deletions.
215 changes: 10 additions & 205 deletions Gruntfile.js
@@ -1,6 +1,3 @@
var exec = require('promised-exec'),
path = require('path');

module.exports = function(grunt) {
'use strict';

Expand All @@ -10,106 +7,22 @@ module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

pluginSlug: '<%= pkg.name %>',
mainFile: '<%= pkg.name %>.php',
changelogFile: 'changelog.txt',
tmpPath: '/tmp/<%= pluginSlug %>',
gitPath: path.resolve(__dirname),
deployUrl: 'git@github.com:<%= pkg.author %>/<%= pkg.repository.slug %>.git',
remoteName: '<%= pkg.repository.slug %>',

// Setting directories
dirs: {
css: 'assets/css',
js: 'assets/js',
},

cssmin: {
target: {
files: [{
expand: true,
cwd: '<%= dirs.css %>',
src: [
'*.css',
'!*.min.css'
],
dest: '<%= dirs.css %>',
ext: '.min.css'
}]
}
},

uglify: {
options: {
compress: {
global_defs: {
"EO_SCRIPT_DEBUG": false
},
dead_code: true
},
banner: '/*! <%= pkg.title %> <%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd HH:MM") %> */\n'
},
build: {
files: [{
expand: true, // Enable dynamic expansion.
src: [ // Actual pattern(s) to match.
'<%= dirs.js %>/*.js',
'!<%= dirs.js %>/*.min.js'
],
ext: '.min.js', // Destination filepaths will have this extension.
}]
}
},

jshint: {
options: {
reporter: require('jshint-stylish'),
globals: {
"EO_SCRIPT_DEBUG": false,
},
'-W099': true, // Mixed spaces and tabs
'-W083': true, // Fix functions within loop
'-W082': true, // Declarations should not be placed in blocks
'-W020': true, // Read only - error when assigning EO_SCRIPT_DEBUG a value.
},
all: [
'<%= dirs.js %>/*.js',
'!<%= dirs.js %>/*.min.js'
]
},

watch: {
scripts: {
files: '<%= dirs.js %>/*.js',
tasks: ['jshint', 'uglify'],
options: {
debounceDelay: 250,
},
},
css: {
files: '<%= dirs.css %>/*.css',
tasks: ['css'],
},
},

// Generate .pot file
makepot: {
target: {
options: {
type: 'wp-plugin', // Type of project (wp-plugin or wp-theme).
domainPath: 'languages', // Where to save the POT file.
mainFile: '<%= mainFile %>', // Main project file.
mainFile: '<%= pkg.name %>.php', // Main project file.
potFilename: '<%= pkg.name %>.pot', // Name of the POT file.
potHeaders: {
'Report-Msgid-Bugs-To': 'https://yourdomain.com/',
'language-team': 'Your Name <youremail@domain.com>',
'Report-Msgid-Bugs-To': 'https://github.com/seb86/WooCommerce-Cart-REST-API/issues',
'language-team': 'Sébastien Dumont <mailme@sebastiendumont.com>',
'language': 'en_US'
},
exclude: [
'woo-dependencies/.*',
'node_modules',
'tests/.*',
'tmp'
'node_modules'
]
}
}
Expand Down Expand Up @@ -140,9 +53,7 @@ module.exports = function(grunt) {
'*.php',
'**/*.php', // Include all files
'!woo-dependencies/**', // Exclude woo-dependencies/
'!node_modules/**', // Exclude node_modules/
'!tmp/**', // Exclude tmp/
'!tests/**' // Exclude tests/
'!node_modules/**' // Exclude node_modules/
],
expand: true
},
Expand Down Expand Up @@ -179,7 +90,7 @@ module.exports = function(grunt) {
},
{
from: /Version:.*$/m,
to: "Version: <%= pkg.version %>"
to: "Version: <%= pkg.version %>"
},
{
from: /public \$version = \'.*.'/m,
Expand Down Expand Up @@ -220,138 +131,32 @@ module.exports = function(grunt) {
compress: {
zip: {
options: {
archive: './<%= pkg.name %>-v<%= pkg.version %>.zip',
archive: './releases/<%= pkg.name %>-v<%= pkg.version %>.zip',
mode: 'zip'
},
files: [
{
expand: true,
cwd: './<%= pkg.name %>/',
src: '**',
dest: 'releases/'
dest: '<%= pkg.name %>'
}
]
}
},

// Deletes the deployable plugin folder once zipped up.
clean: [ '<%= pkg.name %>' ]

});

// Set the default grunt command to run test cases.
grunt.registerTask( 'default', [ 'test' ] );

// Checks for errors.
grunt.registerTask( 'test', [ 'cssmin', 'jshint', 'checktextdomain' ]);
grunt.registerTask( 'test', [ 'checktextdomain' ]);

// Checks for errors, updates version and runs i18n tasks.
grunt.registerTask( 'dev', [ 'replace', 'cssmin', 'jshint', 'newer:uglify', 'makepot' ]);

// All together now.
grunt.registerTask( 'build', 'The "build" sequence: [Update, Check, Test and Build, MakePot]', function() {
grunt.log.ok([
"..........................................",
"Preparing to build...",
".........................................."
].join("\n\n"));

grunt.task.run([
'replace',
'check-git',
'minify',
'update-pot',
'zip'
]);
});

/**
* Run checks and minification tasks.
*
* 1. Checks for any CSS syntax errors and minifies the CSS if error free.
* 2. Checks for any JavaScript syntax errors and minifies the JavaScript if error free.
*/
grunt.registerTask( 'minify', [ 'cssmin', 'jshint', 'newer:uglify' ]);

/**
* Run Git related check tasks.
*
* 1. Checks versions to be the same across all files and compares them to the one in
* package.json
* 2. Makes sure we do not have a tag with the pacakge version released yet.
*/
grunt.registerTask( 'check-git', [ 'check-versions', 'check-git-tag' ]);

/**
* Makes sure we do not have a tag with the pacakge version released yet.
* Exits if we do.
*/
grunt.registerTask( 'check-git-tag', 'Make sure git tag doesn\'t exist yet', function() {
var done = this.async(),
version = '<%= pkg.version %>';

exec( 'git show-ref --tags --quiet --verify -- "refs/tags/' + version + '"' )
.then( function() {
grunt.fail.fatal( 'Version ' + version + ' already exists as git tag.', 3 );
})
.fail( function() {
grunt.log.ok( 'No git tag exists for ' + version + '. Let\'s proceed...' );
})
.fin(done);
});

/**
* Checks versions to be the same across all files and compares them to the one in
* package.json
* - top of plugin-slug.php within WordPress plugin comment
* - static property of the plugin object
* - changelog.txt latest entry
*/
grunt.registerTask( 'check-versions', 'Make sure all versions everywhere are the same', function() {
var file = grunt.file.read( '<%= mainFile %>', {encoding: 'utf8'} ),
changelog = grunt.file.read( '<%= changelogFile %>', {encoding: 'utf8'} ),

// Need the version from the top of the main file
readmeVersionRegex = /\* Version: ([0-9\.]+)/g,
readmeVersion = readmeVersionRegex.exec(file)[1],

// Need the version from the main file in the public static $version property
versionPropertyRegex = /public static \$version = '([0-9\.]+)';/g,
versionProperty = versionPropertyRegex.exec(file)[1],

// Need the version in package.json file = pkg.version
// Need the version in changelog.txt
changelogVersionRegex = /\d{4}\.\d{2}\.\d{2} - version ([0-9\.]+)/g,
changelogVersion = changelogVersionRegex.exec(changelog)[1],
newVersion = '<%= pkg.version %>',
releaseRegex = /\d\.\d\.\d-\d+/,
isRelease = newVersion.match(releaseRegex),
messages = [],
failed = false,
m;

if ( newVersion != readmeVersion ) {
messages.push( 'The readme version (' + readmeVersion + ') is not the same as the new: ' + newVersion );
failed = true;
}

if ( newVersion != versionProperty ) {
messages.push( 'The version property (' + versionProperty + ') is not the same as the new: ' + newVersion );
failed = true;
}

if ( newVersion != changelogVersion ) {
messages.push( 'The changelog version (' + changelogVersion + ') is not the same as the new: ' + newVersion );
failed = true;
}

if ( failed && null === isRelease ) {
m = messages.join("\n");
grunt.fail.fatal("\n" + m, 3);
}

grunt.log.ok( "\nVersions match. Let's proceed...\n" );
});
grunt.registerTask( 'dev', [ 'replace', 'makepot' ]);

/**
* Run i18n related tasks.
Expand Down
19 changes: 3 additions & 16 deletions package.json
@@ -1,9 +1,9 @@
{
"title": "WooCommerce Cart REST API",
"name": "woocommerce-cart-rest-api",
"name": "cart-rest-api-for-woocommerce",
"author": "seb86",
"license": "GPL-3.0",
"version": "1.0.0",
"version": "1.0.0-Beta",
"description": "Provides additional REST-API endpoints for WooCommerce to enable the ability to add, view, update and delete items from the cart.",
"homepage": "https://sebastiendumont.com/",
"main": "Gruntfile.js",
Expand All @@ -18,30 +18,17 @@
"grunt": "^1.0.1"
},
"devDependencies": {
"exec": "^0.1.2",
"grunt": "~1.0.1",
"grunt-checktextdomain": "~1.0.1",
"grunt-contrib-clean": "~1.1.0",
"grunt-contrib-compress": "^1.4.3",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-cssmin": "~2.2.0",
"grunt-contrib-jshint": "~1.0.0",
"grunt-contrib-uglify": "~1.0.0",
"grunt-contrib-watch": "~1.0.0",
"grunt-exec": "^0.4.6",
"grunt-newer": "~1.3.0",
"grunt-potomo": "~3.5.0",
"grunt-text-replace": "^0.4.0",
"grunt-wp-i18n": "~1.0.0",
"jshint-stylish": "~2.2.0",
"load-grunt-tasks": "~3.5.2",
"promised-exec": "~1.0.1"
"load-grunt-tasks": "~3.5.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"engines": {
"node": ">=7.9.0",
"npm": ">=4.2.0"
}
}

0 comments on commit f51141c

Please sign in to comment.