Skip to content

Commit

Permalink
feat: support installer/tarballs (#2)
Browse files Browse the repository at this point in the history
* feat: support installer/tarballs

* chore: bump deps
  • Loading branch information
cristiand391 authored Nov 10, 2023
1 parent bfc2f34 commit f2bf02d
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 193 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
"/oclif.manifest.json"
],
"dependencies": {
"@oclif/core": "^2.15.0",
"@salesforce/core": "^5.3.1",
"@salesforce/source-deploy-retrieve": "^9.7.19",
"@oclif/core": "^3.10.7",
"@salesforce/core": "^5.3.18",
"@salesforce/source-deploy-retrieve": "^9.8.4",
"chalk": "^4.1.2"
},
"devDependencies": {
"@types/cli-progress": "^3.11.5",
"@types/node": "^20.6.4",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
Expand Down
8 changes: 4 additions & 4 deletions src/commands/__fzf_complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export default class __FzfComplete extends Command {

switch (args.comp) {
case 'all-plugins':
for (const plugin of this.config.plugins) {
output += `${plugin.name}\t(${plugin.type})\n`;
for (const [name, plugin] of this.config.plugins) {
output += `${name}\t(${plugin.type})\n`;
}
break;
case 'user-plugins':
for (const plugin of this.config.plugins) {
for (const [name, plugin] of this.config.plugins) {
if (plugin.type !== 'core') {
output += `${plugin.name}\t(${plugin.type})\n`;
output += `${name}\t(${plugin.type})\n`;
}
}
break;
Expand Down
46 changes: 43 additions & 3 deletions src/comp-gen.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Interfaces } from '@oclif/core';
import { writeFile, mkdir } from 'node:fs/promises';
import {
writeFile,
mkdir,
readdir,
realpath,
constants,
access,
} from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { format } from 'node:util';
import { normalize } from 'node:path';
import { normalize, join } from 'node:path';

export async function genCompletion(
config: Interfaces.Config,
Expand Down Expand Up @@ -35,6 +42,38 @@ export async function genCompletion(

await writeFile(commandsFile, JSON.stringify(commands));

const isExecutable = async (filepath: string): Promise<boolean> => {
try {
if (filepath.endsWith('node')) {
// This checks if the filepath is executable on Mac or Linux, if it is not it errors.
await access(filepath, constants.X_OK);
return true;
}
} catch {
return false;
}
return false;
};

const getNodeBinPath = async (root: string): Promise<string | undefined> => {
const binDirs = [join(root, 'bin'), join(root, 'client', 'bin')].filter(
(p) => existsSync(p),
);

if (binDirs.length > 0) {
for (const dir of binDirs) {
const nodeExecutable = (await readdir(dir))
.map((bin) => `${dir}/${bin}`)
.filter(isExecutable)[0];
if (nodeExecutable.length > 0) {
return realpath(nodeExecutable);
}
}
}
};

const nodeBin = config.binPath ? await getNodeBinPath(config.root) : 'node';

const fzfCompleteFuncTpl = `_fzf_complete_sf() {
if [[ "$@" == "sf " || "$@" == "sf which " || "$@" == "sf help " ]]; then
local commands_file preview_command
Expand All @@ -46,7 +85,7 @@ export async function genCompletion(
jq -r '.[] | .id' $commands_file
)
else
local comp=$(node %s "$@")
local comp=$(%s %s "$@")
_fzf_complete --select-1 --ansi --prompt="sf> " -- "$@" < <(
echo $comp
)
Expand All @@ -69,6 +108,7 @@ _fzf_complete_sf_post() {
format(
fzfCompleteFuncTpl,
commandsFile,
nodeBin,
normalize(`${__filename}/../../lib/shell-completion.js`),
),
);
Expand Down
Loading

0 comments on commit f2bf02d

Please sign in to comment.