Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.

Commit 459c0dd

Browse files
committed
feat: Add standalone yarn file to install and uninstall packages (inspired from Hyper)
1 parent 4720ed0 commit 459c0dd

File tree

10 files changed

+147445
-108
lines changed

10 files changed

+147445
-108
lines changed

cli/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "squid-cli",
3-
"version": "0.2.0-canary",
3+
"version": "0.3.0-canary",
44
"description": "The CLI for Squid.",
55
"author": {
66
"email": "[email protected]",
@@ -17,7 +17,6 @@
1717
},
1818
"dependencies": {
1919
"chalk": "^4.1.0",
20-
"get-installed-path": "^4.0.8",
2120
"inquirer": "^8.0.0",
2221
"yargs": "^16.2.0"
2322
},

cli/src/commands/install.ts

+16-21
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Arguments, Argv, CommandModule } from 'yargs';
22
import chalk from 'chalk';
33
import { getConfig, PACKAGES_PATH, saveConfig } from '../utils/config';
44
import { spawn } from 'child_process';
5-
import { getInstalledPath } from 'get-installed-path';
5+
import { YARN_PATH } from '../utils/utils';
66

77
export const install: CommandModule = {
88

@@ -33,32 +33,27 @@ export const install: CommandModule = {
3333
console.log(`Installing ${packageName} in ${chalk.green(PACKAGES_PATH)}...`);
3434
console.log(' ');
3535

36-
getInstalledPath('yarn').then((path) => {
36+
const install = spawn(process.execPath, [YARN_PATH, 'add', '--cwd', process.env.HOME, '--modules-folder', '.squid', packageName], { stdio: 'inherit', env: process.env });
3737

38-
path += '/bin/yarn';
38+
install.on('message', (msg) => console.log(msg))
39+
install.on('exit', (code) => {
3940

40-
const install = spawn(path, ['add', '--cwd', process.env.HOME, '--modules-folder', '.squid', '--no-lockfile', packageName], { stdio: 'inherit', env: process.env });
41+
if(code !== 0) {
4142

42-
install.on('message', (msg) => console.log(msg))
43-
install.on('exit', (code) => {
43+
console.log('Installation failed!')
44+
return;
45+
}
4446

45-
if(code !== 0) {
46-
47-
console.log('Installation failed!')
48-
return;
49-
}
50-
51-
const config = getConfig();
52-
saveConfig({
53-
...config,
54-
packages: [...config.packages, packageName],
55-
});
47+
const config = getConfig();
48+
saveConfig({
49+
...config,
50+
packages: [...config.packages, packageName],
51+
});
5652

57-
console.log(' ');
58-
console.log('Success!');
53+
console.log(' ');
54+
console.log('Success!');
5955

60-
process.exit(0);
61-
});
56+
process.exit(0);
6257
});
6358
},
6459
};

cli/src/commands/list.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export const getPackages = (): PackageItem[] => {
3737
else {
3838

3939
try {
40-
// eslint-disable-next-line @typescript-eslint/no-var-requires
41-
const { name: pName, version: pVersion } = require(packagePath);
40+
const { name: pName, version: pVersion } = JSON.parse(fs.readFileSync(packageJsonPath).toString());
4241
name = pName;
4342
version = pVersion;
4443

@@ -63,11 +62,19 @@ export const list: CommandModule = {
6362
describe: 'List installed package',
6463
handler: () => {
6564

65+
const packages = getPackages();
66+
67+
if(packages.length === 0) {
68+
69+
console.log(chalk.red('Not packages installed.'));
70+
return;
71+
}
72+
6673
console.log(' ');
6774
console.log(`Installed packages in ${chalk.green(PACKAGES_PATH)}`);
6875
console.log(' ');
6976

70-
getPackages().forEach(({ name, version, error }) => {
77+
packages.forEach(({ name, version, error }) => {
7178

7279
console.log(` - ${name} ${chalk.gray('v' + version)}`);
7380
error && console.log(` \\=> ${chalk.red(error)}`);

cli/src/commands/new.ts

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Arguments, Argv, CommandModule } from 'yargs';
22
import inquirer from 'inquirer'
33
import { resolveArgPath } from '../utils/utils';
44
import { initializeProject, Language, PackageType } from '../new/new';
5+
import chalk from 'chalk';
56

67
export const newCommand: CommandModule = {
78

@@ -28,6 +29,12 @@ export const newCommand: CommandModule = {
2829
const path = resolveArgPath(args);
2930
const useYarn = !args.npm;
3031

32+
if(!useYarn) {
33+
34+
console.log(chalk.red('NPM is not yet supported to install packages.'));
35+
return;
36+
}
37+
3138
inquirer.prompt([
3239
{
3340
type: 'input',

cli/src/commands/uninstall.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Arguments, CommandModule } from 'yargs';
22
import chalk from 'chalk';
33
import { getConfig, PACKAGES_PATH, saveConfig } from '../utils/config';
44
import { spawn } from 'child_process';
5-
import path from 'path';
65
import { getPackages } from './list';
6+
import { YARN_PATH } from '../utils/utils';
77

88
export const uninstall: CommandModule = {
99

@@ -15,7 +15,7 @@ export const uninstall: CommandModule = {
1515
const packageName = args.name as string;
1616
const packages = getPackages();
1717

18-
if(packages.every(({ name }) => name !== packageName)) {
18+
if(!packages.find(({ name }) => name === packageName)) {
1919

2020
console.log(chalk.red(`${packageName} is not installed.`));
2121
return;
@@ -25,9 +25,16 @@ export const uninstall: CommandModule = {
2525
console.log(`Uninstalling ${packageName} in ${chalk.green(PACKAGES_PATH)}...`);
2626
console.log(' ');
2727

28-
const install = spawn('rm', ['-rf', path.join(PACKAGES_PATH, packageName)], { stdio: 'inherit' });
28+
const install = spawn(process.execPath, [YARN_PATH, 'remove', '--cwd', process.env.HOME, '--modules-folder', '.squid', packageName], { stdio: 'inherit' });
2929

30-
install.on('exit', () => {
30+
install.on('message', (msg) => console.log(msg))
31+
install.on('exit', (code) => {
32+
33+
if(code !== 0) {
34+
35+
console.log('Uninstallation failed!')
36+
return;
37+
}
3138

3239
const config = getConfig();
3340
saveConfig({

cli/src/new/new.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { javascriptThemeTemplate } from './templates/javascript-theme';
66
import { javascriptPluginTemplate } from './templates/javascript-plugin';
77
import { typescriptPluginTemplate } from './templates/typescript-plugin';
88
import { typescriptThemeTemplate } from './templates/typescript-theme';
9+
import { YARN_PATH } from '../utils/utils';
910

1011
export type PackageType = 'Theme' | 'Plugin';
1112
export type Language = 'TypeScript' | 'JavaScript';
@@ -79,7 +80,7 @@ export const initializeProject = (name: string, path: string, useYarn: boolean,
7980
console.log(`Installing ${chalk.blue(packages.join(', '))}`);
8081
console.log(' ');
8182

82-
const install = spawn(useYarn ? 'yarn' : 'npm', useYarn ? ['add', '--cwd', projectPath, '-D', ...packages] : ['i', '--prefix', projectPath, '--dev', ...packages], { stdio: 'inherit' });
83+
const install = spawn(process.execPath, [YARN_PATH, 'add', '--cwd', projectPath, '-D', ...packages], { stdio: 'inherit' });
8384

8485
install.on('message', (msg) => console.log(msg))
8586
install.on('exit', () => {

cli/src/utils/utils.ts

+5
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ export const resolveArgPath = (args: Arguments) => {
99

1010
export const isMac = process.platform === 'darwin';
1111
export const isWin = process.platform === 'win32';
12+
13+
export const YARN_PATH = isMac ?
14+
'/Applications/Squid.app/Contents/Resources/bin/yarn' : isWin ?
15+
'' :
16+
'';

cli/yarn.lock

-76
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,6 @@ escape-string-regexp@^1.0.5:
134134
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
135135
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
136136

137-
expand-tilde@^2.0.0, expand-tilde@^2.0.2:
138-
version "2.0.2"
139-
resolved "https://registry.yarnpkg.com/expand-tilde/-/expand-tilde-2.0.2.tgz#97e801aa052df02454de46b02bf621642cdc8502"
140-
integrity sha1-l+gBqgUt8CRU3kawK/YhZCzchQI=
141-
dependencies:
142-
homedir-polyfill "^1.0.1"
143-
144137
external-editor@^3.0.3:
145138
version "3.1.0"
146139
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495"
@@ -162,57 +155,18 @@ get-caller-file@^2.0.5:
162155
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
163156
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==
164157

165-
get-installed-path@^4.0.8:
166-
version "4.0.8"
167-
resolved "https://registry.yarnpkg.com/get-installed-path/-/get-installed-path-4.0.8.tgz#a4fee849f5f327c12c551bb37477acd5151e5f7d"
168-
integrity sha512-PmANK1xElIHlHH2tXfOoTnSDUjX1X3GvKK6ZyLbUnSCCn1pADwu67eVWttuPzJWrXDDT2MfO6uAaKILOFfitmA==
169-
dependencies:
170-
global-modules "1.0.0"
171-
172-
[email protected], global-modules@^1.0.0:
173-
version "1.0.0"
174-
resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-1.0.0.tgz#6d770f0eb523ac78164d72b5e71a8877265cc3ea"
175-
integrity sha512-sKzpEkf11GpOFuw0Zzjzmt4B4UZwjOcG757PPvrfhxcLFbq0wpsgpOqxpxtxFiCG4DtG93M6XRVbF2oGdev7bg==
176-
dependencies:
177-
global-prefix "^1.0.1"
178-
is-windows "^1.0.1"
179-
resolve-dir "^1.0.0"
180-
181-
global-prefix@^1.0.1:
182-
version "1.0.2"
183-
resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-1.0.2.tgz#dbf743c6c14992593c655568cb66ed32c0122ebe"
184-
integrity sha1-2/dDxsFJklk8ZVVoy2btMsASLr4=
185-
dependencies:
186-
expand-tilde "^2.0.2"
187-
homedir-polyfill "^1.0.1"
188-
ini "^1.3.4"
189-
is-windows "^1.0.1"
190-
which "^1.2.14"
191-
192158
has-flag@^4.0.0:
193159
version "4.0.0"
194160
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
195161
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==
196162

197-
homedir-polyfill@^1.0.1:
198-
version "1.0.3"
199-
resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz#743298cef4e5af3e194161fbadcc2151d3a058e8"
200-
integrity sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==
201-
dependencies:
202-
parse-passwd "^1.0.0"
203-
204163
iconv-lite@^0.4.24:
205164
version "0.4.24"
206165
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
207166
integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==
208167
dependencies:
209168
safer-buffer ">= 2.1.2 < 3"
210169

211-
ini@^1.3.4:
212-
version "1.3.8"
213-
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
214-
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==
215-
216170
inquirer@^8.0.0:
217171
version "8.0.0"
218172
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.0.0.tgz#957a46db1abcf0fdd2ab82deb7470e90afc7d0ac"
@@ -237,16 +191,6 @@ is-fullwidth-code-point@^3.0.0:
237191
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d"
238192
integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==
239193

240-
is-windows@^1.0.1:
241-
version "1.0.2"
242-
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d"
243-
integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==
244-
245-
isexe@^2.0.0:
246-
version "2.0.0"
247-
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
248-
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
249-
250194
lodash@^4.17.21:
251195
version "4.17.21"
252196
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
@@ -279,24 +223,11 @@ os-tmpdir@~1.0.2:
279223
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
280224
integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=
281225

282-
parse-passwd@^1.0.0:
283-
version "1.0.0"
284-
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
285-
integrity sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY=
286-
287226
require-directory@^2.1.1:
288227
version "2.1.1"
289228
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
290229
integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I=
291230

292-
resolve-dir@^1.0.0:
293-
version "1.0.1"
294-
resolved "https://registry.yarnpkg.com/resolve-dir/-/resolve-dir-1.0.1.tgz#79a40644c362be82f26effe739c9bb5382046f43"
295-
integrity sha1-eaQGRMNivoLybv/nOcm7U4IEb0M=
296-
dependencies:
297-
expand-tilde "^2.0.0"
298-
global-modules "^1.0.0"
299-
300231
restore-cursor@^3.1.0:
301232
version "3.1.0"
302233
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-3.1.0.tgz#39f67c54b3a7a58cea5236d95cf0034239631f7e"
@@ -402,13 +333,6 @@ typescript@^4.2.3:
402333
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.3.tgz#39062d8019912d43726298f09493d598048c1ce3"
403334
integrity sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==
404335

405-
which@^1.2.14:
406-
version "1.3.1"
407-
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
408-
integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==
409-
dependencies:
410-
isexe "^2.0.0"
411-
412336
wrap-ansi@^7.0.0:
413337
version "7.0.0"
414338
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "squid",
3-
"version": "0.2.0-canary",
3+
"version": "0.3.0-canary",
44
"description": "The extendible Shell and SSH terminal, with E2E encryption in the cloud.",
55
"author": {
66
"email": "[email protected]",

0 commit comments

Comments
 (0)