rust-just 1.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,96 @@
1
+ 'use strict';
2
+
3
+ var execa = require('execa');
4
+ var url = require('url');
5
+ var os = require('os');
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ async function getExePath() {
10
+ const platform = os.platform();
11
+ const arch = os.arch();
12
+ let os$1 = platform;
13
+ let extension = "";
14
+ if (platform === "win32" || platform === "cygwin") {
15
+ os$1 = "windows";
16
+ extension = ".exe";
17
+ }
18
+ try {
19
+ return undefined(
20
+ `rust-just-${os$1}-${arch}/bin/just${extension}`
21
+ );
22
+ } catch (e) {
23
+ throw new Error(
24
+ `Couldn't find just binary inside node_modules for ${os$1}-${arch} (${e})`
25
+ );
26
+ }
27
+ }
28
+ __name(getExePath, "getExePath");
29
+
30
+ // src/optionsToStringArgs.ts
31
+ function optionsToStringArgs(options) {
32
+ const args = [];
33
+ for (const [key, value] of Object.entries(options)) {
34
+ const hyphenCaseKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
35
+ if ((key === "list" || key === "shellCommand" || key === "command") && typeof value === "string" && value.trim().length > 0) {
36
+ const values = value.match(/'([^']+)'/g)?.map((v) => v.replace(/'/g, "")) || [];
37
+ if (values.length > 0) {
38
+ args.push(`--${hyphenCaseKey}`, ...values);
39
+ }
40
+ } else if (key === "set" && typeof value === "string") {
41
+ const values = value.match(/'([^']+)'/g)?.map((v) => v.replace(/'/g, "")) || [];
42
+ if (values.length === 2) {
43
+ args.push(`--${hyphenCaseKey}`, values[0], values[1]);
44
+ }
45
+ } else if (key === "verbose" && typeof value === "number") {
46
+ for (let i = 0; i < value; i++) {
47
+ args.push(`--${hyphenCaseKey}`);
48
+ }
49
+ } else if (value === true) {
50
+ args.push(`--${hyphenCaseKey}`);
51
+ } else if (value === false || value === null) {
52
+ continue;
53
+ } else {
54
+ args.push(`--${hyphenCaseKey}`, String(value));
55
+ }
56
+ }
57
+ return args;
58
+ }
59
+ __name(optionsToStringArgs, "optionsToStringArgs");
60
+
61
+ // src/index.ts
62
+ function isOptionKey(arg, optionsKeys) {
63
+ return optionsKeys.includes(arg);
64
+ }
65
+ __name(isOptionKey, "isOptionKey");
66
+ async function runJust(argsOrOptions, execaOptions) {
67
+ const exePath = await getExePath();
68
+ let args = [];
69
+ const optionsKeys = Object.keys({ ...new class {
70
+ }() });
71
+ if (Array.isArray(argsOrOptions)) {
72
+ args = argsOrOptions;
73
+ } else {
74
+ const knownArgs = optionsToStringArgs(argsOrOptions);
75
+ for (const [key, value] of Object.entries(argsOrOptions)) {
76
+ const hyphenCaseKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
77
+ if (!isOptionKey(hyphenCaseKey, optionsKeys)) {
78
+ if (value === true) {
79
+ args.push(key);
80
+ } else if (value !== false && value !== null) {
81
+ args.push(key, String(value));
82
+ }
83
+ }
84
+ }
85
+ args = [...knownArgs, ...args];
86
+ }
87
+ return execa.execa(url.fileURLToPath(exePath), args, {
88
+ stdio: "inherit",
89
+ ...execaOptions
90
+ });
91
+ }
92
+ __name(runJust, "runJust");
93
+
94
+ exports.runJust = runJust;
95
+ //# sourceMappingURL=out.js.map
96
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/getExePath.ts","../../src/optionsToStringArgs.ts"],"names":[],"mappings":";;;;AAAA,SAAS,aAAmE;AAC5E,SAAS,qBAAqB;;;ACD9B,SAAS,QAAQ,SAAS,YAAY,mBAAmB;AAUzD,eAAsB,aAAa;AACjC,QAAM,WAAW,YAAY;AAC7B,QAAM,OAAO,QAAQ;AAErB,MAAI,KAAK;AACT,MAAI,YAAY;AAEhB,MAAI,aAAa,WAAW,aAAa,UAAU;AACjD,SAAK;AACL,gBAAY;AAAA,EACd;AAEA,MAAI;AAEF,WAAO,YAAY;AAAA,MACjB,aAA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/C;AAAA,EACF;AAEA,SAAO;AACT;AAlCgB;;;AFKhB,SAAS,YAAY,KAAa,aAAgC;AAChE,SAAO,YAAY,SAAS,GAAG;AACjC;AAFS;AAmDT,eAAsB,QAAQ,eAAmC,cAAgE;AAC/H,QAAM,UAAU,MAAM,WAAW;AACjC,MAAI,OAAiB,CAAC;AAEtB,QAAM,cAAc,OAAO,KAAK,EAAE,GAAG,IAAK,MAAyB;AAAA,EAAC,IAAG,CAAC;AAExE,MAAI,MAAM,QAAQ,aAAa,GAAG;AAChC,WAAO;AAAA,EACT,OAAO;AACL,UAAM,YAAY,oBAAoB,aAAa;AAEnD,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,aAAa,GAAG;AACxD,YAAM,gBAAgB,IAAI,QAAQ,YAAY,KAAK,EAAE,YAAY;AAEjE,UAAI,CAAC,YAAY,eAAe,WAAW,GAAG;AAC5C,YAAI,UAAU,MAAM;AAClB,eAAK,KAAK,GAAG;AAAA,QACf,WAAW,UAAU,SAAS,UAAU,MAAM;AAC5C,eAAK,KAAK,KAAK,OAAO,KAAK,CAAC;AAAA,QAC9B;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,GAAG,WAAW,GAAG,IAAI;AAAA,EAC/B;AAEA,SAAO,MAAM,cAAc,OAAO,GAAG,MAAM;AAAA,IACzC,OAAO;AAAA,IACP,GAAG;AAAA,EACL,CAAC;AACH;AA9BsB","sourcesContent":["import { execa, type Options as ExecaOptions, type ExecaReturnValue, } from \"execa\";\nimport { fileURLToPath } from \"node:url\";\nimport { getExePath } from \"./getExePath.js\";\nimport type { Options } from \"./options.js\";\nimport { optionsToStringArgs } from \"./optionsToStringArgs.js\";\n\nexport type { Options } from \"./options.js\";\n\n/**\n * Utility function to check if an argument exists in the predefined Options.\n * @param arg - The argument to check\n * @param optionsKeys - The list of keys from the Options type\n * @returns True if the argument exists in Options, false otherwise\n */\nfunction isOptionKey(arg: string, optionsKeys: string[]): boolean {\n return optionsKeys.includes(arg);\n}\n/**\n * Runs `just` with the provided options as a JavaScript object.\n *\n * @param options - The options to pass to `just`.\n * These get transformed into an array strings.\n * - Values that are `true` will be passed as flags (`--flag`).\n * - Values that are `false` or `null` will be ignored.\n * - All other values will be passed as options (`--option value`).\n *\n * @param execaOptions - Options to pass to {@link execa}.\n */\nexport async function runJust(options: Options, execaOptions?: ExecaOptions): Promise<ExecaReturnValue<string>>;\n/**\n * Runs the `just` with the provided arguments.\n *\n * @param args - The arguments to pass to `just`.\n * These should be in an array of string format.\n * Every option and their value should be its own entry in the array.\n *\n * @param execaOptions - Options to pass to {@link execa}.\n *\n * @returns A promise that resolves when the `just` has finished running.\n *\n * @example\n * Options with values\n * ```typescript\n * await runJust([\"--evaluate\", \"foo\"]);\n * ```\n * \n * @example\n * Options with array type values\n * ```typescript\n * await runJust([\"--set\", \"'<VARIABLE>' '<VALUE>'\"]);\n * ```\n *\n * @example\n * Boolean flags\n * ```typescript\n * await runJust([\"--version\"]);\n * ```\n * \n * @example\n * Justfile functions\n * ```typescript\n * await runJust([\"foo\"]);\n * ```\n */\nexport async function runJust(args: string[], execaOptions?: ExecaOptions): Promise<ExecaReturnValue<string>>;\nexport async function runJust(argsOrOptions: Options | string[], execaOptions?: ExecaOptions): Promise<ExecaReturnValue<string>> {\n const exePath = await getExePath();\n let args: string[] = [];\n\n const optionsKeys = Object.keys({ ...new (class implements Options {}) });\n\n if (Array.isArray(argsOrOptions)) {\n args = argsOrOptions;\n } else {\n const knownArgs = optionsToStringArgs(argsOrOptions);\n\n for (const [key, value] of Object.entries(argsOrOptions)) {\n const hyphenCaseKey = key.replace(/([A-Z])/g, \"-$1\").toLowerCase();\n\n if (!isOptionKey(hyphenCaseKey, optionsKeys)) {\n if (value === true) {\n args.push(key);\n } else if (value !== false && value !== null) {\n args.push(key, String(value));\n }\n }\n }\n\n args = [...knownArgs, ...args];\n }\n\n return execa(fileURLToPath(exePath), args, {\n stdio: \"inherit\",\n ...execaOptions,\n });\n}\n","import { arch as getArch, platform as getPlatform } from \"os\";\n\n/**\n * Returns the executable path for just located inside node_modules\n * The naming convention is just-${os}-${arch}\n * If the platform is `win32` or `cygwin`, executable will include a `.exe` extension\n * @see https://nodejs.org/api/os.html#osarch\n * @see https://nodejs.org/api/os.html#osplatform\n * @example \"x/xx/node_modules/just-darwin-arm64\"\n */\nexport async function getExePath() {\n const platform = getPlatform();\n const arch = getArch();\n\n let os = platform as string;\n let extension = \"\";\n\n if (platform === \"win32\" || platform === \"cygwin\") {\n os = \"windows\";\n extension = \".exe\";\n }\n\n try {\n // Since the bin will be located inside `node_modules`, we can simply call import.meta.resolve\n return import.meta.resolve(\n `rust-just-${os}-${arch}/bin/just${extension}`,\n );\n } catch (e) {\n throw new Error(\n `Couldn't find just binary inside node_modules for ${os}-${arch} (${e})`,\n );\n }\n}\n","import type { Options } from \"./options.js\";\n\n/**\n * Transforms a JavaScript object of options into an array\n * of strings that can be passed to {@link execa} for calling `just`\n *\n * @param options The options to transform\n * @returns The options as an array of strings\n */\nexport function optionsToStringArgs(options: Options): string[] {\n const args: string[] = [];\n\n for (const [key, value] of Object.entries(options)) {\n const hyphenCaseKey = key.replace(/([A-Z])/g, \"-$1\").toLowerCase();\n\n if (\n (key === 'list' || key === 'shellCommand' || key === 'command') &&\n typeof value === 'string' &&\n value.trim().length > 0\n ) {\n const values = value.match(/'([^']+)'/g)?.map(v => v.replace(/'/g, '')) || [];\n if (values.length > 0) {\n args.push(`--${hyphenCaseKey}`, ...values);\n }\n } else if (key === 'set' && typeof value === 'string') {\n const values = value.match(/'([^']+)'/g)?.map(v => v.replace(/'/g, '')) || [];\n if (values.length === 2) {\n args.push(`--${hyphenCaseKey}`, values[0], values[1]);\n }\n } else if (key === 'verbose' && typeof value === 'number') {\n for (let i = 0; i < value; i++) {\n args.push(`--${hyphenCaseKey}`);\n }\n } else if (value === true) {\n args.push(`--${hyphenCaseKey}`);\n } else if (value === false || value === null) {\n continue;\n } else {\n args.push(`--${hyphenCaseKey}`, String(value));\n }\n }\n\n return args;\n}\n"]}
@@ -0,0 +1,103 @@
1
+ import { Options as Options$1, ExecaReturnValue } from 'execa';
2
+
3
+ type Options = Partial<{
4
+ help: boolean;
5
+ version: boolean;
6
+ verbose: number;
7
+ init: boolean | string;
8
+ check: boolean;
9
+ chooser: string;
10
+ clearShellArgs: boolean;
11
+ color: string;
12
+ commandColor: string;
13
+ dotenvFilename: string;
14
+ dotenvPath: string;
15
+ dryRun: boolean;
16
+ dumpFormat: string;
17
+ globalJustfile: boolean;
18
+ highlight: boolean;
19
+ justfile: string;
20
+ listHeading: string;
21
+ listPrefix: string;
22
+ listSubmodules: boolean;
23
+ noAliases: boolean;
24
+ noDeps: boolean;
25
+ noDotenv: boolean;
26
+ noHighlight: boolean;
27
+ quiet: boolean;
28
+ set: string;
29
+ shell: string;
30
+ shellArg: string;
31
+ shellCommand: string;
32
+ timestamp: boolean;
33
+ timestampFormat: string;
34
+ unsorted: boolean;
35
+ unstable: boolean;
36
+ workingDirectory: string;
37
+ yes: boolean;
38
+ changelog: boolean;
39
+ choose: boolean;
40
+ command: string;
41
+ completions: string;
42
+ dump: boolean;
43
+ edit: boolean;
44
+ evaluate: boolean;
45
+ fmt: boolean;
46
+ groups: boolean;
47
+ list: string;
48
+ man: boolean;
49
+ show: string;
50
+ summary: boolean;
51
+ variables: boolean;
52
+ }>;
53
+
54
+ /**
55
+ * Runs `just` with the provided options as a JavaScript object.
56
+ *
57
+ * @param options - The options to pass to `just`.
58
+ * These get transformed into an array strings.
59
+ * - Values that are `true` will be passed as flags (`--flag`).
60
+ * - Values that are `false` or `null` will be ignored.
61
+ * - All other values will be passed as options (`--option value`).
62
+ *
63
+ * @param execaOptions - Options to pass to {@link execa}.
64
+ */
65
+ declare function runJust(options: Options, execaOptions?: Options$1): Promise<ExecaReturnValue<string>>;
66
+ /**
67
+ * Runs the `just` with the provided arguments.
68
+ *
69
+ * @param args - The arguments to pass to `just`.
70
+ * These should be in an array of string format.
71
+ * Every option and their value should be its own entry in the array.
72
+ *
73
+ * @param execaOptions - Options to pass to {@link execa}.
74
+ *
75
+ * @returns A promise that resolves when the `just` has finished running.
76
+ *
77
+ * @example
78
+ * Options with values
79
+ * ```typescript
80
+ * await runJust(["--evaluate", "foo"]);
81
+ * ```
82
+ *
83
+ * @example
84
+ * Options with array type values
85
+ * ```typescript
86
+ * await runJust(["--set", "'<VARIABLE>' '<VALUE>'"]);
87
+ * ```
88
+ *
89
+ * @example
90
+ * Boolean flags
91
+ * ```typescript
92
+ * await runJust(["--version"]);
93
+ * ```
94
+ *
95
+ * @example
96
+ * Justfile functions
97
+ * ```typescript
98
+ * await runJust(["foo"]);
99
+ * ```
100
+ */
101
+ declare function runJust(args: string[], execaOptions?: Options$1): Promise<ExecaReturnValue<string>>;
102
+
103
+ export { type Options, runJust };
package/lib/cli/cli.js ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+ import { execa } from 'execa';
3
+ import { fileURLToPath } from 'url';
4
+ import { platform, arch } from 'os';
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ async function getExePath() {
9
+ const platform$1 = platform();
10
+ const arch$1 = arch();
11
+ let os = platform$1;
12
+ let extension = "";
13
+ if (platform$1 === "win32" || platform$1 === "cygwin") {
14
+ os = "windows";
15
+ extension = ".exe";
16
+ }
17
+ try {
18
+ return import.meta.resolve(
19
+ `rust-just-${os}-${arch$1}/bin/just${extension}`
20
+ );
21
+ } catch (e) {
22
+ throw new Error(
23
+ `Couldn't find just binary inside node_modules for ${os}-${arch$1} (${e})`
24
+ );
25
+ }
26
+ }
27
+ __name(getExePath, "getExePath");
28
+
29
+ // src/optionsToStringArgs.ts
30
+ function optionsToStringArgs(options) {
31
+ const args = [];
32
+ for (const [key, value] of Object.entries(options)) {
33
+ const hyphenCaseKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
34
+ if ((key === "list" || key === "shellCommand" || key === "command") && typeof value === "string" && value.trim().length > 0) {
35
+ const values = value.match(/'([^']+)'/g)?.map((v) => v.replace(/'/g, "")) || [];
36
+ if (values.length > 0) {
37
+ args.push(`--${hyphenCaseKey}`, ...values);
38
+ }
39
+ } else if (key === "set" && typeof value === "string") {
40
+ const values = value.match(/'([^']+)'/g)?.map((v) => v.replace(/'/g, "")) || [];
41
+ if (values.length === 2) {
42
+ args.push(`--${hyphenCaseKey}`, values[0], values[1]);
43
+ }
44
+ } else if (key === "verbose" && typeof value === "number") {
45
+ for (let i = 0; i < value; i++) {
46
+ args.push(`--${hyphenCaseKey}`);
47
+ }
48
+ } else if (value === true) {
49
+ args.push(`--${hyphenCaseKey}`);
50
+ } else if (value === false || value === null) {
51
+ continue;
52
+ } else {
53
+ args.push(`--${hyphenCaseKey}`, String(value));
54
+ }
55
+ }
56
+ return args;
57
+ }
58
+ __name(optionsToStringArgs, "optionsToStringArgs");
59
+
60
+ // src/index.ts
61
+ function isOptionKey(arg, optionsKeys) {
62
+ return optionsKeys.includes(arg);
63
+ }
64
+ __name(isOptionKey, "isOptionKey");
65
+ async function runJust(argsOrOptions, execaOptions) {
66
+ const exePath = await getExePath();
67
+ let args = [];
68
+ const optionsKeys = Object.keys({ ...new class {
69
+ }() });
70
+ if (Array.isArray(argsOrOptions)) {
71
+ args = argsOrOptions;
72
+ } else {
73
+ const knownArgs = optionsToStringArgs(argsOrOptions);
74
+ for (const [key, value] of Object.entries(argsOrOptions)) {
75
+ const hyphenCaseKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
76
+ if (!isOptionKey(hyphenCaseKey, optionsKeys)) {
77
+ if (value === true) {
78
+ args.push(key);
79
+ } else if (value !== false && value !== null) {
80
+ args.push(key, String(value));
81
+ }
82
+ }
83
+ }
84
+ args = [...knownArgs, ...args];
85
+ }
86
+ return execa(fileURLToPath(exePath), args, {
87
+ stdio: "inherit",
88
+ ...execaOptions
89
+ });
90
+ }
91
+ __name(runJust, "runJust");
92
+
93
+ // src/cli.ts
94
+ async function run() {
95
+ const args = process.argv.slice(2);
96
+ const processResult = await runJust(args);
97
+ process.exit(processResult.exitCode ?? 0);
98
+ }
99
+ __name(run, "run");
100
+ void run();
@@ -0,0 +1,103 @@
1
+ import { Options as Options$1, ExecaReturnValue } from 'execa';
2
+
3
+ type Options = Partial<{
4
+ help: boolean;
5
+ version: boolean;
6
+ verbose: number;
7
+ init: boolean | string;
8
+ check: boolean;
9
+ chooser: string;
10
+ clearShellArgs: boolean;
11
+ color: string;
12
+ commandColor: string;
13
+ dotenvFilename: string;
14
+ dotenvPath: string;
15
+ dryRun: boolean;
16
+ dumpFormat: string;
17
+ globalJustfile: boolean;
18
+ highlight: boolean;
19
+ justfile: string;
20
+ listHeading: string;
21
+ listPrefix: string;
22
+ listSubmodules: boolean;
23
+ noAliases: boolean;
24
+ noDeps: boolean;
25
+ noDotenv: boolean;
26
+ noHighlight: boolean;
27
+ quiet: boolean;
28
+ set: string;
29
+ shell: string;
30
+ shellArg: string;
31
+ shellCommand: string;
32
+ timestamp: boolean;
33
+ timestampFormat: string;
34
+ unsorted: boolean;
35
+ unstable: boolean;
36
+ workingDirectory: string;
37
+ yes: boolean;
38
+ changelog: boolean;
39
+ choose: boolean;
40
+ command: string;
41
+ completions: string;
42
+ dump: boolean;
43
+ edit: boolean;
44
+ evaluate: boolean;
45
+ fmt: boolean;
46
+ groups: boolean;
47
+ list: string;
48
+ man: boolean;
49
+ show: string;
50
+ summary: boolean;
51
+ variables: boolean;
52
+ }>;
53
+
54
+ /**
55
+ * Runs `just` with the provided options as a JavaScript object.
56
+ *
57
+ * @param options - The options to pass to `just`.
58
+ * These get transformed into an array strings.
59
+ * - Values that are `true` will be passed as flags (`--flag`).
60
+ * - Values that are `false` or `null` will be ignored.
61
+ * - All other values will be passed as options (`--option value`).
62
+ *
63
+ * @param execaOptions - Options to pass to {@link execa}.
64
+ */
65
+ declare function runJust(options: Options, execaOptions?: Options$1): Promise<ExecaReturnValue<string>>;
66
+ /**
67
+ * Runs the `just` with the provided arguments.
68
+ *
69
+ * @param args - The arguments to pass to `just`.
70
+ * These should be in an array of string format.
71
+ * Every option and their value should be its own entry in the array.
72
+ *
73
+ * @param execaOptions - Options to pass to {@link execa}.
74
+ *
75
+ * @returns A promise that resolves when the `just` has finished running.
76
+ *
77
+ * @example
78
+ * Options with values
79
+ * ```typescript
80
+ * await runJust(["--evaluate", "foo"]);
81
+ * ```
82
+ *
83
+ * @example
84
+ * Options with array type values
85
+ * ```typescript
86
+ * await runJust(["--set", "'<VARIABLE>' '<VALUE>'"]);
87
+ * ```
88
+ *
89
+ * @example
90
+ * Boolean flags
91
+ * ```typescript
92
+ * await runJust(["--version"]);
93
+ * ```
94
+ *
95
+ * @example
96
+ * Justfile functions
97
+ * ```typescript
98
+ * await runJust(["foo"]);
99
+ * ```
100
+ */
101
+ declare function runJust(args: string[], execaOptions?: Options$1): Promise<ExecaReturnValue<string>>;
102
+
103
+ export { type Options, runJust };
@@ -0,0 +1,94 @@
1
+ import { execa } from 'execa';
2
+ import { fileURLToPath } from 'url';
3
+ import { platform, arch } from 'os';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ async function getExePath() {
8
+ const platform$1 = platform();
9
+ const arch$1 = arch();
10
+ let os = platform$1;
11
+ let extension = "";
12
+ if (platform$1 === "win32" || platform$1 === "cygwin") {
13
+ os = "windows";
14
+ extension = ".exe";
15
+ }
16
+ try {
17
+ return import.meta.resolve(
18
+ `rust-just-${os}-${arch$1}/bin/just${extension}`
19
+ );
20
+ } catch (e) {
21
+ throw new Error(
22
+ `Couldn't find just binary inside node_modules for ${os}-${arch$1} (${e})`
23
+ );
24
+ }
25
+ }
26
+ __name(getExePath, "getExePath");
27
+
28
+ // src/optionsToStringArgs.ts
29
+ function optionsToStringArgs(options) {
30
+ const args = [];
31
+ for (const [key, value] of Object.entries(options)) {
32
+ const hyphenCaseKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
33
+ if ((key === "list" || key === "shellCommand" || key === "command") && typeof value === "string" && value.trim().length > 0) {
34
+ const values = value.match(/'([^']+)'/g)?.map((v) => v.replace(/'/g, "")) || [];
35
+ if (values.length > 0) {
36
+ args.push(`--${hyphenCaseKey}`, ...values);
37
+ }
38
+ } else if (key === "set" && typeof value === "string") {
39
+ const values = value.match(/'([^']+)'/g)?.map((v) => v.replace(/'/g, "")) || [];
40
+ if (values.length === 2) {
41
+ args.push(`--${hyphenCaseKey}`, values[0], values[1]);
42
+ }
43
+ } else if (key === "verbose" && typeof value === "number") {
44
+ for (let i = 0; i < value; i++) {
45
+ args.push(`--${hyphenCaseKey}`);
46
+ }
47
+ } else if (value === true) {
48
+ args.push(`--${hyphenCaseKey}`);
49
+ } else if (value === false || value === null) {
50
+ continue;
51
+ } else {
52
+ args.push(`--${hyphenCaseKey}`, String(value));
53
+ }
54
+ }
55
+ return args;
56
+ }
57
+ __name(optionsToStringArgs, "optionsToStringArgs");
58
+
59
+ // src/index.ts
60
+ function isOptionKey(arg, optionsKeys) {
61
+ return optionsKeys.includes(arg);
62
+ }
63
+ __name(isOptionKey, "isOptionKey");
64
+ async function runJust(argsOrOptions, execaOptions) {
65
+ const exePath = await getExePath();
66
+ let args = [];
67
+ const optionsKeys = Object.keys({ ...new class {
68
+ }() });
69
+ if (Array.isArray(argsOrOptions)) {
70
+ args = argsOrOptions;
71
+ } else {
72
+ const knownArgs = optionsToStringArgs(argsOrOptions);
73
+ for (const [key, value] of Object.entries(argsOrOptions)) {
74
+ const hyphenCaseKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
75
+ if (!isOptionKey(hyphenCaseKey, optionsKeys)) {
76
+ if (value === true) {
77
+ args.push(key);
78
+ } else if (value !== false && value !== null) {
79
+ args.push(key, String(value));
80
+ }
81
+ }
82
+ }
83
+ args = [...knownArgs, ...args];
84
+ }
85
+ return execa(fileURLToPath(exePath), args, {
86
+ stdio: "inherit",
87
+ ...execaOptions
88
+ });
89
+ }
90
+ __name(runJust, "runJust");
91
+
92
+ export { runJust };
93
+ //# sourceMappingURL=out.js.map
94
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/getExePath.ts","../../src/optionsToStringArgs.ts"],"names":[],"mappings":";;;;AAAA,SAAS,aAAmE;AAC5E,SAAS,qBAAqB;;;ACD9B,SAAS,QAAQ,SAAS,YAAY,mBAAmB;AAUzD,eAAsB,aAAa;AACjC,QAAM,WAAW,YAAY;AAC7B,QAAM,OAAO,QAAQ;AAErB,MAAI,KAAK;AACT,MAAI,YAAY;AAEhB,MAAI,aAAa,WAAW,aAAa,UAAU;AACjD,SAAK;AACL,gBAAY;AAAA,EACd;AAEA,MAAI;AAEF,WAAO,YAAY;AAAA,MACjB,aAAa,EAAE,IAAI,IAAI,YAAY,SAAS;AAAA,IAC9C;AAAA,EACF,SAAS,GAAG;AACV,UAAM,IAAI;AAAA,MACR,qDAAqD,EAAE,IAAI,IAAI,KAAK,CAAC;AAAA,IACvE;AAAA,EACF;AACF;AAtBsB;;;ACDf,SAAS,oBAAoB,SAA4B;AAC9D,QAAM,OAAiB,CAAC;AAExB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AAClD,UAAM,gBAAgB,IAAI,QAAQ,YAAY,KAAK,EAAE,YAAY;AAEjE,SACG,QAAQ,UAAU,QAAQ,kBAAkB,QAAQ,cACrD,OAAO,UAAU,YACjB,MAAM,KAAK,EAAE,SAAS,GACtB;AACA,YAAM,SAAS,MAAM,MAAM,YAAY,GAAG,IAAI,OAAK,EAAE,QAAQ,MAAM,EAAE,CAAC,KAAK,CAAC;AAC5E,UAAI,OAAO,SAAS,GAAG;AACrB,aAAK,KAAK,KAAK,aAAa,IAAI,GAAG,MAAM;AAAA,MAC3C;AAAA,IACF,WAAW,QAAQ,SAAS,OAAO,UAAU,UAAU;AACrD,YAAM,SAAS,MAAM,MAAM,YAAY,GAAG,IAAI,OAAK,EAAE,QAAQ,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G,IAAI;AAAA,EAC/B;AAEA,SAAO,MAAM,cAAc,OAAO,GAAG,MAAM;AAAA,IACzC,OAAO;AAAA,IACP,GAAG;AAAA,EACL,CAAC;AACH;AA9BsB","sourcesContent":["import { execa, type Options as ExecaOptions, type ExecaReturnValue, } from \"execa\";\nimport { fileURLToPath } from \"node:url\";\nimport { getExePath } from \"./getExePath.js\";\nimport type { Options } from \"./options.js\";\nimport { optionsToStringArgs } from \"./optionsToStringArgs.js\";\n\nexport type { Options } from \"./options.js\";\n\n/**\n * Utility function to check if an argument exists in the predefined Options.\n * @param arg - The argument to check\n * @param optionsKeys - The list of keys from the Options type\n * @returns True if the argument exists in Options, false otherwise\n */\nfunction isOptionKey(arg: string, optionsKeys: string[]): boolean {\n return optionsKeys.includes(arg);\n}\n/**\n * Runs `just` with the provided options as a JavaScript object.\n *\n * @param options - The options to pass to `just`.\n * These get transformed into an array strings.\n * - Values that are `true` will be passed as flags (`--flag`).\n * - Values that are `false` or `null` will be ignored.\n * - All other values will be passed as options (`--option value`).\n *\n * @param execaOptions - Options to pass to {@link execa}.\n */\nexport async function runJust(options: Options, execaOptions?: ExecaOptions): Promise<ExecaReturnValue<string>>;\n/**\n * Runs the `just` with the provided arguments.\n *\n * @param args - The arguments to pass to `just`.\n * These should be in an array of string format.\n * Every option and their value should be its own entry in the array.\n *\n * @param execaOptions - Options to pass to {@link execa}.\n *\n * @returns A promise that resolves when the `just` has finished running.\n *\n * @example\n * Options with values\n * ```typescript\n * await runJust([\"--evaluate\", \"foo\"]);\n * ```\n * \n * @example\n * Options with array type values\n * ```typescript\n * await runJust([\"--set\", \"'<VARIABLE>' '<VALUE>'\"]);\n * ```\n *\n * @example\n * Boolean flags\n * ```typescript\n * await runJust([\"--version\"]);\n * ```\n * \n * @example\n * Justfile functions\n * ```typescript\n * await runJust([\"foo\"]);\n * ```\n */\nexport async function runJust(args: string[], execaOptions?: ExecaOptions): Promise<ExecaReturnValue<string>>;\nexport async function runJust(argsOrOptions: Options | string[], execaOptions?: ExecaOptions): Promise<ExecaReturnValue<string>> {\n const exePath = await getExePath();\n let args: string[] = [];\n\n const optionsKeys = Object.keys({ ...new (class implements Options {}) });\n\n if (Array.isArray(argsOrOptions)) {\n args = argsOrOptions;\n } else {\n const knownArgs = optionsToStringArgs(argsOrOptions);\n\n for (const [key, value] of Object.entries(argsOrOptions)) {\n const hyphenCaseKey = key.replace(/([A-Z])/g, \"-$1\").toLowerCase();\n\n if (!isOptionKey(hyphenCaseKey, optionsKeys)) {\n if (value === true) {\n args.push(key);\n } else if (value !== false && value !== null) {\n args.push(key, String(value));\n }\n }\n }\n\n args = [...knownArgs, ...args];\n }\n\n return execa(fileURLToPath(exePath), args, {\n stdio: \"inherit\",\n ...execaOptions,\n });\n}\n","import { arch as getArch, platform as getPlatform } from \"os\";\n\n/**\n * Returns the executable path for just located inside node_modules\n * The naming convention is just-${os}-${arch}\n * If the platform is `win32` or `cygwin`, executable will include a `.exe` extension\n * @see https://nodejs.org/api/os.html#osarch\n * @see https://nodejs.org/api/os.html#osplatform\n * @example \"x/xx/node_modules/just-darwin-arm64\"\n */\nexport async function getExePath() {\n const platform = getPlatform();\n const arch = getArch();\n\n let os = platform as string;\n let extension = \"\";\n\n if (platform === \"win32\" || platform === \"cygwin\") {\n os = \"windows\";\n extension = \".exe\";\n }\n\n try {\n // Since the bin will be located inside `node_modules`, we can simply call import.meta.resolve\n return import.meta.resolve(\n `rust-just-${os}-${arch}/bin/just${extension}`,\n );\n } catch (e) {\n throw new Error(\n `Couldn't find just binary inside node_modules for ${os}-${arch} (${e})`,\n );\n }\n}\n","import type { Options } from \"./options.js\";\n\n/**\n * Transforms a JavaScript object of options into an array\n * of strings that can be passed to {@link execa} for calling `just`\n *\n * @param options The options to transform\n * @returns The options as an array of strings\n */\nexport function optionsToStringArgs(options: Options): string[] {\n const args: string[] = [];\n\n for (const [key, value] of Object.entries(options)) {\n const hyphenCaseKey = key.replace(/([A-Z])/g, \"-$1\").toLowerCase();\n\n if (\n (key === 'list' || key === 'shellCommand' || key === 'command') &&\n typeof value === 'string' &&\n value.trim().length > 0\n ) {\n const values = value.match(/'([^']+)'/g)?.map(v => v.replace(/'/g, '')) || [];\n if (values.length > 0) {\n args.push(`--${hyphenCaseKey}`, ...values);\n }\n } else if (key === 'set' && typeof value === 'string') {\n const values = value.match(/'([^']+)'/g)?.map(v => v.replace(/'/g, '')) || [];\n if (values.length === 2) {\n args.push(`--${hyphenCaseKey}`, values[0], values[1]);\n }\n } else if (key === 'verbose' && typeof value === 'number') {\n for (let i = 0; i < value; i++) {\n args.push(`--${hyphenCaseKey}`);\n }\n } else if (value === true) {\n args.push(`--${hyphenCaseKey}`);\n } else if (value === false || value === null) {\n continue;\n } else {\n args.push(`--${hyphenCaseKey}`, String(value));\n }\n }\n\n return args;\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "rust-just",
3
+ "version": "1.35.0",
4
+ "description": "🤖 Just a command runner",
5
+ "type": "module",
6
+ "main": "lib/cjs/index.d.cts",
7
+ "module": "lib/esm/index.d.ts",
8
+ "types": "lib/cjs/index.d.cts",
9
+ "bin": "lib/cli/cli.js",
10
+ "exports": {
11
+ "./cli": {
12
+ "import": "./lib/cli/cli.js"
13
+ },
14
+ ".": {
15
+ "import": {
16
+ "types": "./lib/esm/index.d.ts",
17
+ "default": "./lib/esm/index.js"
18
+ },
19
+ "require": {
20
+ "types": "./lib/cjs/index.d.cts",
21
+ "default": "./lib/cjs/index.cjs"
22
+ }
23
+ }
24
+ },
25
+ "files": [
26
+ "lib"
27
+ ],
28
+ "scripts": {
29
+ "typecheck": "tsc",
30
+ "lint": "eslint .",
31
+ "lint:fix": "eslint . --fix",
32
+ "build": "tsup",
33
+ "dev": "yarn build && node lib/cli/cli.js"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/gnpaone/rust-just.git"
38
+ },
39
+ "keywords": [
40
+ "just",
41
+ "rust-just",
42
+ "cli",
43
+ "command line",
44
+ "utilities",
45
+ "rust"
46
+ ],
47
+ "author": "Naveen Prashanth <gnpaone@gmail.com>",
48
+ "license": "CC0-1.0",
49
+ "bugs": {
50
+ "url": "https://github.com/casey/just/issues"
51
+ },
52
+ "homepage": "https://github.com/casey/just#readme",
53
+ "dependencies": {
54
+ "execa": "^8.0.1"
55
+ },
56
+ "devDependencies": {
57
+ "@types/node": "^20.11.22",
58
+ "@typescript-eslint/eslint-plugin": "^7.1.0",
59
+ "@typescript-eslint/parser": "^7.1.0",
60
+ "eslint": "^8.57.0",
61
+ "tsup": "^8.0.2",
62
+ "typescript": "^5.3.3"
63
+ },
64
+ "optionalDependencies": {
65
+ "rust-just-darwin-arm64": "1.35.0",
66
+ "rust-just-darwin-x64": "1.35.0",
67
+ "rust-just-linux-arm": "1.35.0",
68
+ "rust-just-linux-arm64": "1.35.0",
69
+ "rust-just-linux-x64": "1.35.0",
70
+ "rust-just-windows-arm64": "1.35.0",
71
+ "rust-just-windows-x64": "1.35.0"
72
+ },
73
+ "eslintConfig": {
74
+ "extends": [
75
+ "eslint:recommended",
76
+ "plugin:@typescript-eslint/recommended"
77
+ ],
78
+ "parser": "@typescript-eslint/parser",
79
+ "plugins": [
80
+ "@typescript-eslint"
81
+ ],
82
+ "ignorePatterns": [
83
+ "lib/*"
84
+ ],
85
+ "root": true
86
+ },
87
+ "packageManager": "yarn@4.5.0",
88
+ "publishConfig": {
89
+ "access": "public"
90
+ },
91
+ "engines": {
92
+ "node": ">=18.19 || >=20.6 || >=21"
93
+ }
94
+ }