@tscircuit/cli 0.0.394 → 0.1.1
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/.github/workflows/bun-formatcheck.yml +26 -0
- package/.github/workflows/bun-pver-release.yml +25 -0
- package/.github/workflows/{typecheck.yml → bun-typecheck.yml} +0 -3
- package/LICENSE +21 -0
- package/README.md +30 -36
- package/biome.json +9 -9
- package/bun.lockb +0 -0
- package/cli/CliContext.ts +8 -0
- package/cli/auth/login/register.ts +73 -0
- package/cli/auth/logout/register.ts +11 -0
- package/cli/auth/register.ts +5 -0
- package/cli/config/print/register.ts +12 -0
- package/cli/config/register.ts +5 -0
- package/cli/dev/register.ts +111 -0
- package/cli/main.ts +31 -0
- package/dist/main.js +473 -0
- package/docs/file-server-api-usage.md +57 -0
- package/docs/run-frame-usage.md +14 -0
- package/example-dir/manual-edits.json +1 -0
- package/example-dir/snippet.d.ts +13 -0
- package/example-dir/snippet.tsx +20 -0
- package/example-dir/types.d.ts +11 -0
- package/lib/cli-config/TypedConfigStore.ts +50 -0
- package/lib/cli-config/index.ts +16 -0
- package/lib/dependency-analysis/DependencyAnalyzer.ts +129 -0
- package/lib/dependency-analysis/getLocalFileDependencies.ts +101 -0
- package/lib/dependency-analysis/installNodeModuleTypes.ts +74 -0
- package/lib/index.ts +2 -0
- package/lib/project-config/index.ts +5 -0
- package/lib/registry-api/endpoint-types.ts +20 -0
- package/lib/registry-api/get-ky.ts +30 -0
- package/lib/server/EventsWatcher.ts +75 -0
- package/lib/server/createServer.ts +62 -0
- package/lib/site/getIndex.ts +18 -0
- package/package.json +27 -144
- package/tsconfig.json +25 -22
- package/.github/workflows/formatbot.yml +0 -63
- package/.github/workflows/release.yml +0 -40
- package/.github/workflows/test.yml +0 -32
- package/.github/workflows/windows-tests.yml +0 -32
- package/.prettierrc +0 -1
- package/DEVELOPMENT.md +0 -7
- package/api/README.md +0 -3
- package/api/db/generic-json-level.ts +0 -123
- package/api/db/get-db.ts +0 -26
- package/api/db/schema.ts +0 -65
- package/api/db/zod-level-db.ts +0 -148
- package/api/index.ts +0 -4
- package/api/lib/middlewares/with-db.ts +0 -18
- package/api/lib/middlewares/with-debug-request-logging.ts +0 -13
- package/api/lib/middlewares/with-error-response.ts +0 -37
- package/api/lib/with-winter-spec.ts +0 -9
- package/api/lib/zod/export_parameters.ts +0 -25
- package/api/routes/api/db/download.ts +0 -25
- package/api/routes/api/dev_package_examples/create.ts +0 -43
- package/api/routes/api/dev_package_examples/get.ts +0 -46
- package/api/routes/api/dev_package_examples/list.ts +0 -36
- package/api/routes/api/dev_package_examples/update.ts +0 -59
- package/api/routes/api/dev_server/reset.ts +0 -13
- package/api/routes/api/export_files/create.ts +0 -27
- package/api/routes/api/export_files/download.ts +0 -25
- package/api/routes/api/export_requests/create.ts +0 -30
- package/api/routes/api/export_requests/get.ts +0 -43
- package/api/routes/api/export_requests/list.ts +0 -26
- package/api/routes/api/export_requests/update.ts +0 -34
- package/api/routes/api/health.ts +0 -11
- package/api/routes/api/package_info/create.ts +0 -26
- package/api/routes/api/package_info/get.ts +0 -16
- package/api/routes/health.ts +0 -11
- package/api/routes/index.ts +0 -16
- package/api/server.ts +0 -20
- package/api/static-routes.ts +0 -24
- package/api/tests/fixtures/get-test-server.ts +0 -31
- package/api/tests/fixtures/start-server.ts +0 -41
- package/api/tests/routes/dev_package_examples/create.test.ts +0 -19
- package/api/tests/routes/dev_package_examples/get.test.ts +0 -25
- package/api/tests/routes/dev_package_examples/list.test.ts +0 -32
- package/api/tests/routes/dev_package_examples/update.test.ts +0 -38
- package/api/tests/routes/export_files/create.test.ts +0 -18
- package/api/tests/routes/export_files/download.test.ts +0 -29
- package/api/tests/routes/export_requests/create.test.ts +0 -24
- package/api/tests/routes/export_requests/get.test.ts +0 -41
- package/api/tests/routes/export_requests/list.test.ts +0 -35
- package/api/tests/routes/export_requests/update.test.ts +0 -50
- package/api/tests/routes/health.test.ts +0 -10
- package/bunfig.toml +0 -2
- package/cli/cli.ts +0 -13
- package/cli/lib/cmd-fns/add.ts +0 -34
- package/cli/lib/cmd-fns/auth-login.ts +0 -59
- package/cli/lib/cmd-fns/auth-logout.ts +0 -7
- package/cli/lib/cmd-fns/auth-sessions-create.ts +0 -3
- package/cli/lib/cmd-fns/auth-sessions-get.ts +0 -3
- package/cli/lib/cmd-fns/auth-sessions-list.ts +0 -5
- package/cli/lib/cmd-fns/config-clear.ts +0 -5
- package/cli/lib/cmd-fns/config-print-config.ts +0 -6
- package/cli/lib/cmd-fns/config-reveal-location.ts +0 -5
- package/cli/lib/cmd-fns/config-set-log-requests.ts +0 -7
- package/cli/lib/cmd-fns/config-set-registry.ts +0 -9
- package/cli/lib/cmd-fns/config-set-runtime.ts +0 -7
- package/cli/lib/cmd-fns/config-set-session.ts +0 -7
- package/cli/lib/cmd-fns/dev/check-if-initialized.ts +0 -22
- package/cli/lib/cmd-fns/dev/derive-selector-from-pcb-component-id.ts +0 -23
- package/cli/lib/cmd-fns/dev/dev-server-request-handler.ts +0 -61
- package/cli/lib/cmd-fns/dev/find-available-port.ts +0 -32
- package/cli/lib/cmd-fns/dev/fulfill-export-requests.ts +0 -162
- package/cli/lib/cmd-fns/dev/get-dev-server-axios.ts +0 -29
- package/cli/lib/cmd-fns/dev/index.ts +0 -168
- package/cli/lib/cmd-fns/dev/infer-export-name-from-source.ts +0 -17
- package/cli/lib/cmd-fns/dev/mark-all-examples-loading.ts +0 -18
- package/cli/lib/cmd-fns/dev/soupify-and-upload-example-file.ts +0 -62
- package/cli/lib/cmd-fns/dev/start-dev-server.ts +0 -34
- package/cli/lib/cmd-fns/dev/start-edit-event-watcher.ts +0 -347
- package/cli/lib/cmd-fns/dev/start-export-request-watcher.ts +0 -33
- package/cli/lib/cmd-fns/dev/start-fs-watcher.ts +0 -54
- package/cli/lib/cmd-fns/dev/upload-examples-from-directory.ts +0 -42
- package/cli/lib/cmd-fns/dev-server-fulfill-export-requests.ts +0 -43
- package/cli/lib/cmd-fns/dev-server-upload.ts +0 -56
- package/cli/lib/cmd-fns/export-gerbers.ts +0 -28
- package/cli/lib/cmd-fns/export-kicad-pcb.ts +0 -36
- package/cli/lib/cmd-fns/export-pnp-csv.ts +0 -32
- package/cli/lib/cmd-fns/gen-jlcpcb-component.ts +0 -64
- package/cli/lib/cmd-fns/go.ts +0 -14
- package/cli/lib/cmd-fns/index.ts +0 -46
- package/cli/lib/cmd-fns/init/create-or-modify-npmrc.ts +0 -21
- package/cli/lib/cmd-fns/init/get-generated-npmrc.ts +0 -8
- package/cli/lib/cmd-fns/init/get-generated-readme.ts +0 -41
- package/cli/lib/cmd-fns/init/get-generated-tsconfig.ts +0 -34
- package/cli/lib/cmd-fns/init/index.ts +0 -193
- package/cli/lib/cmd-fns/install.ts +0 -34
- package/cli/lib/cmd-fns/lint.ts +0 -43
- package/cli/lib/cmd-fns/open.ts +0 -19
- package/cli/lib/cmd-fns/package-examples-create.ts +0 -36
- package/cli/lib/cmd-fns/package-examples-get.ts +0 -20
- package/cli/lib/cmd-fns/package-examples-list.ts +0 -18
- package/cli/lib/cmd-fns/package-files-create.ts +0 -31
- package/cli/lib/cmd-fns/package-files-download.ts +0 -29
- package/cli/lib/cmd-fns/package-files-get.ts +0 -3
- package/cli/lib/cmd-fns/package-files-list.ts +0 -28
- package/cli/lib/cmd-fns/package-files-upload-directory.ts +0 -6
- package/cli/lib/cmd-fns/package-releases-create.ts +0 -35
- package/cli/lib/cmd-fns/package-releases-get.ts +0 -3
- package/cli/lib/cmd-fns/package-releases-list.ts +0 -32
- package/cli/lib/cmd-fns/package-releases-update.ts +0 -45
- package/cli/lib/cmd-fns/packages-create.ts +0 -16
- package/cli/lib/cmd-fns/packages-get.ts +0 -16
- package/cli/lib/cmd-fns/packages-list.ts +0 -16
- package/cli/lib/cmd-fns/publish/index.ts +0 -336
- package/cli/lib/cmd-fns/remove.ts +0 -31
- package/cli/lib/cmd-fns/render.ts +0 -45
- package/cli/lib/cmd-fns/soupify.ts +0 -31
- package/cli/lib/cmd-fns/uninstall.ts +0 -31
- package/cli/lib/cmd-fns/version.ts +0 -38
- package/cli/lib/create-config-manager.ts +0 -97
- package/cli/lib/export-fns/export-bom-csv.ts +0 -32
- package/cli/lib/export-fns/export-gerbers.ts +0 -108
- package/cli/lib/export-fns/export-kicad-pcb.ts +0 -32
- package/cli/lib/export-fns/export-pnp-csv.ts +0 -31
- package/cli/lib/get-program.ts +0 -387
- package/cli/lib/param-handlers/index.ts +0 -21
- package/cli/lib/param-handlers/interact-for-local-directory.ts +0 -58
- package/cli/lib/param-handlers/interact-for-local-file.ts +0 -59
- package/cli/lib/param-handlers/interact-for-package-example-id.ts +0 -25
- package/cli/lib/param-handlers/interact-for-package-name-with-version.ts +0 -63
- package/cli/lib/param-handlers/interact-for-package-name.ts +0 -45
- package/cli/lib/param-handlers/interact-for-package-release-id.ts +0 -15
- package/cli/lib/param-handlers/interact-for-registry-url.ts +0 -27
- package/cli/lib/param-handlers/interact-for-runtime.ts +0 -33
- package/cli/lib/param-handlers/param-handler-type.ts +0 -7
- package/cli/lib/posthog.ts +0 -23
- package/cli/lib/soupify/get-export-name-from-file.ts +0 -29
- package/cli/lib/soupify/get-tmp-entrpoint-filepath.ts +0 -15
- package/cli/lib/soupify/index.ts +0 -1
- package/cli/lib/soupify/run-entrypoint-file.ts +0 -59
- package/cli/lib/soupify/soupify-with-core.ts +0 -74
- package/cli/lib/soupify/soupify.ts +0 -6
- package/cli/lib/util/app-context.ts +0 -17
- package/cli/lib/util/create-context-and-run-program.ts +0 -168
- package/cli/lib/util/get-all-package-files.ts +0 -66
- package/cli/lib/util/lint-project.ts +0 -137
- package/cli/tests/export-gerber-keyboard.test.ts +0 -16
- package/cli/tests/export-gerber.test.ts +0 -49
- package/cli/tests/export-kicad-pcb.test.ts +0 -23
- package/cli/tests/export-pnp-csv.test.ts +0 -24
- package/cli/tests/fixtures/preload.ts +0 -54
- package/cli/tests/init.test.ts +0 -9
- package/cli/tests/open.test.ts +0 -9
- package/cli/tests/soupify-builder.test.ts +0 -9
- package/cli/tests/soupify-core.test.ts +0 -9
- package/dist/cli.js +0 -3676
- package/docs/EDIT_EVENT_PIPELINE.md +0 -34
- package/example-project/README.md +0 -18
- package/example-project/examples/basic-capacitor.tsx +0 -5
- package/example-project/examples/basic-chip.tsx +0 -26
- package/example-project/examples/basic-resistor.tsx +0 -3
- package/example-project/examples/macrokeypad.tsx +0 -59
- package/example-project/index.ts +0 -1
- package/example-project/package.json +0 -5
- package/example-project/src/ArduinoProMicroBreakout.tsx +0 -37
- package/example-project/src/Key.tsx +0 -46
- package/example-project/src/Keyswitch.tsx +0 -26
- package/example-project/src/KeyswitchSocket.tsx +0 -56
- package/example-project/src/MyCircuit.tsx +0 -38
- package/example-project/src/manual-edits.ts +0 -93
- package/frontend/README.md +0 -3
- package/frontend/bun.lockb +0 -0
- package/frontend/components/command-k.tsx +0 -86
- package/frontend/components/dialogs/generic-export-dialog.tsx +0 -189
- package/frontend/components/dialogs/gerber-export-dialog.tsx +0 -168
- package/frontend/components/global-context-providers.tsx +0 -11
- package/frontend/components/select-example-search.tsx +0 -118
- package/frontend/components/ui/alert-dialog.tsx +0 -139
- package/frontend/components/ui/alert.tsx +0 -59
- package/frontend/components/ui/breadcrumb.tsx +0 -115
- package/frontend/components/ui/button.tsx +0 -57
- package/frontend/components/ui/card.tsx +0 -76
- package/frontend/components/ui/command.tsx +0 -153
- package/frontend/components/ui/context-menu.tsx +0 -202
- package/frontend/components/ui/dialog.tsx +0 -120
- package/frontend/components/ui/menubar.tsx +0 -238
- package/frontend/components/ui/navigation-menu.tsx +0 -128
- package/frontend/components/ui/popover.tsx +0 -31
- package/frontend/components/ui/select.tsx +0 -162
- package/frontend/components/ui/tabs.tsx +0 -53
- package/frontend/components/ui/toggle-group.tsx +0 -59
- package/frontend/components/ui/toggle.tsx +0 -43
- package/frontend/components/ui/tooltip.tsx +0 -28
- package/frontend/components.json +0 -17
- package/frontend/hooks/toast-if-api-not-connected.ts +0 -23
- package/frontend/hooks/use-active-dev-package-example-lite.ts +0 -39
- package/frontend/hooks/use-dev-package-examples.tsx +0 -18
- package/frontend/hooks/use-global-store.ts +0 -42
- package/frontend/index.css +0 -76
- package/frontend/index.html +0 -13
- package/frontend/lib/utils.ts +0 -6
- package/frontend/main.tsx +0 -13
- package/frontend/tailwind.config.js +0 -74
- package/frontend/views/App.tsx +0 -22
- package/frontend/views/Header.tsx +0 -55
- package/frontend/views/HeaderMenu.tsx +0 -326
- package/frontend/views/MainContentView.tsx +0 -172
- package/frontend/vite-env.d.ts +0 -1
- package/frontend/vite.config.ts +0 -50
- package/renovate.json +0 -16
- package/scripts/build-cli.ts +0 -12
- package/tsup.config.ts +0 -7
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
|
|
2
|
+
name: Format Check
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: [main]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
format-check:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v3
|
|
16
|
+
|
|
17
|
+
- name: Setup bun
|
|
18
|
+
uses: oven-sh/setup-bun@v1
|
|
19
|
+
with:
|
|
20
|
+
bun-version: latest
|
|
21
|
+
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: bun install
|
|
24
|
+
|
|
25
|
+
- name: Run format check
|
|
26
|
+
run: bun run format:check
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
|
|
2
|
+
name: Publish to npm
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v3
|
|
12
|
+
- name: Setup bun
|
|
13
|
+
uses: oven-sh/setup-bun@v1
|
|
14
|
+
with:
|
|
15
|
+
bun-version: latest
|
|
16
|
+
- uses: actions/setup-node@v3
|
|
17
|
+
with:
|
|
18
|
+
node-version: 20
|
|
19
|
+
registry-url: https://registry.npmjs.org/
|
|
20
|
+
- run: npm install -g pver
|
|
21
|
+
- run: bun install --frozen-lockfile
|
|
22
|
+
- run: bun run build
|
|
23
|
+
- run: pver release
|
|
24
|
+
env:
|
|
25
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 tscircuit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,57 +1,51 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tscircuit/snippets-cli
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
tscircuit registry.
|
|
3
|
+
A CLI for developing, managing and publishing snippets on [tscircuit.com](https://tscircuit.com).
|
|
5
4
|
|
|
6
|
-
##
|
|
5
|
+
## Usage
|
|
7
6
|
|
|
8
7
|
```bash
|
|
9
|
-
|
|
8
|
+
# Start a local server that watches for changes in
|
|
9
|
+
# this file or it's dependencies and updates the
|
|
10
|
+
# browser preview
|
|
11
|
+
snippets dev ./path/to/file.tsx
|
|
10
12
|
```
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
> Note: The snippets CLI uses the same configuration files as the [@tscircuit/cli](https://github.com/tscircuit/cli), so you may need to also install `npm install -g @tscircuit/cli` and run `tsci login` to authenticate!
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
qualified with all required arguments to skip the interactive mode.
|
|
16
|
+
## Installation
|
|
16
17
|
|
|
17
18
|
```bash
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
# Login
|
|
22
|
-
tsci login
|
|
23
|
-
|
|
24
|
-
# Create a Project
|
|
25
|
-
tsci init
|
|
19
|
+
npm install -g @tscircuit/snippets-cli
|
|
20
|
+
```
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
tsci dev
|
|
22
|
+
## Development
|
|
29
23
|
|
|
30
|
-
|
|
31
|
-
tsci install
|
|
32
|
-
tsci add some-package
|
|
33
|
-
tsci remove some-package
|
|
24
|
+
This command will open the `snippets.tsx` file for editing.
|
|
34
25
|
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
```bash
|
|
27
|
+
bun run dev
|
|
37
28
|
```
|
|
38
29
|
|
|
39
|
-
##
|
|
30
|
+
## How it Works
|
|
40
31
|
|
|
41
|
-
|
|
42
|
-
that
|
|
32
|
+
When you run `snippets dev`, we start a local
|
|
33
|
+
server that uses the [@tscircuit/file-server](https://github.com/tscircuit/file-server) and [@tscircuit/runframe](https://github.com/tscircuit/runframe) (on the browser)
|
|
43
34
|
|
|
44
|
-
|
|
35
|
+
We use commanderjs to define the CLI commands inside
|
|
36
|
+
of `cli/main.ts`
|
|
45
37
|
|
|
46
|
-
|
|
38
|
+
Utility functions are defined in `lib/*`
|
|
47
39
|
|
|
48
|
-
|
|
49
|
-
loaded is inside `example-project`
|
|
40
|
+
## Development
|
|
50
41
|
|
|
51
|
-
|
|
42
|
+
### Dynamically Loading Runframe
|
|
52
43
|
|
|
53
|
-
|
|
44
|
+
Use the `RUNFRAME_STANDALONE_FILE_PATH` environment variable to point to the runframe standalone file. You will still need to run `bun run build` inside
|
|
45
|
+
runframe each time you'd like to load a new version of runframe.
|
|
54
46
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
```bash
|
|
48
|
+
export RUNFRAME_STANDALONE_FILE_PATH=../runframe/dist/standalone.min.js
|
|
49
|
+
cd ../runframe && bun run build
|
|
50
|
+
cd ../snippets-cli && bun run dev
|
|
51
|
+
```
|
package/biome.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/1.
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
|
|
3
3
|
"organizeImports": {
|
|
4
4
|
"enabled": true
|
|
5
5
|
},
|
|
@@ -8,13 +8,7 @@
|
|
|
8
8
|
"indentStyle": "space"
|
|
9
9
|
},
|
|
10
10
|
"files": {
|
|
11
|
-
"ignore": [
|
|
12
|
-
"cosmos-export",
|
|
13
|
-
"dist",
|
|
14
|
-
"package.json",
|
|
15
|
-
"tsconfig.json",
|
|
16
|
-
"static-routes.ts"
|
|
17
|
-
]
|
|
11
|
+
"ignore": ["cosmos-export", "dist", "package.json", "tsconfig.json"]
|
|
18
12
|
},
|
|
19
13
|
"javascript": {
|
|
20
14
|
"formatter": {
|
|
@@ -28,13 +22,19 @@
|
|
|
28
22
|
}
|
|
29
23
|
},
|
|
30
24
|
"linter": {
|
|
31
|
-
"enabled":
|
|
25
|
+
"enabled": true,
|
|
32
26
|
"rules": {
|
|
27
|
+
"recommended": true,
|
|
33
28
|
"suspicious": {
|
|
34
29
|
"noExplicitAny": "off"
|
|
35
30
|
},
|
|
31
|
+
"complexity": {
|
|
32
|
+
"noForEach": "off"
|
|
33
|
+
},
|
|
36
34
|
"style": {
|
|
35
|
+
"noUselessElse": "off",
|
|
37
36
|
"noNonNullAssertion": "off",
|
|
37
|
+
"useNumberNamespace": "off",
|
|
38
38
|
"useFilenamingConvention": {
|
|
39
39
|
"level": "error",
|
|
40
40
|
"options": {
|
package/bun.lockb
CHANGED
|
Binary file
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Command } from "commander"
|
|
2
|
+
import { cliConfig } from "lib/cli-config"
|
|
3
|
+
import delay from "delay"
|
|
4
|
+
import { getKy } from "lib/registry-api/get-ky"
|
|
5
|
+
import type { EndpointResponse } from "lib/registry-api/endpoint-types"
|
|
6
|
+
|
|
7
|
+
export const registerAuthLogin = (program: Command) => {
|
|
8
|
+
program.commands
|
|
9
|
+
.find((c) => c.name() === "auth")!
|
|
10
|
+
.command("login")
|
|
11
|
+
.description("Authenticate CLI, login to registry")
|
|
12
|
+
.action(async (args) => {
|
|
13
|
+
const ky = getKy()
|
|
14
|
+
|
|
15
|
+
const { login_page } = await ky
|
|
16
|
+
.post<EndpointResponse["sessions/login_page/create"]>(
|
|
17
|
+
"sessions/login_page/create",
|
|
18
|
+
{
|
|
19
|
+
json: {},
|
|
20
|
+
},
|
|
21
|
+
)
|
|
22
|
+
.json()
|
|
23
|
+
|
|
24
|
+
console.log("Please visit the following URL to log in:")
|
|
25
|
+
console.log(login_page.url)
|
|
26
|
+
|
|
27
|
+
// Wait until we receive confirmation
|
|
28
|
+
while (true) {
|
|
29
|
+
const { login_page: new_login_page } = await ky
|
|
30
|
+
.post<EndpointResponse["sessions/login_page/get"]>(
|
|
31
|
+
"sessions/login_page/get",
|
|
32
|
+
{
|
|
33
|
+
json: {
|
|
34
|
+
login_page_id: login_page.login_page_id,
|
|
35
|
+
},
|
|
36
|
+
headers: {
|
|
37
|
+
Authorization: `Bearer ${login_page.login_page_auth_token}`,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
)
|
|
41
|
+
.json()
|
|
42
|
+
|
|
43
|
+
if (new_login_page.was_login_successful) {
|
|
44
|
+
console.log("Logged in! Generating token...")
|
|
45
|
+
break
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (new_login_page.is_expired) {
|
|
49
|
+
throw new Error("Login page expired")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
await delay(1000)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const { session } = await ky
|
|
56
|
+
.post<EndpointResponse["sessions/login_page/exchange_for_cli_session"]>(
|
|
57
|
+
"sessions/login_page/exchange_for_cli_session",
|
|
58
|
+
{
|
|
59
|
+
json: {
|
|
60
|
+
login_page_id: login_page.login_page_id,
|
|
61
|
+
},
|
|
62
|
+
headers: {
|
|
63
|
+
Authorization: `Bearer ${login_page.login_page_auth_token}`,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
)
|
|
67
|
+
.json()
|
|
68
|
+
|
|
69
|
+
cliConfig.set("sessionToken", session.token)
|
|
70
|
+
|
|
71
|
+
console.log("Ready to use!")
|
|
72
|
+
})
|
|
73
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Command } from "commander"
|
|
2
|
+
|
|
3
|
+
export const registerAuthLogout = (program: Command) => {
|
|
4
|
+
program.commands
|
|
5
|
+
.find((c) => c.name() === "auth")!
|
|
6
|
+
.command("logout")
|
|
7
|
+
.description("Logout from registry")
|
|
8
|
+
.action((args) => {
|
|
9
|
+
console.log("logout")
|
|
10
|
+
})
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Command } from "commander"
|
|
2
|
+
import { cliConfig } from "lib/cli-config"
|
|
3
|
+
|
|
4
|
+
export const registerConfigPrint = (program: Command) => {
|
|
5
|
+
program.commands
|
|
6
|
+
.find((c) => c.name() === "config")!
|
|
7
|
+
.command("print")
|
|
8
|
+
.description("Print the current config")
|
|
9
|
+
.action(() => {
|
|
10
|
+
console.log(JSON.stringify(cliConfig.all, null, 2))
|
|
11
|
+
})
|
|
12
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { Command } from "commander"
|
|
2
|
+
import * as path from "node:path"
|
|
3
|
+
import * as chokidar from "chokidar"
|
|
4
|
+
import * as fs from "node:fs"
|
|
5
|
+
import { createServer } from "lib/server/createServer"
|
|
6
|
+
import { getLocalFileDependencies } from "lib/dependency-analysis/getLocalFileDependencies"
|
|
7
|
+
import { installTypes } from "../../lib/dependency-analysis/installNodeModuleTypes"
|
|
8
|
+
import { EventsWatcher } from "../../lib/server/EventsWatcher"
|
|
9
|
+
|
|
10
|
+
export const registerDev = (program: Command) => {
|
|
11
|
+
program
|
|
12
|
+
.command("dev")
|
|
13
|
+
.description("Start development server for a snippet")
|
|
14
|
+
.argument("<file>", "Path to the snippet file")
|
|
15
|
+
.option("-p, --port <number>", "Port to run server on", "3000")
|
|
16
|
+
.action(async (file: string, options: { port: string }) => {
|
|
17
|
+
const absolutePath = path.resolve(file)
|
|
18
|
+
const fileDir = path.dirname(absolutePath)
|
|
19
|
+
const port = parseInt(options.port)
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
console.log("Installing types for imported snippets...")
|
|
23
|
+
await installTypes(absolutePath)
|
|
24
|
+
console.log("Types installed successfully")
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.warn("Failed to install types:", error)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Start the server
|
|
30
|
+
await createServer(port)
|
|
31
|
+
|
|
32
|
+
const eventsWatcher = new EventsWatcher(`http://localhost:${port}`)
|
|
33
|
+
eventsWatcher.start()
|
|
34
|
+
|
|
35
|
+
await fetch(`http://localhost:${port}/api/files/upsert`, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: { "Content-Type": "application/json" },
|
|
38
|
+
body: JSON.stringify({
|
|
39
|
+
file_path: "entrypoint.tsx",
|
|
40
|
+
text_content: `
|
|
41
|
+
import MyCircuit from "./snippet.tsx"
|
|
42
|
+
|
|
43
|
+
circuit.add(<MyCircuit />)
|
|
44
|
+
`,
|
|
45
|
+
}),
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
// Function to update file content
|
|
49
|
+
const updateFile = async (filePath: string) => {
|
|
50
|
+
try {
|
|
51
|
+
const content = await fs.promises.readFile(filePath, "utf-8")
|
|
52
|
+
const response = await fetch(
|
|
53
|
+
`http://localhost:${port}/api/files/upsert`,
|
|
54
|
+
{
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: { "Content-Type": "application/json" },
|
|
57
|
+
body: JSON.stringify({
|
|
58
|
+
file_path: path.relative(fileDir, filePath),
|
|
59
|
+
text_content: content,
|
|
60
|
+
}),
|
|
61
|
+
},
|
|
62
|
+
)
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
console.error(`Failed to update ${filePath}`)
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(`Error updating ${filePath}:`, error)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Get initial dependencies
|
|
72
|
+
const dependencies = new Set([absolutePath])
|
|
73
|
+
try {
|
|
74
|
+
const deps = getLocalFileDependencies(absolutePath)
|
|
75
|
+
deps.forEach((dep) => dependencies.add(dep))
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.warn("Failed to analyze dependencies:", error)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Watch the main file and its dependencies
|
|
81
|
+
const filesystemWatcher = chokidar.watch(Array.from(dependencies), {
|
|
82
|
+
persistent: true,
|
|
83
|
+
ignoreInitial: false,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
filesystemWatcher.on("change", async (filePath) => {
|
|
87
|
+
console.log(`File ${filePath} changed`)
|
|
88
|
+
await updateFile(filePath)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
filesystemWatcher.on("add", async (filePath) => {
|
|
92
|
+
console.log(`File ${filePath} added`)
|
|
93
|
+
await updateFile(filePath)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
eventsWatcher.on("FILE_UPDATED", async (ev) => {
|
|
97
|
+
if (ev.file_path === "manual-edits.json") {
|
|
98
|
+
console.log("Manual edits updated, updating on filesystem...")
|
|
99
|
+
const { file } = await fetch(
|
|
100
|
+
`http://localhost:${port}/api/files/get?file_path=manual-edits.json`,
|
|
101
|
+
).then((r) => r.json())
|
|
102
|
+
fs.writeFileSync(
|
|
103
|
+
path.join(fileDir, "manual-edits.json"),
|
|
104
|
+
file.text_content,
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
console.log(`Watching ${file} and its dependencies...`)
|
|
110
|
+
})
|
|
111
|
+
}
|
package/cli/main.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander"
|
|
3
|
+
import { registerDev } from "./dev/register"
|
|
4
|
+
import { registerAuthLogin } from "./auth/login/register"
|
|
5
|
+
import { registerAuthLogout } from "./auth/logout/register"
|
|
6
|
+
import { registerAuth } from "./auth/register"
|
|
7
|
+
import { registerConfig } from "./config/register"
|
|
8
|
+
import { registerConfigPrint } from "./config/print/register"
|
|
9
|
+
import { perfectCli } from "perfect-cli"
|
|
10
|
+
|
|
11
|
+
const program = new Command()
|
|
12
|
+
|
|
13
|
+
program
|
|
14
|
+
.name("tsci")
|
|
15
|
+
.description("CLI for developing tscircuit snippets")
|
|
16
|
+
.version("1.0.0")
|
|
17
|
+
|
|
18
|
+
registerDev(program)
|
|
19
|
+
|
|
20
|
+
registerAuth(program)
|
|
21
|
+
registerAuthLogin(program)
|
|
22
|
+
registerAuthLogout(program)
|
|
23
|
+
|
|
24
|
+
registerConfig(program)
|
|
25
|
+
registerConfigPrint(program)
|
|
26
|
+
|
|
27
|
+
if (process.argv.length === 2) {
|
|
28
|
+
perfectCli(program, process.argv)
|
|
29
|
+
} else {
|
|
30
|
+
program.parse()
|
|
31
|
+
}
|