UNPKG

1.37 kBJavaScriptView Raw
1'use strict';
2
3const fs = require('fs');
4const path = require('path');
5const packer = require('@my-dish/packer');
6const commandExistsSync = require('command-exists').sync;
7
8function 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
22function installTemplates(templateURL) {
23 return packer.installTemplates(templateURL);
24}
25
26// yarn and npm(over 5) overwrite node_modules so dish reinstalls templates
27function uninstallTemplates(templateURL) {
28
29 // if (command === 'yarn') {
30 //
31 // // delete package-lock.json if npm version is over 5
32 // fs.unlinkSync(path.join(process.cwd(), 'package-lock.json'));
33 // }
34
35 return packer.uninstallTemplates(templateURL);
36}
37
38function 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
48module.exports = {
49 installPackages,
50 installTemplates,
51 createPackageJSON,
52 uninstallTemplates
53};