1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const chalk_1 = require("chalk");
|
4 | const path_1 = require("path");
|
5 | const fs_1 = require("fs");
|
6 | const YAML = require("json-to-pretty-yaml");
|
7 | const detectIndent = require("detect-indent");
|
8 |
|
9 | function writeConfig(answers, config) {
|
10 | const ext = answers.config.toLocaleLowerCase().endsWith('.json') ? 'json' : 'yml';
|
11 | const content = ext === 'json' ? JSON.stringify(config) : YAML.stringify(config);
|
12 | const fullPath = path_1.resolve(process.cwd(), answers.config);
|
13 | const relativePath = path_1.relative(process.cwd(), answers.config);
|
14 | fs_1.writeFileSync(fullPath, content, {
|
15 | encoding: 'utf-8'
|
16 | });
|
17 | return {
|
18 | relativePath,
|
19 | fullPath
|
20 | };
|
21 | }
|
22 | exports.writeConfig = writeConfig;
|
23 |
|
24 | function writePackage(answers, configLocation) {
|
25 |
|
26 | const pkgPath = path_1.resolve(process.cwd(), 'package.json');
|
27 | const pkgContent = fs_1.readFileSync(pkgPath, {
|
28 | encoding: 'utf-8'
|
29 | });
|
30 | const pkg = JSON.parse(pkgContent);
|
31 | const { indent } = detectIndent(pkgContent);
|
32 | if (!pkg.scripts) {
|
33 | pkg.scripts = {};
|
34 | }
|
35 | pkg.scripts[answers.script] = `gql-gen --config ${configLocation}`;
|
36 |
|
37 | if (!pkg.devDependencies) {
|
38 | pkg.devDependencies = {};
|
39 | }
|
40 |
|
41 | const { version } = JSON.parse(fs_1.readFileSync(path_1.resolve(__dirname, '../../package.json'), {
|
42 | encoding: 'utf-8'
|
43 | }));
|
44 | answers.plugins.forEach(plugin => {
|
45 | pkg.devDependencies[plugin.package] = version;
|
46 | });
|
47 | fs_1.writeFileSync(pkgPath, JSON.stringify(pkg, null, indent));
|
48 | }
|
49 | exports.writePackage = writePackage;
|
50 | function bold(str) {
|
51 | return chalk_1.default.bold(str);
|
52 | }
|
53 | exports.bold = bold;
|
54 | function grey(str) {
|
55 | return chalk_1.default.grey(str);
|
56 | }
|
57 | exports.grey = grey;
|
58 | function italic(str) {
|
59 | return chalk_1.default.italic(str);
|
60 | }
|
61 | exports.italic = italic;
|
62 |
|
\ | No newline at end of file |