@tadpolehq/cli 0.1.2

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @tadpolehq/cli
2
+
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 79d0b4d: Initial release
8
+ - Updated dependencies [79d0b4d]
9
+ - @tadpolehq/core@0.1.2
package/LICENSE ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 TADPOLE HQ LLC
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/dist/main.mjs ADDED
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env node
2
+ import { program } from "commander";
3
+ import fs, { mkdir, writeFile } from "node:fs/promises";
4
+ import os from "node:os";
5
+ import path$1 from "node:path";
6
+ import { execute } from "@tadpolehq/core";
7
+ import { spawn } from "node:child_process";
8
+ import { createLogger, format, transports } from "winston";
9
+
10
+ //#region ../../packages/utils/index.ts
11
+ async function fileExistsAsync(path) {
12
+ try {
13
+ await fs.access(path, fs.constants.F_OK);
14
+ return true;
15
+ } catch {
16
+ return false;
17
+ }
18
+ }
19
+ function spawnAsync(command, args, options, resolveOn = "close") {
20
+ return new Promise((resolve, reject) => {
21
+ const child = spawn(command, args, options);
22
+ child.on("error", (err) => {
23
+ reject(/* @__PURE__ */ new Error(`Failed to start process: ${err.message}`));
24
+ });
25
+ if (resolveOn === "close") {
26
+ let errorData = "";
27
+ child.stderr.on("data", (data) => {
28
+ errorData += data.toString();
29
+ });
30
+ child.on("close", (code) => {
31
+ if (code === 0) resolve(child);
32
+ else reject(/* @__PURE__ */ new Error(`Command failed with code ${code}. Error: ${errorData}`));
33
+ });
34
+ } else if (resolveOn === "spawn") child.on("spawn", () => {
35
+ resolve(child);
36
+ });
37
+ else resolveOn(child).then(() => resolve(child)).catch((err) => {
38
+ reject(err);
39
+ });
40
+ });
41
+ }
42
+
43
+ //#endregion
44
+ //#region src/main.ts
45
+ async function findChrome() {
46
+ let paths = [];
47
+ switch (os.platform()) {
48
+ case "win32": {
49
+ const suffixes = [
50
+ "\\Google\\Chrome\\Application\\chrome.exe",
51
+ "\\Chromium\\Application\\chrome.exe",
52
+ "\\Microsoft\\Edge\\Application\\msedge.exe"
53
+ ];
54
+ const prefixes = [
55
+ process.env.PROGRAMFILES,
56
+ process.env["PROGRAMFILES(X86)"],
57
+ process.env.LOCALAPPDATA
58
+ ];
59
+ for (const prefix of prefixes) if (prefix) for (const suffix of suffixes) paths.push(path$1.join(prefix, suffix));
60
+ break;
61
+ }
62
+ case "darwin":
63
+ paths = ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "/Applications/Chromium.app/Contents/MacOS/Chromium"];
64
+ break;
65
+ case "linux":
66
+ paths = [
67
+ "/usr/bin/google-chrome",
68
+ "/usr/bin/chromium",
69
+ "/usr/bin/chromium-browser"
70
+ ];
71
+ break;
72
+ }
73
+ for (const path of paths) if (await fileExistsAsync(path)) return path;
74
+ return null;
75
+ }
76
+ async function launchChrome(port, headless, userDataDir, fallBackChromePath, windowHeight, windowWidth) {
77
+ const chromePath = await findChrome() ?? fallBackChromePath;
78
+ if (chromePath === null) throw new Error("Chrome not found. Install Chrome or run manually if path is not standard.");
79
+ if (!fileExistsAsync(userDataDir)) await mkdir(userDataDir, { recursive: true });
80
+ const args = [
81
+ `--remote-debugging-port=${port}`,
82
+ `--user-data-dir=${userDataDir}`,
83
+ `--window-size=${windowWidth},${windowHeight}`
84
+ ];
85
+ if (headless) args.push("--headless");
86
+ const child = await spawnAsync(chromePath, args, { detached: true }, (child) => {
87
+ return new Promise((resolve, reject) => {
88
+ const timeout = setTimeout(() => reject(/* @__PURE__ */ new Error("Chrome timeout")), 15e3);
89
+ child.stderr.on("data", (chunk) => {
90
+ if (chunk.toString().includes("DevTools listening on")) {
91
+ clearTimeout(timeout);
92
+ resolve();
93
+ }
94
+ });
95
+ });
96
+ });
97
+ child.unref();
98
+ return child;
99
+ }
100
+ const log = createLogger({
101
+ format: format.combine(format.colorize(), format.simple()),
102
+ transports: [new transports.Console()]
103
+ });
104
+ program.name("tadpole");
105
+ program.command("run <file>").option("--input <value>", "JSON string of input values").option("--output <value>", "Path to write output to").option("--host", "Chrome remote debugging host", "localhost").option("--port <value>", "Chrome remote debugging port", parseInt, 9222).option("--auto", "Whether or not to try to launch Chrome automatically").option("--headless", "If --auto is used, whether or not to start Chrome in headless mode").option("--user-data-dir", "If --auto is used, the custom user-data-dir to use when starting Chrome.", path$1.join(process.cwd(), ".tadpole", "profile")).option("--log-level <value>", "Sets the log level, must be one of 'debug', 'info', 'warn' and 'error'", "warn").option("--chrome-bin <value>", "The full path to the Chrome executable, used as a fallback when used with --auto").option("--window-height <value>", "If --auto is used, the height of the browser window", parseInt, 1080).option("--window-width <value>", "If --auto is used, the width of the browser window", parseInt, 1920).action(async (filePath, options) => {
106
+ log.level = options.logLevel;
107
+ let chrome;
108
+ if (options.auto) chrome = await launchChrome(options.port, options.headless, options.userDataDir, options.chromeBin ?? null, options.windowHeight, options.windowWidth);
109
+ let input = {};
110
+ if (options.input) input = JSON.parse(options.input);
111
+ const result = await execute(filePath);
112
+ if (result.isOk()) {
113
+ const output = await result.value.execute({
114
+ host: options.host,
115
+ port: options.port,
116
+ log,
117
+ expressionValues: input
118
+ });
119
+ const serialized = JSON.stringify(output, (_, value) => {
120
+ if (value instanceof Map) return Object.fromEntries(value);
121
+ return value;
122
+ }, 2);
123
+ if (options.output) await writeFile(options.output, serialized);
124
+ else console.log(serialized);
125
+ } else log.error(`Error parsing definition: ${JSON.stringify(result.error.issue, void 0, 2)}`);
126
+ if (chrome) chrome.kill();
127
+ });
128
+ await program.parseAsync(process.argv);
129
+
130
+ //#endregion
131
+ export { };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@tadpolehq/cli",
3
+ "version": "0.1.2",
4
+ "description": "Command line interface for managing Tadpole projects",
5
+ "homepage": "https://tadpolehq.com",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/tadpolehq/tadpole.git",
9
+ "directory": "apps/cli"
10
+ },
11
+ "type": "module",
12
+ "scripts": {
13
+ "check-types": "tsc --noEmit",
14
+ "dev": "tsdown --watch",
15
+ "build": "tsdown",
16
+ "lint": "eslint ."
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "bin": {
22
+ "tadpole": "./dist/main.mjs"
23
+ },
24
+ "dependencies": {
25
+ "@tadpolehq/core": "0.1.2",
26
+ "commander": "^14.0.2",
27
+ "winston": "^3.19.0"
28
+ },
29
+ "devDependencies": {
30
+ "@tadpolehq/eslint-config": "0.0.0",
31
+ "@tadpolehq/ts-config": "0.0.0",
32
+ "@tadpolehq/utils": "0.0.0",
33
+ "eslint": "^9.39.1",
34
+ "tsdown": "^0.20.1",
35
+ "typescript": "^5.9.3"
36
+ },
37
+ "license": "FSL-1.1-ALv2"
38
+ }