@epublishing/grunt-epublishing 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cli.js CHANGED
@@ -65,15 +65,25 @@ function printOptions(options) {
65
65
  */
66
66
  async function runNpmInstall(config, options) {
67
67
  const paths = config.paths || {};
68
- const resolver = new Resolver({ ...paths }, { includeSite: false });
69
- resolver.removePath('site');
70
-
68
+ // Build paths object with ONLY jade and jade child gem directories (absolute paths)
69
+ const gemPaths = {};
70
+ if (paths.jade && path.isAbsolute(paths.jade)) {
71
+ gemPaths.jade = paths.jade;
72
+ }
73
+ if (paths.jadechild && path.isAbsolute(paths.jadechild)) {
74
+ gemPaths.jadechild = paths.jadechild;
75
+ }
76
+ for (const [key, value] of Object.entries(paths)) {
77
+ if (key.startsWith('jade_') && value && path.isAbsolute(value)) {
78
+ gemPaths[key] = value;
79
+ }
80
+ }
81
+ const resolver = new Resolver(gemPaths, { includeSite: false });
71
82
  const packages = resolver.find('package.json');
72
83
  if (!packages || packages.length === 0) {
73
84
  return;
74
85
  }
75
86
 
76
- const origCwd = process.cwd();
77
87
  const dirs = [...new Set(packages.map((p) => path.dirname(p)))];
78
88
 
79
89
  for (const dir of dirs) {
@@ -84,13 +94,12 @@ async function runNpmInstall(config, options) {
84
94
  const hasLock = fs.existsSync(path.join(dir, 'package-lock.json'));
85
95
  const cmd = hasLock ? 'ci' : 'install';
86
96
  await new Promise((resolve, reject) => {
87
- process.chdir(dir);
88
97
  const proc = spawn('npm', [cmd], {
98
+ cwd: dir,
89
99
  stdio: options.verbose ? 'inherit' : 'pipe',
90
100
  shell: true,
91
101
  });
92
102
  proc.on('close', (code) => {
93
- process.chdir(origCwd);
94
103
  if (code === 0) {
95
104
  spinner.succeed(`npm ${cmd} completed in ${basename}`);
96
105
  resolve();
@@ -100,13 +109,11 @@ async function runNpmInstall(config, options) {
100
109
  }
101
110
  });
102
111
  proc.on('error', (err) => {
103
- process.chdir(origCwd);
104
112
  spinner.fail(`npm ${cmd} failed in ${basename}`);
105
113
  reject(err);
106
114
  });
107
115
  });
108
116
  } catch (err) {
109
- process.chdir(origCwd);
110
117
  throw err;
111
118
  }
112
119
  }
@@ -412,6 +419,9 @@ async function run(argv) {
412
419
  const options = program.opts();
413
420
  const task = program.args[0] || 'all';
414
421
 
422
+ // Debug: print paths and webpack alias (with -v or DEBUG=1)
423
+ const debug = options.verbose || process.env.DEBUG;
424
+
415
425
  // Set NODE_ENV if specified
416
426
  if (options.env) {
417
427
  process.env.NODE_ENV = options.env;
@@ -437,6 +447,15 @@ async function run(argv) {
437
447
  throw error;
438
448
  }
439
449
 
450
+ if (debug && config.paths) {
451
+ console.log(chalk.gray(' Paths: jade=') + (config.paths.jade || '(none)'));
452
+ console.log(chalk.gray(' Paths: jadechild=') + (config.paths.jadechild || '(none)'));
453
+ const jadeChildKeys = Object.keys(config.paths).filter((k) => k.startsWith('jade_'));
454
+ jadeChildKeys.forEach((k) => {
455
+ console.log(chalk.gray(` Paths: ${k}=`) + config.paths[k]);
456
+ });
457
+ }
458
+
440
459
  // Install npm packages from jade hierarchy (jade, jadechild) before build
441
460
  if (task === 'webpack' || task === 'all') {
442
461
  try {
@@ -11,8 +11,8 @@
11
11
 
12
12
  const fs = require('fs');
13
13
  const path = require('path');
14
+ const { spawn } = require('child_process');
14
15
  const _ = require('lodash');
15
- const getGemPaths = require('@epublishing/get-gem-paths');
16
16
  const { resolveConfig, resolveTemplates } = require('./template-resolver');
17
17
 
18
18
  /**
@@ -41,6 +41,43 @@ function getFilename(fullPath) {
41
41
  return path.basename(fullPath);
42
42
  }
43
43
 
44
+ /**
45
+ * Get gem paths by running the get-gem-paths Ruby script via bundle exec.
46
+ * This ensures Bundler has loaded the site's Gemfile and gem specs.
47
+ * @param {string} sitePath - Path to the site (with Gemfile)
48
+ * @param {string} pattern - Gem name pattern (e.g. 'jade')
49
+ * @returns {Promise<Array<{name: string, path: string, version: string}>>}
50
+ */
51
+ function getGemPathsFromBundler(sitePath, pattern = 'jade') {
52
+ return new Promise((resolve, reject) => {
53
+ const rubyScript = path.join(
54
+ path.dirname(require.resolve('@epublishing/get-gem-paths')),
55
+ 'scripts',
56
+ 'get-gem-paths.rb'
57
+ );
58
+ const proc = spawn('bundle', ['exec', 'ruby', rubyScript, pattern], {
59
+ cwd: sitePath || process.cwd(),
60
+ stdio: ['ignore', 'pipe', 'pipe'],
61
+ });
62
+ let stdout = '';
63
+ let stderr = '';
64
+ proc.stdout.on('data', (d) => { stdout += d; });
65
+ proc.stderr.on('data', (d) => { stderr += d; });
66
+ proc.on('close', (code) => {
67
+ if (code !== 0) {
68
+ reject(new Error(`get-gem-paths failed (${code}): ${stderr || stdout}`));
69
+ return;
70
+ }
71
+ try {
72
+ resolve(JSON.parse(stdout));
73
+ } catch (e) {
74
+ reject(new Error(`get-gem-paths invalid JSON: ${stdout}`));
75
+ }
76
+ });
77
+ proc.on('error', reject);
78
+ });
79
+ }
80
+
44
81
  /**
45
82
  * Custom merger for lodash merge
46
83
  * Handles array merging with JS file override logic
@@ -127,8 +164,8 @@ async function loadConfig(sitePath = process.cwd(), options = {}) {
127
164
  const jadeChildPaths = {};
128
165
 
129
166
  try {
130
- const gems = await getGemPaths('jade_?', sitePath);
131
-
167
+ const gems = await getGemPathsFromBundler(sitePath, 'jade');
168
+
132
169
  for (const gem of gems) {
133
170
  if (gem.name === 'jade') {
134
171
  jadePath = gem.path;
@@ -90,11 +90,16 @@ function createWebpackConfig(config, options = {}) {
90
90
  const resolveAlias = {
91
91
  lodash: lodashDir,
92
92
  };
93
- if (paths.jadechild) {
94
- resolveAlias['jade-child'] = path.join(paths.jadechild, paths.js_src || 'app/js', 'jade-child.js');
93
+ const jadeChildPath = paths.jadechild || (() => {
94
+ const jadeChildKey = Object.keys(paths).find((k) => k.startsWith('jade_') && k !== 'jadechild');
95
+ return jadeChildKey ? paths[jadeChildKey] : null;
96
+ })();
97
+ if (jadeChildPath && typeof jadeChildPath === 'string') {
98
+ const jadeChildJs = path.resolve(jadeChildPath, paths.js_src || 'app/js', 'jade-child.js');
99
+ resolveAlias['jade-child'] = jadeChildJs;
95
100
  }
96
- if (paths.jade) {
97
- resolveAlias['jade-engine'] = path.join(paths.jade, paths.js_src || 'app/js', 'jade-engine.js');
101
+ if (paths.jade && typeof paths.jade === 'string') {
102
+ resolveAlias['jade-engine'] = path.resolve(paths.jade, paths.js_src || 'app/js', 'jade-engine.js');
98
103
  }
99
104
 
100
105
  // Build plugins array
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@epublishing/grunt-epublishing",
3
3
  "description": "Modern front-end build tools for ePublishing Jade and client sites.",
4
- "version": "1.1.3",
4
+ "version": "1.1.4",
5
5
  "homepage": "https://www.epublishing.com",
6
6
  "contributors": [
7
7
  {