Skip to content

Commit 549c800

Browse files
committed
Updated python, ssh (partial), pgcli, shell, scripting, npm resources
1 parent 844dd79 commit 549c800

28 files changed

+191
-151
lines changed

src/resources/javascript/npm/global-install.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ParameterSetting, Plan, StatefulParameter, getPty } from 'codify-plugin-lib';
22

3-
import { codifySpawn } from '../../../utils/codify-spawn.js';
43
import { NpmConfig } from './npm.js';
54

65
export interface NpmPackage {
@@ -74,6 +73,7 @@ export class NpmGlobalInstallParameter extends StatefulParameter<NpmConfig, Arra
7473
}
7574

7675
async install(packages: Array<NpmPackage | string>): Promise<void> {
76+
const $ = getPty();
7777
const installStatements = packages.map((p) => {
7878
if (typeof p === 'string') {
7979
return p;
@@ -86,10 +86,11 @@ export class NpmGlobalInstallParameter extends StatefulParameter<NpmConfig, Arra
8686
return p.name;
8787
})
8888

89-
await codifySpawn(`npm install --global ${installStatements.join(' ')}`);
89+
await $.spawn(`npm install --global ${installStatements.join(' ')}`, { interactive: true });
9090
}
9191

9292
async uninstall(packages: Array<NpmPackage | string>): Promise<void> {
93+
const $ = getPty();
9394
const uninstallStatements = packages.map((p) => {
9495
if (typeof p === 'string') {
9596
return p;
@@ -98,7 +99,7 @@ export class NpmGlobalInstallParameter extends StatefulParameter<NpmConfig, Arra
9899
return p.name;
99100
})
100101

101-
await codifySpawn(`npm uninstall --global ${uninstallStatements.join(' ')}`);
102+
await $.spawn(`npm uninstall --global ${uninstallStatements.join(' ')}`, { interactive: true });
102103
}
103104

104105

src/resources/javascript/npm/npm-login.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import {
22
CreatePlan,
3-
DestroyPlan, getPty,
3+
DestroyPlan,
4+
getPty,
45
ModifyPlan,
56
ParameterChange,
67
Resource,
78
ResourceSettings,
89
} from 'codify-plugin-lib';
9-
import { ResourceConfig } from 'codify-schemas';
10+
import { OS, ResourceConfig } from 'codify-schemas';
1011
import * as fsSync from 'node:fs';
1112
import fs from 'node:fs/promises';
1213
import os from 'node:os';
1314
import path from 'node:path';
1415

15-
import { codifySpawn } from '../../../utils/codify-spawn.js';
1616
import schema from './npm-login-schema.json';
1717

1818
export interface NpmLoginConfig extends ResourceConfig {
@@ -25,6 +25,7 @@ export class NpmLoginResource extends Resource<NpmLoginConfig> {
2525
getSettings(): ResourceSettings<NpmLoginConfig> {
2626
return {
2727
id: 'npm-login',
28+
operatingSystems: [OS.Darwin, OS.Linux],
2829
schema,
2930
isSensitive: true,
3031
dependencies: ['npm'],
@@ -215,7 +216,8 @@ export class NpmLoginResource extends Resource<NpmLoginConfig> {
215216
}
216217

217218
private async ensureNpmAvailable(): Promise<void> {
218-
await codifySpawn('which npm');
219+
const $ = getPty();
220+
await $.spawn('which npm', { interactive: true });
219221
}
220222

221223
private async ensureFile(filePath: string): Promise<void> {

src/resources/javascript/npm/npm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Resource, ResourceSettings, getPty } from 'codify-plugin-lib';
2-
import { ResourceConfig } from 'codify-schemas';
2+
import { OS, ResourceConfig } from 'codify-schemas';
33

44
import { NpmGlobalInstallParameter, NpmPackage } from './global-install.js';
55
import schema from './npm-schema.json'
@@ -12,6 +12,7 @@ export class Npm extends Resource<NpmConfig> {
1212
getSettings(): ResourceSettings<NpmConfig> {
1313
return {
1414
id: 'npm',
15+
operatingSystems: [OS.Darwin],
1516
schema,
1617
parameterSettings: {
1718
globalInstall: { type: 'stateful', definition: new NpmGlobalInstallParameter() },

src/resources/javascript/nvm/global-parameter.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { getPty, ParameterSetting, SpawnStatus, StatefulParameter } from 'codify-plugin-lib';
22

3-
import { codifySpawn } from '../../../utils/codify-spawn.js';
43
import { NvmConfig } from './nvm.js';
54

65
export class NvmGlobalParameter extends StatefulParameter<NvmConfig, string>{
@@ -24,11 +23,13 @@ export class NvmGlobalParameter extends StatefulParameter<NvmConfig, string>{
2423
}
2524

2625
override async add(valueToAdd: string): Promise<void> {
27-
await codifySpawn(`nvm alias default ${valueToAdd}`)
26+
const $ = getPty();
27+
await $.spawn(`nvm alias default ${valueToAdd}`, { interactive: true })
2828
}
2929

3030
override async modify(newValue: string): Promise<void> {
31-
await codifySpawn(`nvm alias default ${newValue}`)
31+
const $ = getPty();
32+
await $.spawn(`nvm alias default ${newValue}`, { interactive: true })
3233
}
3334

3435
override async remove(valueToRemove: string): Promise<void> {

src/resources/javascript/nvm/node-versions-parameter.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { ArrayParameterSetting, ArrayStatefulParameter, getPty } from 'codify-plugin-lib';
1+
import { ArrayParameterSetting, ArrayStatefulParameter, getPty, SpawnStatus } from 'codify-plugin-lib';
22

3-
import { SpawnStatus, codifySpawn } from '../../../utils/codify-spawn.js';
43
import { NvmConfig } from './nvm.js';
54

65
export class NvmNodeVersionsParameter extends ArrayStatefulParameter<NvmConfig, string> {
@@ -50,10 +49,12 @@ export class NvmNodeVersionsParameter extends ArrayStatefulParameter<NvmConfig,
5049
}
5150

5251
override async addItem(version: string): Promise<void> {
53-
await codifySpawn(`nvm install ${version}`);
52+
const $ = getPty();
53+
await $.spawn(`nvm install ${version}`, { interactive: true });
5454
}
5555

5656
override async removeItem(version: string): Promise<void> {
57-
await codifySpawn(`nvm uninstall ${version}`);
57+
const $ = getPty();
58+
await $.spawn(`nvm uninstall ${version}`, { interactive: true });
5859
}
5960
}

src/resources/javascript/nvm/nvm.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { getPty, Resource, ResourceSettings } from 'codify-plugin-lib';
1+
import { getPty, Resource, ResourceSettings, SpawnStatus } from 'codify-plugin-lib';
22
import { OS, ResourceConfig } from 'codify-schemas';
33
import * as os from 'node:os';
44

5-
import { SpawnStatus, codifySpawn } from '../../../utils/codify-spawn.js';
65
import { FileUtils } from '../../../utils/file-utils.js';
76
import { Utils } from '../../../utils/index.js';
87
import { NvmGlobalParameter } from './global-parameter.js';
@@ -40,30 +39,32 @@ export class NvmResource extends Resource<NvmConfig> {
4039
}
4140

4241
override async create(): Promise<void> {
42+
const $ = getPty();
4343
// Node installer was previously used.
44-
const { data } = await codifySpawn('echo $npm_config_prefix')
44+
const { data } = await $.spawn('echo $npm_config_prefix', { interactive: true })
4545
if (data.trim() !== '') {
4646
await FileUtils.addToStartupFile('unset npm_config_prefix');
4747
}
4848

49-
const { data: installResult } = await codifySpawn('curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash')
49+
const { data: installResult } = await $.spawn('curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash', { interactive: true })
5050

5151
// Nvm doesn't handle if the init string is commented out
5252
// This check first checks that nvm detects the init string is there but nvm itself is still not present
5353
const shellRc = Utils.getPrimaryShellRc();
5454
if (installResult.includes(`nvm source string already in ${shellRc}`)
55-
&& (await codifySpawn('which nvm', { throws: false })).status === SpawnStatus.ERROR
55+
&& (await $.spawnSafe('which nvm', { interactive: true })).status === SpawnStatus.ERROR
5656
) {
5757
await FileUtils.addToStartupFile('export NVM_DIR="$HOME/.nvm"')
5858
await FileUtils.addToStartupFile('[ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh" ');
5959
}
6060
}
6161

6262
override async destroy(): Promise<void> {
63+
const $ = getPty();
6364
// eslint-disable-next-line no-template-curly-in-string
64-
const { data: nvmDir } = await codifySpawn('echo "${NVM_DIR:-~/.nvm}"');
65-
await codifySpawn('nvm unload');
66-
await codifySpawn(`rm -rf ${nvmDir.trim()}`, { cwd: os.homedir() });
65+
const { data: nvmDir } = await $.spawn('echo "${NVM_DIR:-~/.nvm}"', { interactive: true });
66+
await $.spawn('nvm unload', { interactive: true });
67+
await $.spawn(`rm -rf ${nvmDir.trim()}`, { cwd: os.homedir() });
6768

6869
await FileUtils.removeLineFromZshrc('export NVM_DIR="$HOME/.nvm"')
6970
await FileUtils.removeLineFromZshrc('[ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh" # This loads nvm')

src/resources/javascript/pnpm/pnpm-global-env-stateful-parameter.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ParameterSetting, StatefulParameter, getPty } from 'codify-plugin-lib';
22
import fs from 'node:fs/promises';
33

4-
import { codifySpawn } from '../../../utils/codify-spawn.js';
54
import { FileUtils } from '../../../utils/file-utils.js';
65
import { PnpmConfig } from './pnpm.js';
76

@@ -26,15 +25,18 @@ export class PnpmGlobalEnvStatefulParameter extends StatefulParameter<PnpmConfig
2625
}
2726

2827
async add(valueToAdd: string): Promise<void> {
29-
await codifySpawn(`pnpm env use --global ${valueToAdd}`);
28+
const $ = getPty();
29+
await $.spawn(`pnpm env use --global ${valueToAdd}`, { interactive: true });
3030
}
3131

3232
async modify(newValue: string): Promise<void> {
33-
await codifySpawn(`pnpm env use --global ${newValue}`)
33+
const $ = getPty();
34+
await $.spawn(`pnpm env use --global ${newValue}`, { interactive: true })
3435
}
3536

3637
async remove(): Promise<void> {
37-
const { data: path } = await codifySpawn('echo $PNPM_HOME/nodejs')
38+
const $ = getPty();
39+
const { data: path } = await $.spawn('echo $PNPM_HOME/nodejs', { interactive: true })
3840
await fs.rm(path!, { recursive: true, force: true });
3941
}
4042
}

src/resources/javascript/pnpm/pnpm.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import fs from 'node:fs/promises';
44
import os from 'node:os';
55
import path from 'node:path';
66

7-
import { codifySpawn } from '../../../utils/codify-spawn.js';
87
import { FileUtils } from '../../../utils/file-utils.js';
98
import { Utils } from '../../../utils/index.js';
109
import { PnpmGlobalEnvStatefulParameter } from './pnpm-global-env-stateful-parameter.js';
@@ -46,20 +45,22 @@ export class Pnpm extends Resource<PnpmConfig> {
4645
}
4746

4847
async create(plan: CreatePlan<PnpmConfig>): Promise<void> {
48+
const $ = getPty();
4949
const specificVersion = plan.desiredConfig.version;
5050

5151
specificVersion
52-
? await codifySpawn(`curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION=${specificVersion} sh -`)
53-
: await codifySpawn('curl -fsSL https://get.pnpm.io/install.sh | sh -')
52+
? await $.spawn(`curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION=${specificVersion} sh -`, { interactive: true })
53+
: await $.spawn('curl -fsSL https://get.pnpm.io/install.sh | sh -', { interactive: true })
5454
}
5555

5656
async destroy(plan: DestroyPlan<PnpmConfig>): Promise<void> {
57-
const { data: pnpmLocation } = await codifySpawn('which pnpm');
57+
const $ = getPty();
58+
const { data: pnpmLocation } = await $.spawn('which pnpm', { interactive: true });
5859
if (pnpmLocation.trim().toLowerCase() !== path.join(os.homedir(), 'Library', 'pnpm', 'pnpm').trim().toLowerCase()) {
5960
throw new Error('pnpm was installed outside of Codify. Please uninstall manually and re-run Codify');
6061
}
6162

62-
const { data: pnpmHome } = await codifySpawn('echo $PNPM_HOME', { throws: false });
63+
const { data: pnpmHome } = await $.spawnSafe('echo $PNPM_HOME', { interactive: true });
6364
if (!pnpmHome) {
6465
throw new Error('$PNPM_HOME variable is not set. Unable to determine how to uninstall pnpm. Please uninstall manually and re-run Codify.')
6566
}

src/resources/macports/install-parameter.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ParameterSetting, Plan, StatefulParameter, getPty } from 'codify-plugin-lib';
22

3-
import { codifySpawn } from '../../utils/codify-spawn.js';
43
import { MacportsConfig } from './macports.js';
54

65
export interface PortPackage {
@@ -66,6 +65,7 @@ export class MacportsInstallParameter extends StatefulParameter<MacportsConfig,
6665
}
6766

6867
private async install(packages: Array<PortPackage | string>): Promise<void> {
68+
const $ = getPty();
6969
const toInstall = packages.map((p) => {
7070
if (typeof p === 'string') {
7171
return p;
@@ -74,14 +74,15 @@ export class MacportsInstallParameter extends StatefulParameter<MacportsConfig,
7474
if (p.version) {
7575
return `${p.name} ${p.version}`;
7676
}
77-
77+
7878
return p.name;
7979
}).join(' ');
8080

81-
await codifySpawn(`port install ${toInstall}`, { requiresRoot: true });
81+
await $.spawn(`port install ${toInstall}`, { requiresRoot: true, interactive: true });
8282
}
8383

8484
private async uninstall(packages: Array<PortPackage | string>): Promise<void> {
85+
const $ = getPty();
8586
const toInstall = packages.map((p) => {
8687
if (typeof p === 'string') {
8788
return p;
@@ -90,7 +91,7 @@ export class MacportsInstallParameter extends StatefulParameter<MacportsConfig,
9091
return p.name;
9192
}).join(' ');
9293

93-
await codifySpawn(`port uninstall ${toInstall}`, { requiresRoot: true });
94+
await $.spawn(`port uninstall ${toInstall}`, { requiresRoot: true, interactive: true });
9495
}
9596

9697
isSamePackage(a: PortPackage | string, b: PortPackage | string): boolean {

src/resources/macports/macports.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { CreatePlan, Resource, ResourceSettings, SpawnStatus, getPty } from 'codify-plugin-lib';
2-
import { ResourceConfig } from 'codify-schemas';
3-
import * as fsSync from 'node:fs';
2+
import { OS, ResourceConfig } from 'codify-schemas';
43
import * as fs from 'node:fs/promises';
54
import os from 'node:os';
65
import path from 'node:path';
76

8-
import { codifySpawn } from '../../utils/codify-spawn.js';
97
import { FileUtils } from '../../utils/file-utils.js';
108
import { Utils } from '../../utils/index.js';
119
import { MacportsInstallParameter, PortPackage } from './install-parameter.js';
@@ -33,6 +31,7 @@ export class MacportsResource extends Resource<MacportsConfig> {
3331
override getSettings(): ResourceSettings<MacportsConfig> {
3432
return {
3533
id: 'macports',
34+
operatingSystems: [OS.Darwin],
3635
schema,
3736
parameterSettings: {
3837
install: { type: 'stateful', definition: new MacportsInstallParameter() }
@@ -52,7 +51,8 @@ export class MacportsResource extends Resource<MacportsConfig> {
5251
}
5352

5453
override async create(plan: CreatePlan<MacportsConfig>): Promise<void> {
55-
const macOSVersion = (await codifySpawn('sw_vers --productVersion'))?.data?.split('.')?.at(0);
54+
const $ = getPty();
55+
const macOSVersion = (await $.spawn('sw_vers --productVersion'))?.data?.split('.')?.at(0);
5656
if (!macOSVersion) {
5757
throw new Error('Unable to determine macOS version');
5858
}
@@ -68,17 +68,18 @@ export class MacportsResource extends Resource<MacportsConfig> {
6868
console.log(`Downloading macports installer ${installerUrl}`)
6969
await Utils.downloadUrlIntoFile(installerPath, installerUrl);
7070

71-
await codifySpawn(`installer -pkg "${installerPath}" -target /;`, { requiresRoot: true })
71+
await $.spawn(`installer -pkg "${installerPath}" -target /;`, { requiresRoot: true })
7272

7373
await FileUtils.addToStartupFile('')
7474
await FileUtils.addToStartupFile('export PATH=/opt/local/bin:/opt/local/sbin:$PATH')
7575
}
7676

7777
override async destroy(): Promise<void> {
78-
await codifySpawn('port -fp uninstall installed', { requiresRoot: true, throws: false });
79-
await codifySpawn('dscl . -delete /Users/macports', { requiresRoot: true, throws: false });
80-
await codifySpawn('dscl . -delete /Groups/macports', { requiresRoot: true, throws: false });
81-
await codifySpawn('rm -rf \\\n' +
78+
const $ = getPty();
79+
await $.spawnSafe('port -fp uninstall installed', { requiresRoot: true, interactive: true });
80+
await $.spawnSafe('dscl . -delete /Users/macports', { requiresRoot: true });
81+
await $.spawnSafe('dscl . -delete /Groups/macports', { requiresRoot: true });
82+
await $.spawnSafe('rm -rf \\\n' +
8283
' /opt/local \\\n' +
8384
' /Applications/DarwinPorts \\\n' +
8485
' /Applications/MacPorts \\\n' +
@@ -88,7 +89,7 @@ export class MacportsResource extends Resource<MacportsConfig> {
8889
' /Library/StartupItems/DarwinPortsStartup \\\n' +
8990
' /Library/Tcl/darwinports1.0 \\\n' +
9091
' /Library/Tcl/macports1.0 \\\n' +
91-
' ~/.macports', { requiresRoot: true, throws: false })
92+
' ~/.macports', { requiresRoot: true })
9293

9394
await FileUtils.removeLineFromZshrc('export PATH=/opt/local/bin:/opt/local/sbin:$PATH');
9495

0 commit comments

Comments
 (0)