|
1 | 1 | 'use strict'; |
| 2 | + |
2 | 3 | const path = require('path'); |
3 | | -const pkg = require(path.resolve(process.cwd(), 'package.json')); |
| 4 | +const EOL = require('os').EOL; |
4 | 5 | const { |
5 | 6 | checkAndInstallPackage, |
6 | 7 | copyAsync, |
7 | 8 | wrapAsync, |
8 | 9 | writeJsonAsync, |
| 10 | + getJSONKey, |
9 | 11 | } = require('./utils'); |
10 | 12 |
|
11 | | -const installEdition = (edition, config) => |
12 | | - wrapAsync(function*() { |
| 13 | +const installEdition = (edition, config, projectDir) => { |
| 14 | + const pkg = require(path.resolve(projectDir, 'package.json')); |
| 15 | + |
| 16 | + return wrapAsync(function*() { |
13 | 17 | /** |
14 | 18 | * 1. Trigger edition install |
15 | 19 | * 2. Copy over the mandatory edition files to sourceDir |
16 | | - * 3. Do custom post-install procedures for different core editions: |
17 | | - * 3.1 Copy gulpfile.js for edition-node-gulp |
| 20 | + * 3. Copy dependencies defined in edition |
| 21 | + * 4. Do custom post-install procedures for different core editions: |
| 22 | + * 4.1 Copy gulpfile.js for edition-node-gulp |
| 23 | + * 4.2 Copy scripts for edition-node |
18 | 24 | */ |
19 | 25 | const sourceDir = config.paths.source.root; |
20 | 26 | yield checkAndInstallPackage(edition); // 1 |
21 | 27 | yield copyAsync( |
22 | 28 | path.resolve('./node_modules', edition, 'source', '_meta'), |
23 | 29 | path.resolve(sourceDir, '_meta') |
24 | 30 | ); // 2 |
25 | | - switch (edition) { // 3 |
26 | | - // 3.1 |
| 31 | + pkg.dependencies = Object.assign( |
| 32 | + {}, |
| 33 | + pkg.dependencies || {}, |
| 34 | + yield getJSONKey(edition, 'dependencies') |
| 35 | + ); // 3 |
| 36 | + switch (edition) { // 4 |
| 37 | + // 4.1 |
27 | 38 | case '@pattern-lab/edition-node-gulp': { |
28 | 39 | yield copyAsync( |
29 | 40 | path.resolve('./node_modules', edition, 'gulpfile.js'), |
30 | 41 | path.resolve(sourceDir, '../', 'gulpfile.js') |
31 | 42 | ); |
32 | 43 | break; |
33 | 44 | } |
| 45 | + // 4.2 |
34 | 46 | case '@pattern-lab/edition-node': { |
35 | | - const scriptsJSON = { |
36 | | - 'pl:build': 'patternlab build --config ./patternlab-config.json', |
37 | | - 'pl:help': 'patternlab --help', |
38 | | - 'pl:install': 'patternlab install --config ./patternlab-config.json', |
39 | | - 'pl:serve': 'patternlab serve --config ./patternlab-config.json', |
40 | | - 'pl:version': 'patternlab --version', |
41 | | - }; |
42 | | - pkg.scripts = Object.assign({}, pkg.scripts || {}, scriptsJSON); |
43 | | - yield writeJsonAsync('./package.json', pkg, { spaces: 2 }); |
| 47 | + pkg.scripts = Object.assign( |
| 48 | + {}, |
| 49 | + pkg.scripts || {}, |
| 50 | + yield getJSONKey(edition, 'scripts') |
| 51 | + ); |
44 | 52 | break; |
45 | 53 | } |
46 | 54 | } |
| 55 | + yield writeJsonAsync(path.resolve(projectDir, 'package.json'), pkg, { |
| 56 | + spaces: 2, |
| 57 | + EOL: EOL, |
| 58 | + }); |
47 | 59 | return config; |
48 | 60 | }); |
| 61 | +}; |
49 | 62 |
|
50 | 63 | module.exports = installEdition; |
0 commit comments