1 | 'use strict';
|
2 |
|
3 | const fs = require('fs');
|
4 | const path = require('path');
|
5 | const packer = require('@my-dish/packer');
|
6 | const commandExistsSync = require('command-exists').sync;
|
7 |
|
8 | function installPackages(templateURL) {
|
9 | const command = commandExistsSync('yarn') ? 'yarn' : 'npm';
|
10 |
|
11 | const npm = require(
|
12 | path.join(process.cwd(), 'node_modules', templateURL, 'npm')
|
13 | );
|
14 |
|
15 | return packer.installPackages(
|
16 | command,
|
17 | npm.packages.dependencies,
|
18 | npm.packages.devDependencies
|
19 | );
|
20 | }
|
21 |
|
22 | function installTemplates(templateURL) {
|
23 | return packer.installTemplates(templateURL);
|
24 | }
|
25 |
|
26 |
|
27 | function uninstallTemplates(templateURL) {
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | return packer.uninstallTemplates(templateURL);
|
36 | }
|
37 |
|
38 | function createPackageJSON(projectName, projectPath, templateURL) {
|
39 | const npm = require(
|
40 | path.join(process.cwd(), 'node_modules', templateURL, 'npm')
|
41 | );
|
42 |
|
43 | const packageJSON = packer.createPackageJSON(npm, projectName);
|
44 |
|
45 | fs.writeFileSync(path.join(projectPath, 'package.json'), packageJSON);
|
46 | }
|
47 |
|
48 | module.exports = {
|
49 | installPackages,
|
50 | installTemplates,
|
51 | createPackageJSON,
|
52 | uninstallTemplates
|
53 | };
|