|
1 | 1 | const Generator = require('yeoman-generator'); |
2 | 2 | const pkg = require('../../package.json'); |
3 | 3 |
|
| 4 | +const globalModules = require('global-modules'); |
4 | 5 | const globby = require('globby'); |
5 | 6 | const updateNotifier = require('update-notifier'); |
| 7 | +const yarnModules = require('yarn-global-modules'); |
6 | 8 | const yosay = require('yosay'); |
7 | | -const { basename, join } = require('path'); |
| 9 | +const { basename, join, resolve } = require('path'); |
| 10 | +const { existsSync } = require('fs'); |
8 | 11 |
|
9 | 12 | // Is there a newer version of this generator? |
10 | 13 | updateNotifier({ pkg: pkg }).notify(); |
11 | 14 |
|
12 | | -const hljsDir = join(__dirname, '..', '..', 'node_modules', 'highlight.js'); |
| 15 | +// console.log(require.resolve('highlight.js')) |
| 16 | +const hljsDir = getModuleDir(); |
| 17 | + |
| 18 | +function getModuleDir() { |
| 19 | + const npmDir = resolve(globalModules, 'generator-hljs/node_modules', 'highlight.js'); |
| 20 | + |
| 21 | + if (existsSync(npmDir)) { |
| 22 | + return npmDir; |
| 23 | + } |
| 24 | + |
| 25 | + const yarnDir = resolve(yarnModules(), 'node_modules', 'highlight.js'); |
| 26 | + |
| 27 | + if (existsSync(yarnDir)) { |
| 28 | + return yarnDir; |
| 29 | + } |
| 30 | + |
| 31 | + const localDir = resolve(__dirname, '..', '..', 'node_modules', 'highlight.js'); |
| 32 | + |
| 33 | + if (existsSync(localDir)) { |
| 34 | + return localDir; |
| 35 | + } |
| 36 | + |
| 37 | + throw 'Error: highlight.js not found in node_modules'; |
| 38 | +} |
13 | 39 |
|
14 | 40 | function getLanguages() { |
15 | 41 | const languagesPath = join(hljsDir, 'src', 'languages'); |
|
0 commit comments