|
| 1 | +module.exports = function(grunt) { |
| 2 | + 'use strict'; |
| 3 | + |
| 4 | + require('load-grunt-tasks')(grunt); |
| 5 | + |
| 6 | + // Project configuration. |
| 7 | + grunt.initConfig({ |
| 8 | + pkg: grunt.file.readJSON('package.json'), |
| 9 | + |
| 10 | + // Generate .pot file |
| 11 | + makepot: { |
| 12 | + target: { |
| 13 | + options: { |
| 14 | + type: 'wp-plugin', // Type of project (wp-plugin or wp-theme). |
| 15 | + domainPath: 'languages', // Where to save the POT file. |
| 16 | + mainFile: '<%= pkg.name %>.php', // Main project file. |
| 17 | + potFilename: '<%= pkg.name %>.pot', // Name of the POT file. |
| 18 | + potHeaders: { |
| 19 | + 'Report-Msgid-Bugs-To': 'https://github.com/autoloadnextpost/alnp-divi-support/issues', |
| 20 | + 'language-team': 'Sébastien Dumont <mailme@sebastiendumont.com>', |
| 21 | + 'language': 'en_US' |
| 22 | + }, |
| 23 | + exclude: [ |
| 24 | + 'releases', |
| 25 | + 'node_modules' |
| 26 | + ] |
| 27 | + } |
| 28 | + } |
| 29 | + }, |
| 30 | + |
| 31 | + checktextdomain: { |
| 32 | + options:{ |
| 33 | + text_domain: '<%= pkg.name %>', // Project text domain. |
| 34 | + keywords: [ |
| 35 | + '__:1,2d', |
| 36 | + '_e:1,2d', |
| 37 | + '_x:1,2c,3d', |
| 38 | + 'esc_html__:1,2d', |
| 39 | + 'esc_html_e:1,2d', |
| 40 | + 'esc_html_x:1,2c,3d', |
| 41 | + 'esc_attr__:1,2d', |
| 42 | + 'esc_attr_e:1,2d', |
| 43 | + 'esc_attr_x:1,2c,3d', |
| 44 | + '_ex:1,2c,3d', |
| 45 | + '_n:1,2,4d', |
| 46 | + '_nx:1,2,4c,5d', |
| 47 | + '_n_noop:1,2,3d', |
| 48 | + '_nx_noop:1,2,3c,4d' |
| 49 | + ] |
| 50 | + }, |
| 51 | + files: { |
| 52 | + src: [ |
| 53 | + '*.php', |
| 54 | + '**/*.php', // Include all files |
| 55 | + '!node_modules/**' // Exclude node_modules/ |
| 56 | + ], |
| 57 | + expand: true |
| 58 | + }, |
| 59 | + }, |
| 60 | + |
| 61 | + potomo: { |
| 62 | + dist: { |
| 63 | + options: { |
| 64 | + poDel: false |
| 65 | + }, |
| 66 | + files: [{ |
| 67 | + expand: true, |
| 68 | + cwd: 'languages', |
| 69 | + src: ['*.po'], |
| 70 | + dest: 'languages', |
| 71 | + ext: '.mo', |
| 72 | + nonull: false |
| 73 | + }] |
| 74 | + } |
| 75 | + }, |
| 76 | + |
| 77 | + // Bump version numbers (replace with version in package.json) |
| 78 | + replace: { |
| 79 | + Version: { |
| 80 | + src: [ |
| 81 | + 'readme.txt', |
| 82 | + '<%= pkg.name %>.php' |
| 83 | + ], |
| 84 | + overwrite: true, |
| 85 | + replacements: [ |
| 86 | + { |
| 87 | + from: /Stable tag:.*$/m, |
| 88 | + to: "Stable tag: <%= pkg.version %>" |
| 89 | + }, |
| 90 | + { |
| 91 | + from: /Version:.*$/m, |
| 92 | + to: "Version: <%= pkg.version %>" |
| 93 | + }, |
| 94 | + { |
| 95 | + from: /public \$version = \'.*.'/m, |
| 96 | + to: "public $version = '<%= pkg.version %>'" |
| 97 | + } |
| 98 | + ] |
| 99 | + } |
| 100 | + }, |
| 101 | + |
| 102 | + // Copies the plugin to create deployable plugin. |
| 103 | + copy: { |
| 104 | + deploy: { |
| 105 | + src: [ |
| 106 | + '**', |
| 107 | + '!.*', |
| 108 | + '!*.md', |
| 109 | + '!.*/**', |
| 110 | + '.htaccess', |
| 111 | + '!Gruntfile.js', |
| 112 | + '!package.json', |
| 113 | + '!package-lock.json', |
| 114 | + '!releases/**', |
| 115 | + '!node_modules/**', |
| 116 | + '!.DS_Store', |
| 117 | + '!npm-debug.log', |
| 118 | + '!*.sh', |
| 119 | + '!*.zip', |
| 120 | + '!*.jpg', |
| 121 | + '!*.jpeg', |
| 122 | + '!*.gif', |
| 123 | + '!*.png' |
| 124 | + ], |
| 125 | + dest: '<%= pkg.name %>', |
| 126 | + expand: true, |
| 127 | + dot: true |
| 128 | + } |
| 129 | + }, |
| 130 | + |
| 131 | + // Compresses the deployable plugin folder. |
| 132 | + compress: { |
| 133 | + zip: { |
| 134 | + options: { |
| 135 | + archive: './releases/<%= pkg.name %>-v<%= pkg.version %>.zip', |
| 136 | + mode: 'zip' |
| 137 | + }, |
| 138 | + files: [ |
| 139 | + { |
| 140 | + expand: true, |
| 141 | + cwd: './<%= pkg.name %>/', |
| 142 | + src: '**', |
| 143 | + dest: '<%= pkg.name %>' |
| 144 | + } |
| 145 | + ] |
| 146 | + } |
| 147 | + }, |
| 148 | + |
| 149 | + // Deletes the deployable plugin folder once zipped up. |
| 150 | + clean: [ '<%= pkg.name %>' ] |
| 151 | + }); |
| 152 | + |
| 153 | + // Set the default grunt command to run test cases. |
| 154 | + grunt.registerTask( 'default', [ 'test' ] ); |
| 155 | + |
| 156 | + // Checks for errors. |
| 157 | + grunt.registerTask( 'test', [ 'checktextdomain' ]); |
| 158 | + |
| 159 | + // Checks for errors, updates version and runs i18n tasks. |
| 160 | + grunt.registerTask( 'dev', [ 'replace', 'makepot' ]); |
| 161 | + |
| 162 | + /** |
| 163 | + * Run i18n related tasks. |
| 164 | + * |
| 165 | + * This includes extracting translatable strings, updating the master pot file. |
| 166 | + * If this is part of a deploy process, it should come before zipping everything up. |
| 167 | + */ |
| 168 | + grunt.registerTask( 'update-pot', [ 'checktextdomain', 'makepot' ]); |
| 169 | + |
| 170 | + /** |
| 171 | + * Creates a deployable plugin zipped up ready to upload |
| 172 | + * and install on a WordPress installation. |
| 173 | + */ |
| 174 | + grunt.registerTask( 'zip', [ 'copy', 'compress', 'clean' ]); |
| 175 | +}; |
0 commit comments