Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📦 NEW: Add build tools (#12) #16

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[*.txt]
end_of_line = crlf
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.sass-cache
.codekit-cache
config.codekit
.DS_Store
.DS_Store
node_modules/
/storefront-hamburger-menu
storefront-hamburger-menu.zip
24 changes: 24 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"esversion": 7,
"expr": true,
"immed": true,
"noarg": true,
"quotmark": "single",
"trailingcomma": false,
"undef": true,
"unused": true,

"browser": true,

"globals": {
"_": false,
"Backbone": false,
"carousel_parameters": true,
"jQuery": true,
"wp": true
}
}
9 changes: 9 additions & 0 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": [
"stylelint-config-wordpress"
],
"plugins": ["stylelint-a11y"],
"rules": {
"selector-class-pattern": null
}
}
303 changes: 303 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
/* jshint node:true */
const glob = require('glob');
const sass = require('node-sass');

// variables
const sourceFolderRelPath = 'src';
const destFolderRelPath = 'assets';

// add js files here if necessary
const sourceJsFiles = [
`${sourceFolderRelPath}/**/*.js`,
];

// methods
const getFilePaths = (pathArr) => {
let filePaths = [];
for (let path of pathArr) {
const files = glob.sync(path);
filePaths = filePaths.concat(files);
}
return filePaths;
};

const getFilesPathObjects = (pathArr) => {
const filesPathsObjs = [];
for (let path of pathArr) {
const src = path;
const dest = path.replace(sourceFolderRelPath, destFolderRelPath);
filesPathsObjs.push({src, dest});
}
return filesPathsObjs;
};

const jsFilesPaths = getFilePaths(sourceJsFiles);
const jsFilesPathsObjs = getFilesPathObjects(jsFilesPaths);

/**
* Returns an object with destinations as key and sources as value
* @param filesPathsObjs
* @returns {}
*/
const buildFileConfiguration = (filesPathsObjs) => {
let fileConfig = {};
for (let pathObj of filesPathsObjs) {
fileConfig[pathObj.dest] = pathObj.src;
}
return fileConfig;
};

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

grunt.initConfig({

// JavaScript linting with JSHint.
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: jsFilesPaths.concat('Gruntfile.js')
},

browserify: {
dist: {
files: buildFileConfiguration(jsFilesPathsObjs)
},
options: {
transform: [['babelify', {
presets: [
'@wordpress/babel-preset-default',
]
}]],
browserifyOptions: {
debug: true
}
}
},

// Minify .js files.
uglify: {
options: {
preserveComments: 'some',
sourceMap: true
},
main: {
files: [{
expand: true,
src: jsFilesPathsObjs.map(file => file.dest),
dest: './',
ext: '.min.js',
extDot: 'last',
}]
}
},

// Compile all .scss files.
sass: {

dist: {
options: {
require: 'susy',
implementation: sass,
sourceMap: true,
includePaths: ['node_modules/susy/sass'].concat( require( 'node-bourbon' ).includePaths )
},
files: [
{
expand: true,
cwd: `${sourceFolderRelPath}/scss`,
src: ['**/*.scss'],
dest: `${destFolderRelPath}/css`,
ext: '.css',
extDot: 'last',
},
],
},

},

postcss: {
options: {
map: true,
processors: [
require('autoprefixer')
]
},
dist: {
files: [
{
expand: true,
cwd: `${destFolderRelPath}/css`,
src: ['**/*.css'],
dest: `${destFolderRelPath}/css`,
ext: '.css',
extDot: 'last',
},
]
}
},

cssmin: {
target: {
files: [{
expand: true,
cwd: `${destFolderRelPath}/css`,
src: ['**/*.css', '!**/*.min.css'],
dest: `${destFolderRelPath}/css`,
ext: '.min.css',
extDot: 'last',
}]
}
},

// Watch changes for assets.
watch: {
css: {
files: [
`${sourceFolderRelPath}/scss/**/*.scss`
],
tasks: [
'css'
]
},
js: {
files: jsFilesPaths,
tasks: ['js']
}
},

// Generate POT files.
makepot: {
options: {
type: 'wp-plugin',
domainPath: 'languages',
potHeaders: {
'report-msgid-bugs-to': 'https://wordpress.org/support/plugin/storefront-hamburger-menu/',
'language-team': 'LANGUAGE <EMAIL@ADDRESS>'
}
},
frontend: {
options: {
potFilename: 'storefront-hamburger-menu.pot',
exclude: [
'node_modules/.*'
]
}
}
},

// Check textdomain errors.
checktextdomain: {
options:{
text_domain: 'storefront-hamburger-menu',
keywords: [
'__:1,2d',
'_e:1,2d',
'_x:1,2c,3d',
'esc_html__:1,2d',
'esc_html_e:1,2d',
'esc_html_x:1,2c,3d',
'esc_attr__:1,2d',
'esc_attr_e:1,2d',
'esc_attr_x:1,2c,3d',
'_ex:1,2c,3d',
'_n:1,2,4d',
'_nx:1,2,4c,5d',
'_n_noop:1,2,3d',
'_nx_noop:1,2,3c,4d'
]
},
files: {
src: [
'**/*.php', // Include all files
'!node_modules/**' // Exclude node_modules/
],
expand: true
}
},

// Sass linting with Stylelint.
stylelint: {
options: {
configFile: '.stylelintrc'
},
all: [
'src/**/*.scss'
]
},

compress: {
zip: {
options: {
archive: './storefront-hamburger-menu.zip',
mode: 'zip'
},
files: [{
src: [
'**',
'.htaccess',
'!.*/**',
'!*.md',
'!.DS_Store',
'!composer.json',
'!composer.lock',
'!Gruntfile.js',
'!node_modules/**',
'!npm-debug.log',
'!package.json',
'!package-lock.json',
'!phpcs.xml',
'!storefront-hamburger-menu.zip',
'!storefront-hamburger-menu/**',
'!vendor/**',
'!src/**'
]
}]
}
},

});

// Load NPM tasks to be used here
grunt.loadNpmTasks( 'grunt-browserify' );
grunt.loadNpmTasks( 'grunt-checktextdomain' );
grunt.loadNpmTasks( 'grunt-contrib-cssmin' );
grunt.loadNpmTasks( 'grunt-contrib-compress' );
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
grunt.loadNpmTasks( 'grunt-contrib-watch' );
grunt.loadNpmTasks( 'grunt-postcss' );
grunt.loadNpmTasks( 'grunt-sass' );
grunt.loadNpmTasks( 'grunt-stylelint' );
grunt.loadNpmTasks( 'grunt-wp-i18n' );

// Register tasks
grunt.registerTask( 'js', [
'jshint',
'browserify:dist',
'uglify',
]);

grunt.registerTask( 'css', [
'sass',
'postcss',
'cssmin',
]);

grunt.registerTask( 'i18n', [
'checktextdomain',
'makepot',
]);

grunt.registerTask( 'build', [
'js',
'css',
]);

// Compress task is part of default to work with woorelease
grunt.registerTask( 'default', [
'build',
'compress',
]);
};
5 changes: 1 addition & 4 deletions assets/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/css/style.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading