Skip to content

Commit a8f5ed5

Browse files
committed
chore: revert zx to execa
1 parent 34b025d commit a8f5ed5

File tree

7 files changed

+145
-49
lines changed

7 files changed

+145
-49
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
"dependencies": {
5151
"consola": "^3.4.2",
5252
"destr": "^2.0.5",
53+
"execa": "^5.1.1",
5354
"fs-extra": "^11.3.2",
5455
"gradient-string": "^3.0.0",
5556
"pathe": "^2.0.3",
56-
"sade": "^1.8.1",
57-
"zx": "^8.8.5"
57+
"sade": "^1.8.1"
5858
},
5959
"devDependencies": {
6060
"@types/fs-extra": "^11.0.4",

pnpm-lock.yaml

Lines changed: 75 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/git.ts

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { $ } from 'zx';
1+
import execa from 'execa';
22
import { success, error, info } from './console';
33
import { Commit, GitNewTag, GitPrerelease } from './types';
44
import { getRoot, setFile, getFile, getPackageRoot, getLernaRoot } from './utils';
@@ -30,16 +30,17 @@ export const parseCommitSummary = (commit: Commit) => {
3030
};
3131

3232
export const commits = (): Commit[] => {
33-
return $.sync`git log --oneline --pretty=hash<%h> ref<%D> message<%s> date<%cd>`.stdout
34-
.split('\n')
33+
return execa
34+
.sync('git', ['log', '--oneline --pretty=hash<%h> ref<%D> message<%s> date<%cd>'])
35+
.stdout.split('\n')
3536
.map(parseLogMessage);
3637
};
3738

3839
export const lastTag = (): string => {
3940
let last;
4041

4142
try {
42-
last = $.sync`git describe --abbrev=0 --tags`;
43+
last = execa.sync('git', ['describe', '--abbrev=0', '--tags']);
4344
} catch (e) {}
4445
if (!last) {
4546
error('Unable to fetch the last tag. First use the generi init command');
@@ -93,13 +94,23 @@ export const setVersion = (
9394
try {
9495
const asPrerelease = prerelease ? ['--preid', prerelease] : [];
9596

96-
$.sync`lerna version ${tag} ${asPrerelease.join(' ')} --no-private --no-changelog --no-git-tag-version --no-push --yes --force-publish`;
97+
execa.sync('lerna', [
98+
'version',
99+
tag,
100+
...asPrerelease,
101+
'--no-private',
102+
'--no-changelog',
103+
'--no-git-tag-version',
104+
'--no-push',
105+
'--yes',
106+
'--force-publish',
107+
]);
97108
} catch (e) {
98109
error(`Could not execute <lerna version ${tag}> command`);
99110
}
100111

101-
const lernaPrev = destr<Record<string, any>>(lerna);
102-
const lernaPost = destr<Record<string, any>>(getFile(getLernaRoot()));
112+
const lernaPrev = destr<Record<string, unknown>>(lerna);
113+
const lernaPost = destr<Record<string, unknown>>(getFile(getLernaRoot()));
103114

104115
// if lerna version has no previous workspace changes, it does not execute any command to change the version.
105116
if (lernaPrev.version === lernaPost.version) {
@@ -148,14 +159,14 @@ export const setVersion = (
148159
};
149160

150161
export const setTag = (target: string) => {
151-
const tags = $.sync`git tag -n`;
162+
const tags = execa.sync('git', ['tag', '-n']);
152163

153164
if (tags.stdout?.includes(target)) {
154165
error('Tag already exists!');
155166
return;
156167
}
157168

158-
const tag = $.sync`git tag ${target}`;
169+
const tag = execa.sync('git', ['tag', target]);
159170

160171
if (!tag) {
161172
error('Tag already exists!');
@@ -166,7 +177,7 @@ export const setTag = (target: string) => {
166177
};
167178

168179
export const initGit = () => {
169-
const init = $.sync`git init`;
180+
const init = execa.sync('git', ['init']);
170181

171182
if (!init) {
172183
error('Git is not installed.');
@@ -175,19 +186,19 @@ export const initGit = () => {
175186

176187
success('Initialized Git Project');
177188

178-
$.sync`git add -A`;
189+
execa.sync('git', ['add', '-A']);
179190

180191
success('Added All Staged Changes');
181192

182-
$.sync`git commit -m "chore(changelog): initial content"`;
193+
execa.sync('git', ['commit', '-m', 'chore(changelog): initial content']);
183194

184195
success('Commit Initial Content With Message: chore(changelog): initial content');
185196
};
186197

187198
export const setCommit = (message: string, log = true) => {
188-
$.sync`git add -A`;
199+
execa.sync('git', ['add', '-A']);
189200

190-
$.sync`git commit -m "${message}"`;
201+
execa.sync('git', ['commit', '-m', message]);
191202

192203
if (log) success('Commit With Message: ' + message);
193204
};
@@ -197,11 +208,11 @@ export const pushCommits = () => {
197208

198209
info(`Pushing...`);
199210

200-
const target = $.sync`git branch --show`;
211+
const target = execa.sync('git', ['branch', '--show']);
201212

202-
$.sync`git push origin ${target?.stdout || 'main'}`;
213+
execa.sync('git', ['push', 'origin', target?.stdout || 'main']);
203214

204-
$.sync`git push --tags`;
215+
execa.sync('git', ['push', '--tags']);
205216

206217
success('Success in Push!');
207218
};
@@ -218,18 +229,19 @@ export const revertAll = () => {
218229

219230
const tag = lastTag();
220231

221-
$.sync`git reset HEAD~1`;
232+
execa.sync('git', ['reset', 'HEAD~1']);
222233

223-
$.sync`git tag --delete ${tag}`;
234+
execa.sync('git', ['tag', '--delete', tag]);
224235

225-
$.sync`git checkout .`;
236+
execa.sync('git', ['checkout', '.']);
237+
``;
226238

227239
success(`Success in revert ${tag} tag!`);
228240
};
229241

230242
export const verifyExistentRemote = () => {
231243
try {
232-
$.sync`git remote -v`;
244+
execa.sync('git', ['remote', '-v']);
233245
} catch (e) {
234246
return false;
235247
}
@@ -249,7 +261,7 @@ export const isValidTag = (tag: GitNewTag) => {
249261
};
250262

251263
export const isCleanChanges = (): boolean => {
252-
const changes = $.sync`git diff HEAD`;
264+
const changes = execa.sync('git', ['diff', 'HEAD']);
253265

254266
return !changes.stdout;
255267
};

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env -vS zx
1+
#!/usr/bin/env node
22

33
import sade from 'sade';
44

@@ -8,7 +8,6 @@ import * as init from './commands/init';
88
import * as log from './commands/log';
99
import * as revert from './commands/revert';
1010
import * as test from './commands/test';
11-
import 'zx/globals'
1211

1312
(async function () {
1413
const prog = sade('generi');

0 commit comments

Comments
 (0)