From d6ec9e2d47a6eb00ce69fa2252f76a2b8d08308d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dumont?= Date: Sat, 27 Jan 2018 19:14:15 +0100 Subject: [PATCH] Grunt --- .gitignore | 12 ++++ Gruntfile.js | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 34 ++++++++++ 3 files changed, 221 insertions(+) create mode 100644 .gitignore create mode 100644 Gruntfile.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b15222 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Grunt +/releases/ +/node_modules/ +npm-debug.log + +# Various file types to ignore when exporting. +.DS_Store +Thumbs.db +*.sh +.gitconfig +*.zip +package-lock.json diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..319df56 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,175 @@ +module.exports = function(grunt) { + 'use strict'; + + require('load-grunt-tasks')(grunt); + + // Project configuration. + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + + // 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: '<%= pkg.name %>.php', // Main project file. + potFilename: '<%= pkg.name %>.pot', // Name of the POT file. + potHeaders: { + 'Report-Msgid-Bugs-To': 'https://github.com/AutoLoadNextPost/alnp-beta-tester/issues', + 'language-team': 'Sébastien Dumont ', + 'language': 'en_US' + }, + exclude: [ + 'releases', + 'node_modules' + ] + } + } + }, + + checktextdomain: { + options:{ + text_domain: '<%= pkg.name %>', // Project text domain. + 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', + '**/*.php', // Include all files + '!node_modules/**' // Exclude node_modules/ + ], + expand: true + }, + }, + + potomo: { + dist: { + options: { + poDel: false + }, + files: [{ + expand: true, + cwd: 'languages', + src: ['*.po'], + dest: 'languages', + ext: '.mo', + nonull: false + }] + } + }, + + // Bump version numbers (replace with version in package.json) + replace: { + Version: { + src: [ + 'readme.txt', + '<%= pkg.name %>.php' + ], + overwrite: true, + replacements: [ + { + from: /Stable tag:.*$/m, + to: "Stable tag: <%= pkg.version %>" + }, + { + from: /Version:.*$/m, + to: "Version: <%= pkg.version %>" + }, + { + from: /public \$version = \'.*.'/m, + to: "public $version = '<%= pkg.version %>'" + } + ] + } + }, + + // Copies the plugin to create deployable plugin. + copy: { + deploy: { + src: [ + '**', + '!.*', + '!*.md', + '!.*/**', + '.htaccess', + '!Gruntfile.js', + '!package.json', + '!package-lock.json', + '!releases/**', + '!node_modules/**', + '!.DS_Store', + '!npm-debug.log', + '!*.sh', + '!*.zip', + '!*.jpg', + '!*.jpeg', + '!*.gif', + '!*.png' + ], + dest: '<%= pkg.name %>', + expand: true, + dot: true + } + }, + + // Compresses the deployable plugin folder. + compress: { + zip: { + options: { + archive: './releases/<%= pkg.name %>-v<%= pkg.version %>.zip', + mode: 'zip' + }, + files: [ + { + expand: true, + cwd: './<%= pkg.name %>/', + src: '**', + 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', [ 'checktextdomain' ]); + + // Checks for errors, updates version and runs i18n tasks. + grunt.registerTask( 'dev', [ 'replace', 'makepot' ]); + + /** + * Run i18n related tasks. + * + * This includes extracting translatable strings, updating the master pot file. + * If this is part of a deploy process, it should come before zipping everything up. + */ + grunt.registerTask( 'update-pot', [ 'checktextdomain', 'makepot' ]); + + /** + * Creates a deployable plugin zipped up ready to upload + * and install on a WordPress installation. + */ + grunt.registerTask( 'zip', [ 'copy', 'compress', 'clean' ]); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..6c745fb --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "title": "Auto Load Next Post: JS Boilerplate", + "name": "alnp-js-Boilerplate", + "author": "AutoLoadNextPost", + "license": "GPL-3.0", + "version": "1.0.0", + "description": "Boilerplate for writing plugins for Auto Load Next Post JavaScript.", + "homepage": "https://autoloadnextpost.com/", + "main": "Gruntfile.js", + "repository": { + "type": "git", + "url": "https://github.com/AutoLoadNextPost/alnp-js-boilerplate" + }, + "bugs": { + "url": "https://github.com/AutoLoadNextPost/alnp-js-boilerplate/issues" + }, + "dependencies": { + "grunt": "^1.0.1" + }, + "devDependencies": { + "grunt-checktextdomain": "~1.0.1", + "grunt-contrib-clean": "~1.1.0", + "grunt-contrib-compress": "^1.4.3", + "grunt-contrib-copy": "^1.0.0", + "grunt-newer": "~1.3.0", + "grunt-potomo": "~3.5.0", + "grunt-text-replace": "^0.4.0", + "grunt-wp-i18n": "~1.0.0", + "load-grunt-tasks": "~3.5.2" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + } +}