From 0635b3f7b3d5155d18abd6143efbeeeef2122efa Mon Sep 17 00:00:00 2001 From: mpv Date: Sun, 12 Jun 2016 03:26:07 -0300 Subject: [PATCH 01/10] Deprecate Gruntconfig.json and use load-grunt-configs Still needs to change example and tests. --- bootstrap.js | 2 +- package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bootstrap.js b/bootstrap.js index 88fc1ce3..ca917339 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -1,6 +1,6 @@ module.exports = function(grunt) { // Initialize global configuration variables. - var config = grunt.file.readJSON('Gruntconfig.json'); + var config = require('load-grunt-configs')(grunt); if (grunt.config.getRaw() === undefined) { grunt.initConfig({ config: config diff --git a/package.json b/package.json index 6e8a2056..de4adede 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "fs-extra": "~3.0.1", "grunt": "^1.0.1", "grunt-available-tasks": "~0.6.2", + "load-grunt-configs": "~1.0.0", "grunt-composer": "~0.4.4", "grunt-concurrent": "^2.1.0", "grunt-contrib-clean": "^1.0.0", From 35532bc3ef27c54a3cbccca968e35ecf79d97f3c Mon Sep 17 00:00:00 2001 From: "Cristian G. Segarra" Date: Mon, 6 Nov 2017 16:40:39 -0300 Subject: [PATCH 02/10] Load configurations from files using load-grunt-configs https://www.npmjs.com/package/load-grunt-configs --- bootstrap.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/bootstrap.js b/bootstrap.js index ca917339..d5654f98 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -1,6 +1,6 @@ module.exports = function(grunt) { // Initialize global configuration variables. - var config = require('load-grunt-configs')(grunt); + var config = grunt.file.readJSON('Gruntconfig.json'); if (grunt.config.getRaw() === undefined) { grunt.initConfig({ config: config @@ -9,6 +9,26 @@ module.exports = function(grunt) { grunt.config.set('config', config); } + config_dir = grunt.config.get('config.srcPaths.config_dir'); + if (config_dir && grunt.file.isDir(config_dir)) { + var options = { + config: { + src: [ + config_dir + '/*.js*', + config_dir + '/*.coffee', + config_dir + '/*.y*ml', + config_dir + '/*.cson' + ] + } + }; + var configs = require('load-grunt-configs')(grunt, options); + for (config_name in configs) { + if (config_name != 'config') { + grunt.config.set('config.' + config_name, configs[config_name]); + } + } + } + var GDT = require('./lib/init')(grunt); GDT.init(); From d5d0767c20c86f6e45ec18947808b2ea9de4ff84 Mon Sep 17 00:00:00 2001 From: "Cristian G. Segarra" Date: Mon, 6 Nov 2017 16:42:44 -0300 Subject: [PATCH 03/10] Add documentation about the new config for loading configurations from files --- docs/10_BUILD.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/10_BUILD.md b/docs/10_BUILD.md index 6f765594..af3dd1de 100644 --- a/docs/10_BUILD.md +++ b/docs/10_BUILD.md @@ -154,6 +154,11 @@ The following build output paths are optional to specify in the project's **srcPaths.make**: The Drush make file used to assemble the Drupal project. This is only used for Drupal 7.x projects. Example is `src/project.make`. +**srcPaths.config_dir**: The directory that should be used for loading +configurations. The files inside this directory will be loaded using +[load-grunt-configs](https://www.npmjs.com/package/load-grunt-configs) +and merged with the *Gruntconfig.json*. + **buildPaths.build**: The directory that should be used for miscellaneous build artifacts. This can be the parent directory of the following build paths. From 4778c5e339920987a35187bd7839b979597c9dcf Mon Sep 17 00:00:00 2001 From: "Cristian G. Segarra" Date: Mon, 6 Nov 2017 16:43:34 -0300 Subject: [PATCH 04/10] Add example for loading configurations from files --- example/Gruntconfig.json | 9 +-------- example/config/packages.yml | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 example/config/packages.yml diff --git a/example/Gruntconfig.json b/example/Gruntconfig.json index 9d8ee5ad..3f2bc59d 100644 --- a/example/Gruntconfig.json +++ b/example/Gruntconfig.json @@ -1,5 +1,6 @@ { "srcPaths": { + "config_dir": "config", "make": "src/project.make", "drupal": "src" }, @@ -7,14 +8,6 @@ "buildPaths": { "packages": "build/packages" }, - "packages": { - "srcFiles": ["!sites/*/files/**", "!xmlrpc.php", "!modules/php/*"], - "projFiles": ["README*", "bin/**", "hooks/**", "src/*.make", "vendor/**"], - "dest": { - "docroot": "html", - "devResources": "" - } - }, "phpcs": true, "phpmd": true, "behat": { diff --git a/example/config/packages.yml b/example/config/packages.yml new file mode 100644 index 00000000..de49598b --- /dev/null +++ b/example/config/packages.yml @@ -0,0 +1,14 @@ +--- +srcFiles: + - "!sites/*/files/**" + - "!xmlrpc.php" + - "!modules/php/*" +projFiles: + - "README*" + - "bin/**" + - "hooks/**" + - "src/*.make" + - "vendor/**" +dest: + docroot: "html" + devResources: "" From f0e725abb723abc151de6f37b135bfea4203004b Mon Sep 17 00:00:00 2001 From: "Cristian G. Segarra" Date: Mon, 6 Nov 2017 17:19:49 -0300 Subject: [PATCH 05/10] Fix code syntax --- bootstrap.js | 18 +++++++++--------- docs/10_BUILD.md | 2 +- example/Gruntconfig.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index d5654f98..b40740e7 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -9,22 +9,22 @@ module.exports = function(grunt) { grunt.config.set('config', config); } - config_dir = grunt.config.get('config.srcPaths.config_dir'); - if (config_dir && grunt.file.isDir(config_dir)) { + var configDir = grunt.config.get('config.srcPaths.configDir'); + if (configDir && grunt.file.isDir(configDir)) { var options = { config: { src: [ - config_dir + '/*.js*', - config_dir + '/*.coffee', - config_dir + '/*.y*ml', - config_dir + '/*.cson' + configDir + '/*.js*', + configDir + '/*.coffee', + configDir + '/*.y*ml', + configDir + '/*.cson' ] } }; var configs = require('load-grunt-configs')(grunt, options); - for (config_name in configs) { - if (config_name != 'config') { - grunt.config.set('config.' + config_name, configs[config_name]); + for (var configName in configs) { + if (configName !== 'config') { + grunt.config.set('config.' + configName, configs[configName]); } } } diff --git a/docs/10_BUILD.md b/docs/10_BUILD.md index af3dd1de..e12a2284 100644 --- a/docs/10_BUILD.md +++ b/docs/10_BUILD.md @@ -154,7 +154,7 @@ The following build output paths are optional to specify in the project's **srcPaths.make**: The Drush make file used to assemble the Drupal project. This is only used for Drupal 7.x projects. Example is `src/project.make`. -**srcPaths.config_dir**: The directory that should be used for loading +**srcPaths.configDir**: The directory that should be used for loading configurations. The files inside this directory will be loaded using [load-grunt-configs](https://www.npmjs.com/package/load-grunt-configs) and merged with the *Gruntconfig.json*. diff --git a/example/Gruntconfig.json b/example/Gruntconfig.json index 3f2bc59d..27b7478f 100644 --- a/example/Gruntconfig.json +++ b/example/Gruntconfig.json @@ -1,6 +1,6 @@ { "srcPaths": { - "config_dir": "config", + "configDir": "config", "make": "src/project.make", "drupal": "src" }, From 49c811bb885a7d284c1d31653d5fa4b062fdb6c3 Mon Sep 17 00:00:00 2001 From: "Cristian G. Segarra" Date: Mon, 6 Nov 2017 17:36:57 -0300 Subject: [PATCH 06/10] Add test for D7 --- test/test_assets/Gruntconfig.json | 5 +---- test/test_assets/config/packages.yml | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 test/test_assets/config/packages.yml diff --git a/test/test_assets/Gruntconfig.json b/test/test_assets/Gruntconfig.json index ec863dbd..b8cf66fa 100644 --- a/test/test_assets/Gruntconfig.json +++ b/test/test_assets/Gruntconfig.json @@ -1,15 +1,12 @@ { "srcPaths": { + "configDir": "config", "make": "src/project.make", "drupal": "src" }, "siteUrls": { "default": "http://project.local" }, - "packages": { - "srcFiles": ["!sites/*/files/**", "!xmlrpc.php", "!modules/php/*"], - "projFiles": ["README*", "bin/**"] - }, "phpcs": true, "phpmd": true, "behat": { diff --git a/test/test_assets/config/packages.yml b/test/test_assets/config/packages.yml new file mode 100644 index 00000000..6c4b02b6 --- /dev/null +++ b/test/test_assets/config/packages.yml @@ -0,0 +1,8 @@ +--- +srcFiles: + - "!sites/*/files/**" + - "!xmlrpc.php" + - "!modules/php/*" +projFiles: + - "README*" + - "bin/**" From d08954b51cb560c79c380d202ecf38cb129c6cc5 Mon Sep 17 00:00:00 2001 From: "Cristian G. Segarra" Date: Mon, 6 Nov 2017 17:39:19 -0300 Subject: [PATCH 07/10] Add test for D8 --- test/test_assets_d8/Gruntconfig.json | 9 +-------- test/test_assets_d8/config/packages.yml | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 test/test_assets_d8/config/packages.yml diff --git a/test/test_assets_d8/Gruntconfig.json b/test/test_assets_d8/Gruntconfig.json index 63b7a9a5..831eb496 100644 --- a/test/test_assets_d8/Gruntconfig.json +++ b/test/test_assets_d8/Gruntconfig.json @@ -1,19 +1,12 @@ { "domain": "http://127.0.0.1:8080", "srcPaths": { + "configDir": "config", "drupal": "src" }, "siteUrls": { "default": "http://project.local" }, - "packages": { - "srcFiles": ["!sites/*/files/**", "!xmlrpc.php", "!modules/php/*"], - "projFiles": ["README*", "bin/**", "hooks/**", "src/*.make", "vendor/**", "composer.*"], - "dest": { - "docroot": "html", - "devResources": "" - } - }, "phpcs": true, "phpmd": true, "behat": { diff --git a/test/test_assets_d8/config/packages.yml b/test/test_assets_d8/config/packages.yml new file mode 100644 index 00000000..5bb668dc --- /dev/null +++ b/test/test_assets_d8/config/packages.yml @@ -0,0 +1,15 @@ +--- +srcFiles: + - "!sites/*/files/**" + - "!xmlrpc.php" + - "!modules/php/*" +projFiles: + - "README*" + - "bin/**" + - "hooks/**" + - "src/*.make" + - "vendor/**" + - "composer.*" +dest: + docroot: "html" + devResources: "" From 0b2fba347afbc7807766a2dac0871b94f608388c Mon Sep 17 00:00:00 2001 From: "Cristian G. Segarra" Date: Fri, 10 Nov 2017 12:11:39 -0300 Subject: [PATCH 08/10] Add load-grunt-configs on npm-shrinkwrap.json --- npm-shrinkwrap.json | 232 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index b5cdce4d..723b11e1 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -2807,6 +2807,238 @@ "from": "lazystream@>=1.0.0 <2.0.0", "resolved": "https://registry.npmjs.org/lazystream/-/lazystream-1.0.0.tgz" }, + "load-grunt-configs": { + "version": "1.0.0", + "from": "load-grunt-configs@latest", + "resolved": "https://registry.npmjs.org/load-grunt-configs/-/load-grunt-configs-1.0.0.tgz", + "dependencies": { + "cson-parser": { + "version": "1.3.5", + "from": "cson-parser@>=1.0.9 <2.0.0", + "resolved": "https://registry.npmjs.org/cson-parser/-/cson-parser-1.3.5.tgz", + "dependencies": { + "coffee-script": { + "version": "1.12.7", + "from": "coffee-script@>=1.10.0 <2.0.0", + "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.12.7.tgz" + } + } + }, + "inquirer": { + "version": "0.8.5", + "from": "inquirer@>=0.8.2 <0.9.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-0.8.5.tgz", + "dependencies": { + "ansi-regex": { + "version": "1.1.1", + "from": "ansi-regex@>=1.1.1 <2.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-1.1.1.tgz" + }, + "chalk": { + "version": "1.1.3", + "from": "chalk@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "dependencies": { + "ansi-styles": { + "version": "2.2.1", + "from": "ansi-styles@>=2.2.1 <3.0.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz" + }, + "escape-string-regexp": { + "version": "1.0.5", + "from": "escape-string-regexp@>=1.0.5 <2.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz" + }, + "has-ansi": { + "version": "2.0.0", + "from": "has-ansi@>=2.0.0 <3.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "from": "ansi-regex@>=2.0.0 <3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz" + } + } + }, + "strip-ansi": { + "version": "3.0.1", + "from": "strip-ansi@>=3.0.0 <4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "from": "ansi-regex@>=2.0.0 <3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz" + } + } + }, + "supports-color": { + "version": "2.0.0", + "from": "supports-color@>=2.0.0 <3.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz" + } + } + }, + "cli-width": { + "version": "1.1.1", + "from": "cli-width@>=1.0.1 <2.0.0", + "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-1.1.1.tgz" + }, + "figures": { + "version": "1.7.0", + "from": "figures@>=1.3.5 <2.0.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz", + "dependencies": { + "escape-string-regexp": { + "version": "1.0.5", + "from": "escape-string-regexp@>=1.0.5 <2.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz" + }, + "object-assign": { + "version": "4.1.1", + "from": "object-assign@>=4.1.0 <5.0.0", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz" + } + } + }, + "readline2": { + "version": "0.1.1", + "from": "readline2@>=0.1.1 <0.2.0", + "resolved": "https://registry.npmjs.org/readline2/-/readline2-0.1.1.tgz", + "dependencies": { + "mute-stream": { + "version": "0.0.4", + "from": "mute-stream@0.0.4", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.4.tgz" + }, + "strip-ansi": { + "version": "2.0.1", + "from": "strip-ansi@>=2.0.1 <3.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-2.0.1.tgz" + } + } + }, + "rx": { + "version": "2.5.3", + "from": "rx@>=2.4.3 <3.0.0", + "resolved": "https://registry.npmjs.org/rx/-/rx-2.5.3.tgz" + }, + "through": { + "version": "2.3.8", + "from": "through@>=2.3.6 <3.0.0", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz" + } + } + }, + "js-yaml": { + "version": "3.10.0", + "from": "js-yaml@>=3.2.7 <4.0.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz", + "dependencies": { + "argparse": { + "version": "1.0.9", + "from": "argparse@>=1.0.7 <2.0.0", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz", + "dependencies": { + "sprintf-js": { + "version": "1.0.3", + "from": "sprintf-js@>=1.0.2 <1.1.0", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz" + } + } + }, + "esprima": { + "version": "4.0.0", + "from": "esprima@>=4.0.0 <5.0.0", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz" + } + } + }, + "lodash": { + "version": "3.10.1", + "from": "lodash@>=3.6.0 <4.0.0", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz" + }, + "rimraf": { + "version": "2.6.2", + "from": "rimraf@>=2.3.2 <3.0.0", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", + "dependencies": { + "glob": { + "version": "7.1.2", + "from": "glob@>=7.0.5 <8.0.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "dependencies": { + "fs.realpath": { + "version": "1.0.0", + "from": "fs.realpath@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" + }, + "inflight": { + "version": "1.0.6", + "from": "inflight@>=1.0.4 <2.0.0", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "dependencies": { + "wrappy": { + "version": "1.0.2", + "from": "wrappy@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" + } + } + }, + "inherits": { + "version": "2.0.3", + "from": "inherits@>=2.0.0 <3.0.0", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz" + }, + "minimatch": { + "version": "3.0.4", + "from": "minimatch@>=3.0.4 <4.0.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "dependencies": { + "brace-expansion": { + "version": "1.1.8", + "from": "brace-expansion@>=1.1.7 <2.0.0", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", + "dependencies": { + "balanced-match": { + "version": "1.0.0", + "from": "balanced-match@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz" + }, + "concat-map": { + "version": "0.0.1", + "from": "concat-map@0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz" + } + } + } + } + }, + "once": { + "version": "1.4.0", + "from": "once@>=1.3.0 <2.0.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "dependencies": { + "wrappy": { + "version": "1.0.2", + "from": "wrappy@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" + } + } + }, + "path-is-absolute": { + "version": "1.0.1", + "from": "path-is-absolute@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz" + } + } + } + } + } + } + }, "load-json-file": { "version": "1.1.0", "from": "load-json-file@>=1.0.0 <2.0.0", From 44323f2f33b61cca2dffcfbe4ed0167a876a07c4 Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 13 May 2021 19:37:28 -0300 Subject: [PATCH 09/10] Don't try to run drupal-scaffold script if its not defined --- tasks/package.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tasks/package.js b/tasks/package.js index ed9b1dc5..a1206c4c 100644 --- a/tasks/package.js +++ b/tasks/package.js @@ -113,8 +113,13 @@ module.exports = function(grunt) { } }); tasks.push('composer:install'); - grunt.config(['composer', 'drupal-scaffold'], {}); - tasks.push('composer:drupal-scaffold'); + + // Add the drupal-scaffold task if it is defined in the `composer.json`. + var composer = JSON.parse(require('fs').readFileSync('./composer.json', 'utf8')); + if (typeof composer.scripts !== 'undefined' && 'drupal-scaffold' in composer.scripts) { + grunt.config(['composer', 'drupal-scaffold'], {}); + tasks.push('composer:drupal-scaffold'); + } } if (this.args[0] && this.args[0] === 'compress') { From b9696ebe0e35cb1a6038eb3ff2499a81ebd5060b Mon Sep 17 00:00:00 2001 From: Francisco Alvarez Date: Wed, 19 Jan 2022 16:02:09 -0300 Subject: [PATCH 10/10] add case condition for drupal 9 Add new case condition for drupal 9 in drupalPath() function. --- lib/drupal.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/drupal.js b/lib/drupal.js index 20a8ec6f..28596a7c 100644 --- a/lib/drupal.js +++ b/lib/drupal.js @@ -58,6 +58,7 @@ module.exports = function(grunt) { module.drupalPath = function(type) { switch (module.majorVersion()) { case 8: + case 9: return path.join(grunt.config('config.buildPaths.html'), type); case 7: default: