Skip to content

Commit f8593a8

Browse files
committed
Introduce Grunt with Coffee & SASS compiling 🎉
1 parent e563ec2 commit f8593a8

File tree

9 files changed

+209
-2
lines changed

9 files changed

+209
-2
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
/.settings
22
/.project
33
*.zip
4+
.sass-cache*
5+
6+
# NPM packages used by Grunt.js
7+
/node_modules
8+
9+
# NPM debug log
10+
npm-debug.log

Gruntfile.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* jshint node:true */
2+
module.exports = function( grunt ) {
3+
'use strict';
4+
5+
// load all grunt tasks matching the `grunt-*` pattern
6+
require( 'load-grunt-tasks' )( grunt );
7+
8+
// Show elapsed time
9+
require( 'time-grunt' )( grunt );
10+
11+
var _ = require( 'underscore' );
12+
var path = require( 'path' );
13+
14+
// Set plugin slug option
15+
//grunt.option( 'plugin-slug', path.basename( process.cwd() ) );
16+
17+
var gruntConfig = {};
18+
19+
// options
20+
gruntConfig.options = {};
21+
22+
// Set folder templates
23+
gruntConfig.dirs = {
24+
css: 'assets/css',
25+
js: 'assets/js',
26+
images: 'assets/images',
27+
fonts: 'assets/fonts',
28+
build: 'build'
29+
};
30+
31+
function loadConfig( filepath ) {
32+
var object = {};
33+
var key;
34+
35+
filepath = path.normalize( path.resolve( process.cwd(), filepath ) + '/' )
36+
37+
var files = grunt.file.glob.sync( '*', { cwd: filepath } );
38+
39+
files.forEach( function( option ) {
40+
key = option.replace(/\.js$/,'');
41+
object = _.extend( object, require( filepath + option )( grunt ) );
42+
});
43+
44+
return object;
45+
};
46+
47+
// load task configs
48+
gruntConfig = _.extend( gruntConfig, loadConfig( './grunt/configs/' ) );
49+
50+
// Init Grunt
51+
grunt.initConfig( gruntConfig );
52+
53+
// Register Tasks
54+
grunt.registerTask( 'default', [
55+
'coffee',
56+
'uglify',
57+
'sass',
58+
'clean'
59+
] );
60+
};

grunt/configs/clean.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* jshint node:true */
2+
module.exports = function( grunt ) {
3+
'use strict';
4+
5+
var util = grunt.option( 'util' );
6+
var _ = require( 'underscore' );
7+
var config = {};
8+
9+
// Delete source map from the CoffeeScript compilation
10+
config.clean = {
11+
options: {
12+
force: true
13+
},
14+
clean: [
15+
// Delete map files
16+
'woocommerce/payment-gateway/assets/js/frontend/*.min.js.map'
17+
]
18+
};
19+
20+
return config;
21+
};

grunt/configs/coffee.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* jshint node:true */
2+
module.exports = function( grunt ) {
3+
'use strict';
4+
5+
var config = {};
6+
7+
// Compile CoffeeScript
8+
config.coffee = {
9+
compile: {
10+
options: {
11+
sourceMap: true
12+
},
13+
files: [
14+
{
15+
expand: true,
16+
cwd: 'woocommerce/payment-gateway/assets/js/admin/',
17+
dest: 'woocommerce/payment-gateway/assets/js/admin/',
18+
src: '*.coffee',
19+
ext: '.min.js'
20+
},
21+
{
22+
expand: true,
23+
cwd: 'woocommerce/payment-gateway/assets/js/frontend/',
24+
dest: 'woocommerce/payment-gateway/assets/js/frontend/',
25+
src: '*.coffee',
26+
ext: '.min.js'
27+
}
28+
]
29+
}
30+
};
31+
32+
return config;
33+
};

grunt/configs/sass.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* jshint node:true */
2+
module.exports = function( grunt ) {
3+
'use strict';
4+
5+
var config = {};
6+
7+
// Compile all .scss files.
8+
config.sass = {
9+
compile: {
10+
options: {
11+
style: 'compressed',
12+
sourcemap: true
13+
},
14+
files: [
15+
{
16+
expand: true,
17+
cwd: 'woocommerce/payment-gateway/assets/css/admin/',
18+
dest: 'woocommerce/payment-gateway/assets/css/admin/',
19+
src: ['*.scss', '!_*.scss'],
20+
ext: '.min.css'
21+
},
22+
{
23+
expand: true,
24+
cwd: 'woocommerce/payment-gateway/assets/css/frontend/',
25+
dest: 'woocommerce/payment-gateway/assets/css/frontend/',
26+
src: ['*.scss', '!_*.scss'],
27+
ext: '.min.css'
28+
}
29+
]
30+
}
31+
};
32+
33+
return config;
34+
};

grunt/configs/uglify.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* jshint node:true */
2+
module.exports = function( grunt ) {
3+
'use strict';
4+
var config = {};
5+
6+
// Add Uglify task with legacy rules
7+
config.uglify = {
8+
uglify: {
9+
options : {
10+
sourceMap: true,
11+
sourceMapIncludeSources: true,
12+
sourceMapIn: 'woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-frontend.min.js.map', // input sourcemap from CoffeeScript compilation
13+
sourceMapName: 'woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-frontend.min.map'
14+
},
15+
files : [{
16+
src: [ 'woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-frontend.min.js' ], // uglify JS from CoffeeScript compilation
17+
dest: 'woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-frontend.min.js'
18+
}]
19+
}
20+
}
21+
22+
return config;
23+
};

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "wc-plugin-framework",
3+
"version": "4.0.0",
4+
"author": "SkyVerge Team",
5+
"homepage": "http://www.skyverge.com",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/skyverge/wc-plugin-framework.git"
9+
},
10+
"bugs": {
11+
"url": "https://github.com/skyverge/wc-plugin-framework/issues"
12+
},
13+
"engines": {
14+
"node": ">= 0.10.0"
15+
},
16+
"devDependencies": {
17+
"grunt": "~0.4.5",
18+
"grunt-newer": "~1.1.1",
19+
"grunt-notify": "~0.4.1",
20+
"grunt-contrib-clean": "~0.6.0",
21+
"grunt-contrib-coffee": "~0.13.0",
22+
"grunt-contrib-uglify": "~0.9.1",
23+
"grunt-contrib-sass": "~0.9.2",
24+
"load-grunt-tasks": "~3.2.0",
25+
"time-grunt": "~1.2.1",
26+
"underscore": "~1.8.3",
27+
"underscore.string": "~3.1.1"
28+
}
29+
}

woocommerce/payment-gateway/assets/js/frontend/sv-wc-payment-gateway-frontend.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)