|
1 | 1 | import semver from 'semver';
|
2 |
| -import { execa, execaCommand } from 'execa'; |
| 2 | +import { execa } from 'execa'; |
3 | 3 | import enq from 'enquirer';
|
4 | 4 | import { parse, stringify } from 'yaml';
|
5 | 5 |
|
6 | 6 | const { Select, prompt } = enq;
|
7 | 7 |
|
8 |
| -import * as readline from 'node:readline/promises'; |
9 |
| -import { stdin as input, stdout as output } from 'node:process'; |
10 |
| -import { readFile, writeFile } from 'node:fs/promises'; |
| 8 | +import { readFile } from 'node:fs/promises'; |
11 | 9 |
|
12 |
| -async function manual(description) { |
13 |
| - const rl = readline.createInterface({ input, output }); |
14 |
| - await rl.question(`🧑💻 ${description} |
15 |
| -
|
16 |
| -Press enter to continue...`); |
17 |
| - rl.close(); |
18 |
| -} |
19 |
| - |
20 |
| -/** |
21 |
| - * |
22 |
| - * @param {string} description |
23 |
| - */ |
24 |
| -function automated(description) { |
25 |
| - console.log(`🤖 ${description}`); |
26 |
| -} |
27 |
| - |
28 |
| -/** |
29 |
| - * |
30 |
| - * @param {string} command |
31 |
| - * @param {boolean} dryRun |
32 |
| - */ |
33 |
| -function dryExeca(command, dryRun = true) { |
34 |
| - if (dryRun) { |
35 |
| - console.log(`🌵 Dry run: '${command}'`); |
36 |
| - } else { |
37 |
| - console.log(`🤖 Running command '${command}'`); |
38 |
| - return execaCommand(command, { |
39 |
| - preferLocal: true, |
40 |
| - stdout: 'inherit', |
41 |
| - stdin: 'inherit', |
42 |
| - }); |
43 |
| - } |
44 |
| -} |
45 |
| - |
46 |
| -/** |
47 |
| - * |
48 |
| - * @param {string} file |
49 |
| - * @param {string} contents |
50 |
| - * @param {boolean} dryRun |
51 |
| - */ |
52 |
| -function dryWrite(file, contents, dryRun = true) { |
53 |
| - if (dryRun) { |
54 |
| - console.log(`🌵 Dry run: Updating the contents of '${file}' to be the following: |
55 |
| -
|
56 |
| -${contents}`); |
57 |
| - } else { |
58 |
| - return writeFile(file, contents, 'utf-8'); |
59 |
| - } |
60 |
| -} |
61 |
| - |
62 |
| -/** |
63 |
| - * |
64 |
| - * @param {string} error |
65 |
| - */ |
66 |
| -function fatalError(error) { |
67 |
| - console.error(error); |
68 |
| - process.exit(1); |
69 |
| -} |
| 10 | +import ensureRepo from './lib/ensure-repo.js'; |
| 11 | +import { automated, fatalError, manual } from './lib/log.js'; |
| 12 | +import { dryExeca } from './lib/dry-execa.js'; |
| 13 | +import dryWrite from './lib/dry-write.js'; |
70 | 14 |
|
71 | 15 | async function minimumNodeVersion(minVersion) {
|
72 | 16 | const { stdout: nodeVerison } = await execa`node --version`;
|
73 | 17 |
|
74 | 18 | if (!semver.gte(semver.clean(nodeVerison), semver.coerce(minVersion))) {
|
75 |
| - console.error( |
76 |
| - `Guides can only be installed with node version greater than ${minVersion} and above right now. you have ${nodeVerison}`, |
77 |
| - ); |
78 |
| - process.exit(1); |
79 |
| - } |
80 |
| -} |
81 |
| - |
82 |
| -async function ensureRepo(repo, branch, dryRun) { |
83 |
| - let stdout; |
84 |
| - |
85 |
| - try { |
86 |
| - let result = await execa`git remote get-url origin`; |
87 |
| - stdout = result.stdout; |
88 |
| - } catch (err) { |
89 |
| - fatalError( |
90 |
| - `Error checking current remote: [${err.message}]. Make sure you are in the cloned folder for ${repo}`, |
91 |
| - ); |
92 |
| - } |
93 |
| - |
94 |
| - if (repo !== stdout) { |
95 |
| - console.error( |
96 |
| - `It does not look like you are in the repo ${repo}. You can verify that you are by running 'git remote get-url origin'`, |
97 |
| - ); |
98 |
| - process.exit(1); |
99 |
| - } |
100 |
| - |
101 |
| - let { stdout: cleanDir } = await execa`git status --porcelain`; |
102 |
| - |
103 |
| - if (cleanDir.length) { |
104 |
| - fatalError(`Make sure you are in a clean working directory. You can verify this by making sure 'git status --porcelain' returns nothign. |
105 |
| -
|
106 |
| -Current response: |
107 |
| -${cleanDir}`); |
108 |
| - } |
109 |
| - |
110 |
| - let { stdout: currentBranch } = await execa`git rev-parse --abbrev-ref HEAD`; |
111 |
| - if (currentBranch !== branch) { |
112 | 19 | fatalError(
|
113 |
| - `Make sure you are on the '${branch}' branch. You are currently on '${currentBranch}'`, |
| 20 | + `Guides can only be installed with node version greater than ${minVersion} and above right now. you have ${nodeVerison}`, |
114 | 21 | );
|
115 | 22 | }
|
116 |
| - |
117 |
| - automated('Pulling latest changes from origin'); |
118 |
| - await dryExeca('git pull', dryRun); |
119 | 23 | }
|
120 | 24 |
|
121 | 25 | export default async function guides(args, options) {
|
@@ -176,6 +80,8 @@ export default async function guides(args, options) {
|
176 | 80 | automated(
|
177 | 81 | `Updating version number for links in /guides/${currentVersion}/**/*.md`,
|
178 | 82 | );
|
| 83 | + |
| 84 | + // TODO this should be pulled into this release scirpt rather than shelling out with execa |
179 | 85 | await dryExeca(
|
180 | 86 | `node ./scripts/update-version-links guides/${currentVersion} ${currentVersion.replace(/^v/, '')} ${semver.coerce(emberDataCurrentVersion)} --silent`,
|
181 | 87 | dryRun,
|
|
0 commit comments