Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/use_esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
cstrnt committed Jul 22, 2021
2 parents bd70b6a + 3ed44b6 commit 2e32ed2
Show file tree
Hide file tree
Showing 9 changed files with 2,412 additions and 104 deletions.
756 changes: 756 additions & 0 deletions dev/aws/cloudwatch.ts

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions dev/bazel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const bazelBuildFiles: Fig.Generator = {
script: `FILES=( $(find ./ -name BUILD) ); for f in $FILES; do echo "----$f"; cat "$f"; done`,
// returns filepaths and contents in the form below, note the "----" to indicate the filepath
// ----.//lib/BUILD
// load("@rules_cc//cc:defs.bzl", "cc_library")

// cc_library(
// name = "hello-time",
// srcs = ["hello-time.cc"],
// hdrs = ["hello-time.h"],
// visibility = ["//main:__pkg__"],
// )

postProcess: function (out) {
const lines = out.split("\n");
// return lines
const targets = [];
let currPath = "";
for (let i = 0; i < lines.length; i++) {
const isFilepath = lines[i].match("----.(.*)/BUILD");
const isBazelTarget = lines[i].match('name = "(.*)"');
if (isFilepath) {
currPath = isFilepath[1] + ":";
} else if (isBazelTarget) {
targets.push({
name: currPath + isBazelTarget[1],
description: "bazel target",
icon: "🎯",
priority: 80,
});
}
}
return targets;
},
};

const completionSpec: Fig.Spec = {
name: "bazel",
description: "Bazel the build system!",
subcommands: [
{
name: "run",
description: "Runs the specified target.",
args: {
name: "BUILD file",
generators: bazelBuildFiles,
},
},
{
name: "test",
description: "Builds and runs the specified test targets.",
args: {
name: "BUILD file",
generators: bazelBuildFiles,
},
},
{
name: "build",
description: "Builds the specified targets..",
args: {
name: "BUILD file",
generators: bazelBuildFiles,
},
},
],
};

export default completionSpec;
98 changes: 98 additions & 0 deletions dev/composer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
interface ComposerArgument {
name: string;
is_required: boolean;
is_array: boolean;
description: string;
default: null | string | Array<string>;
}

interface ComposerOption {
name: string;
shortcut: string;
accept_value: boolean;
is_value_required: boolean;
is_multiple: boolean; // not supported by fig
description: string;
default: null | boolean; // not supported by fig
}

interface ComposerCommandDefinition {
arguments: Record<string, ComposerArgument>;
options: Record<string, ComposerOption>;
}

interface ComposerCommand {
name: string;
usage: string[]; // this is actually generated by fig
description: string;
help: string; //
definition: ComposerCommandDefinition;
}

interface ComposerListOutput {
commands: ComposerCommand[];
}

const completionSpec: Fig.Spec = {
name: "composer",
description: "Composer Command",

generateSpec: async (context, executeShellCommand) => {
const jsonList = await executeShellCommand("composer list --format=json");
const subcommands: Fig.Subcommand[] = [];

try {
const data: ComposerListOutput = JSON.parse(jsonList);
for (const command of data.commands) {
subcommands.push({
name: command.name,
description: command.description,
icon: "https://getcomposer.org/img/logo-composer-transparent5.png",

args: Object.keys(command.definition.arguments).map((argKey) => {
const arg = command.definition.arguments[argKey];
const argDefault = arg.default
? Array.isArray(arg.default)
? arg.default[0]
: arg.default
: undefined;

return {
name: arg.name,
description: arg.description,
isOptional: !arg.is_required,
default: argDefault,
variadic: arg.is_array,
};
}),

options: Object.keys(command.definition.options).map((optionKey) => {
const option = command.definition.options[optionKey];
const names = [option.name];

const shortCut = option.shortcut;
if (shortCut.trim().length > 0) {
names.push(shortCut);
}

return {
name: names,
description: option.description,
required: option.is_value_required,
args: option.accept_value ? {} : undefined,
};
}),
});
}
} catch (err) {
console.error(err);
}

return {
name: "composer",
subcommands,
};
},
};

export default completionSpec;
Loading

0 comments on commit 2e32ed2

Please sign in to comment.