@tscircuit/cli 0.0.144 → 0.0.161
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/formatbot.yml +41 -0
- package/.github/workflows/release.yml +6 -1
- package/.github/workflows/test.yml +2 -2
- package/.github/workflows/typecheck.yml +29 -0
- package/DEVELOPMENT.md +4 -1
- package/README.md +2 -6
- package/{dev-server-api/src → api}/db/generic-json-level.ts +4 -7
- package/{dev-server-api/src → api}/db/zod-level-db.ts +9 -9
- package/{dev-server-api/src → api/lib}/middlewares/with-db.ts +2 -2
- package/{dev-server-api/src → api/lib}/middlewares/with-debug-request-logging.ts +1 -1
- package/{dev-server-api/src → api/lib}/middlewares/with-error-response.ts +2 -2
- package/{dev-server-api → api}/routes/api/db/download.ts +3 -3
- package/{dev-server-api → api}/routes/api/dev_package_examples/create.ts +1 -1
- package/{dev-server-api → api}/routes/api/dev_package_examples/get.ts +3 -3
- package/{dev-server-api → api}/routes/api/dev_package_examples/list.ts +3 -3
- package/{dev-server-api → api}/routes/api/dev_package_examples/update.ts +4 -4
- package/{dev-server-api → api}/routes/api/dev_server/reset.ts +1 -1
- package/{dev-server-api → api}/routes/api/export_files/create.ts +2 -6
- package/{dev-server-api → api}/routes/api/export_files/download.ts +1 -3
- package/{dev-server-api → api}/routes/api/export_requests/create.ts +3 -4
- package/{dev-server-api → api}/routes/api/export_requests/get.ts +5 -8
- package/{dev-server-api → api}/routes/api/export_requests/list.ts +2 -3
- package/{dev-server-api → api}/routes/api/export_requests/update.ts +3 -5
- package/{dev-server-api/routes → api/routes/api}/health.ts +1 -1
- package/{dev-server-api → api}/routes/api/package_info/create.ts +1 -1
- package/{dev-server-api → api}/routes/api/package_info/get.ts +3 -2
- package/{dev-server-api/routes/api → api/routes}/health.ts +1 -1
- package/{dev-server-api → api}/routes/index.ts +2 -2
- package/{dev-server-api → api}/server.ts +2 -2
- package/api/static-routes.ts +24 -0
- package/{dev-server-api → api}/tests/fixtures/get-test-server.ts +2 -1
- package/api/tests/fixtures/start-server.ts +41 -0
- package/{dev-server-api → api}/tests/routes/dev_package_examples/create.test.ts +2 -2
- package/{dev-server-api → api}/tests/routes/dev_package_examples/get.test.ts +2 -2
- package/{dev-server-api → api}/tests/routes/dev_package_examples/list.test.ts +2 -2
- package/{dev-server-api → api}/tests/routes/dev_package_examples/update.test.ts +3 -3
- package/{dev-server-api → api}/tests/routes/export_files/create.test.ts +1 -1
- package/{dev-server-api → api}/tests/routes/export_files/download.test.ts +3 -3
- package/{dev-server-api → api}/tests/routes/export_requests/create.test.ts +2 -2
- package/{dev-server-api → api}/tests/routes/export_requests/get.test.ts +2 -2
- package/{dev-server-api → api}/tests/routes/export_requests/list.test.ts +1 -1
- package/{dev-server-api → api}/tests/routes/export_requests/update.test.ts +1 -1
- package/biome.json +49 -0
- package/bun.lockb +0 -0
- package/{lib → cli/lib}/cmd-fns/add.ts +2 -2
- package/{lib → cli/lib}/cmd-fns/auth-login.ts +2 -2
- package/{lib → cli/lib}/cmd-fns/dev/check-if-initialized.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/dev/derive-selector-from-pcb-component-id.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/dev/dev-server-request-handler.ts +5 -5
- package/{lib → cli/lib}/cmd-fns/dev/find-available-port.ts +7 -5
- package/{lib → cli/lib}/cmd-fns/dev/fulfill-export-requests.ts +27 -27
- package/{lib → cli/lib}/cmd-fns/dev/get-dev-server-axios.ts +3 -3
- package/{lib → cli/lib}/cmd-fns/dev/index.ts +4 -4
- package/{lib → cli/lib}/cmd-fns/dev/infer-export-name-from-source.ts +2 -2
- package/{lib → cli/lib}/cmd-fns/dev/soupify-and-upload-example-file.ts +6 -5
- package/{lib → cli/lib}/cmd-fns/dev/start-edit-event-watcher.ts +41 -42
- package/{lib → cli/lib}/cmd-fns/dev/start-export-request-watcher.ts +3 -4
- package/{lib → cli/lib}/cmd-fns/dev/start-fs-watcher.ts +2 -1
- package/{lib → cli/lib}/cmd-fns/dev/upload-examples-from-directory.ts +4 -3
- package/{lib → cli/lib}/cmd-fns/dev-server-fulfill-export-requests.ts +3 -3
- package/{lib → cli/lib}/cmd-fns/dev-server-upload.ts +3 -3
- package/{lib → cli/lib}/cmd-fns/export-gerbers.ts +2 -2
- package/cli/lib/cmd-fns/go.ts +14 -0
- package/{lib → cli/lib}/cmd-fns/index.ts +2 -0
- package/{lib → cli/lib}/cmd-fns/init/create-or-modify-npmrc.ts +2 -2
- package/{lib → cli/lib}/cmd-fns/init/get-generated-npmrc.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/init/index.ts +13 -9
- package/{lib → cli/lib}/cmd-fns/install.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/lint.ts +16 -10
- package/{lib → cli/lib}/cmd-fns/open.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/package-examples-create.ts +2 -2
- package/{lib → cli/lib}/cmd-fns/package-files-create.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/package-files-upload-directory.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/package-releases-create.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/package-releases-list.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/publish/index.ts +34 -34
- package/{lib → cli/lib}/cmd-fns/remove.ts +2 -2
- package/cli/lib/cmd-fns/render.ts +45 -0
- package/{lib → cli/lib}/cmd-fns/soupify.ts +2 -2
- package/{lib → cli/lib}/cmd-fns/uninstall.ts +1 -1
- package/{lib → cli/lib}/cmd-fns/version.ts +7 -8
- package/{lib → cli/lib}/create-config-manager.ts +1 -1
- package/{lib → cli/lib}/export-fns/export-bom-csv.ts +3 -3
- package/{lib → cli/lib}/export-fns/export-gerbers.ts +6 -6
- package/{lib → cli/lib}/export-fns/export-pnp-csv.ts +3 -3
- package/{lib → cli/lib}/get-program.ts +37 -21
- package/{lib → cli/lib}/param-handlers/interact-for-package-release-id.ts +2 -3
- package/{lib → cli/lib}/param-handlers/interact-for-runtime.ts +1 -1
- package/{lib → cli/lib}/param-handlers/param-handler-type.ts +1 -1
- package/{lib → cli/lib}/posthog.ts +6 -7
- package/{lib → cli/lib}/soupify.ts +4 -4
- package/{lib → cli/lib}/util/app-context.ts +1 -1
- package/{lib → cli/lib}/util/create-context-and-run-program.ts +14 -10
- package/{lib → cli/lib}/util/get-all-package-files.ts +2 -2
- package/cli/lib/util/lint-project.ts +137 -0
- package/{tests → cli/tests}/init.test.ts +1 -1
- package/{tests → cli/tests}/open.test.ts +2 -1
- package/{tests → cli/tests}/soupify.test.ts +1 -1
- package/dist/cli.js +311 -310
- package/example-project/package.json +2 -11
- package/example-project/src/manual-edits.ts +34 -34
- package/{dev-server-frontend/src → frontend}/components/command-k.tsx +2 -2
- package/{dev-server-frontend/src → frontend}/components/dialogs/generic-export-dialog.tsx +6 -10
- package/{dev-server-frontend/src → frontend}/components/dialogs/gerber-export-dialog.tsx +5 -5
- package/{dev-server-frontend/src → frontend}/components/select-example-search.tsx +7 -7
- package/{dev-server-frontend/src → frontend}/components/ui/alert-dialog.tsx +7 -7
- package/{dev-server-frontend/src → frontend}/components/ui/alert.tsx +2 -2
- package/{dev-server-frontend/src → frontend}/components/ui/breadcrumb.tsx +2 -2
- package/{dev-server-frontend/src → frontend}/components/ui/button.tsx +3 -3
- package/{dev-server-frontend/src → frontend}/components/ui/card.tsx +2 -2
- package/{dev-server-frontend/src → frontend}/components/ui/command.tsx +7 -7
- package/{dev-server-frontend/src → frontend}/components/ui/context-menu.tsx +9 -9
- package/{dev-server-frontend/src → frontend}/components/ui/dialog.tsx +6 -6
- package/{dev-server-frontend/src → frontend}/components/ui/menubar.tsx +13 -13
- package/{dev-server-frontend/src → frontend}/components/ui/navigation-menu.tsx +7 -7
- package/{dev-server-frontend/src → frontend}/components/ui/popover.tsx +2 -2
- package/{dev-server-frontend/src → frontend}/components/ui/select.tsx +7 -7
- package/{dev-server-frontend/src → frontend}/components/ui/tabs.tsx +4 -4
- package/{dev-server-frontend/src → frontend}/components/ui/toggle-group.tsx +3 -3
- package/{dev-server-frontend/src → frontend}/components/ui/toggle.tsx +2 -2
- package/{dev-server-frontend/src → frontend}/components/ui/tooltip.tsx +2 -2
- package/{dev-server-frontend → frontend}/components.json +1 -1
- package/{dev-server-frontend/src → frontend}/hooks/use-active-dev-package-example-lite.ts +2 -2
- package/{dev-server-frontend → frontend}/index.html +1 -1
- package/{dev-server-frontend/src → frontend}/main.tsx +2 -2
- package/{dev-server-frontend → frontend}/tailwind.config.js +4 -7
- package/frontend/views/App.tsx +22 -0
- package/{dev-server-frontend/src → frontend/views}/Header.tsx +5 -5
- package/{dev-server-frontend/src → frontend/views}/HeaderMenu.tsx +51 -23
- package/{dev-server-frontend/src/ExampleContentView.tsx → frontend/views/MainContentView.tsx} +7 -7
- package/frontend/vite.config.ts +50 -0
- package/package.json +57 -18
- package/renovate.json +2 -4
- package/scripts/build-cli.ts +12 -0
- package/tsconfig.json +17 -108
- package/tsup.config.ts +3 -3
- package/.github/workflows/server-tests.yml +0 -31
- package/build-cli.ts +0 -14
- package/dev-server-api/bun.lockb +0 -0
- package/dev-server-api/edgespec.config.ts +0 -4
- package/dev-server-api/package.json +0 -23
- package/dev-server-api/src/db/create-schema.ts +0 -54
- package/dev-server-api/src/lib/public-mapping/public-map-export-file.ts +0 -17
- package/dev-server-api/src/lib/public-mapping/public-map-export-request.ts +0 -23
- package/dev-server-api/static-routes.ts +0 -24
- package/dev-server-api/tests/fixtures/start-server.ts +0 -20
- package/dev-server-api/tsconfig.json +0 -28
- package/dev-server-frontend/.eslintrc.cjs +0 -20
- package/dev-server-frontend/package-lock.json +0 -8970
- package/dev-server-frontend/package.json +0 -70
- package/dev-server-frontend/postcss.config.js +0 -6
- package/dev-server-frontend/src/App.tsx +0 -22
- package/dev-server-frontend/tsconfig.json +0 -29
- package/dev-server-frontend/tsconfig.node.json +0 -13
- package/dev-server-frontend/vite.config.ts +0 -23
- package/example-project/package-lock.json +0 -609
- package/lib/util/lint-project.ts +0 -112
- /package/{dev-server-api → api}/README.md +0 -0
- /package/{dev-server-api/src → api}/db/get-db.ts +0 -0
- /package/{dev-server-api/src → api}/db/schema.ts +0 -0
- /package/{dev-server-api → api}/index.ts +0 -0
- /package/{dev-server-api/src → api/lib}/with-winter-spec.ts +0 -0
- /package/{dev-server-api/src → api}/lib/zod/export_parameters.ts +0 -0
- /package/{dev-server-api → api}/tests/routes/health.test.ts +0 -0
- /package/{cli.ts → cli/cli.ts} +0 -0
- /package/{lib → cli/lib}/cmd-fns/auth-logout.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/auth-sessions-create.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/auth-sessions-get.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/auth-sessions-list.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-clear.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-print-config.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-reveal-location.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-set-log-requests.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-set-registry.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-set-runtime.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/config-set-session.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/dev/mark-all-examples-loading.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/dev/start-dev-server.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/init/get-generated-readme.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/init/get-generated-tsconfig.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-examples-get.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-examples-list.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-files-download.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-files-get.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-files-list.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-releases-get.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/package-releases-update.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/packages-create.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/packages-get.ts +0 -0
- /package/{lib → cli/lib}/cmd-fns/packages-list.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/index.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/interact-for-local-directory.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/interact-for-local-file.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/interact-for-package-example-id.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/interact-for-package-name-with-version.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/interact-for-package-name.ts +0 -0
- /package/{lib → cli/lib}/param-handlers/interact-for-registry-url.ts +0 -0
- /package/example-project/examples/{basic-bug.tsx → basic-chip.tsx} +0 -0
- /package/{dev-server-frontend → frontend}/README.md +0 -0
- /package/{dev-server-frontend → frontend}/bun.lockb +0 -0
- /package/{dev-server-frontend/src → frontend}/components/global-context-providers.tsx +0 -0
- /package/{dev-server-frontend/src → frontend}/hooks/toast-if-api-not-connected.ts +0 -0
- /package/{dev-server-frontend/src → frontend}/hooks/use-dev-package-examples.tsx +0 -0
- /package/{dev-server-frontend/src → frontend}/hooks/use-global-store.ts +0 -0
- /package/{dev-server-frontend/src → frontend}/index.css +0 -0
- /package/{dev-server-frontend/src → frontend}/lib/utils.ts +0 -0
- /package/{dev-server-frontend/src → frontend}/vite-env.d.ts +0 -0
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { PostHog } from
|
|
1
|
+
import { PostHog } from "posthog-node"
|
|
2
2
|
|
|
3
3
|
const POSTHOG_API_KEY: string | undefined = process.env.POSTHOG_API_KEY
|
|
4
4
|
|
|
5
5
|
let posthogInstance: PostHog | null = null
|
|
6
6
|
|
|
7
7
|
if (POSTHOG_API_KEY) {
|
|
8
|
-
posthogInstance = new PostHog(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
)
|
|
8
|
+
posthogInstance = new PostHog(POSTHOG_API_KEY, {
|
|
9
|
+
host: "https://us.i.posthog.com",
|
|
10
|
+
})
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
const posthogProxy = new Proxy<PostHog>({} as PostHog, {
|
|
@@ -18,7 +17,7 @@ const posthogProxy = new Proxy<PostHog>({} as PostHog, {
|
|
|
18
17
|
}
|
|
19
18
|
// Return a no-op function for any method call if PostHog is not initialized
|
|
20
19
|
return () => {}
|
|
21
|
-
}
|
|
20
|
+
},
|
|
22
21
|
})
|
|
23
22
|
|
|
24
|
-
export default posthogProxy
|
|
23
|
+
export default posthogProxy
|
|
@@ -18,7 +18,7 @@ export const soupify = async (
|
|
|
18
18
|
filePath: string
|
|
19
19
|
exportName?: string
|
|
20
20
|
},
|
|
21
|
-
ctx: Pick<AppContext, "runtime" | "params"
|
|
21
|
+
ctx: Pick<AppContext, "runtime" | "params">,
|
|
22
22
|
) => {
|
|
23
23
|
debug(`reading ${filePath}`)
|
|
24
24
|
const targetFileContent = await readFile(filePath, "utf-8")
|
|
@@ -38,13 +38,13 @@ export const soupify = async (
|
|
|
38
38
|
|
|
39
39
|
if (!exportName) {
|
|
40
40
|
throw new Error(
|
|
41
|
-
`Couldn't derive an export name and didn't find default export in "${filePath}"
|
|
41
|
+
`Couldn't derive an export name and didn't find default export in "${filePath}"`,
|
|
42
42
|
)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const tmpFilePath = Path.join(
|
|
46
46
|
Path.dirname(filePath),
|
|
47
|
-
Path.basename(filePath).replace(/\.[^\.]+$/, "") + ".__tmp_entrypoint.tsx"
|
|
47
|
+
Path.basename(filePath).replace(/\.[^\.]+$/, "") + ".__tmp_entrypoint.tsx",
|
|
48
48
|
)
|
|
49
49
|
|
|
50
50
|
debug(`writing to ${tmpFilePath}`)
|
|
@@ -71,7 +71,7 @@ const elements = await createRoot().render(<Component />, projectBuilder)
|
|
|
71
71
|
|
|
72
72
|
console.log(JSON.stringify(elements))
|
|
73
73
|
|
|
74
|
-
`.trim()
|
|
74
|
+
`.trim(),
|
|
75
75
|
)
|
|
76
76
|
|
|
77
77
|
debug(`using runtime ${ctx.runtime}`)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Configstore from "configstore"
|
|
2
|
-
import { AppContext } from "./app-context"
|
|
2
|
+
import type { AppContext } from "./app-context"
|
|
3
3
|
import minimist from "minimist"
|
|
4
4
|
import _ from "lodash"
|
|
5
5
|
import prompts from "prompts"
|
|
@@ -7,10 +7,10 @@ import { perfectCli } from "perfect-cli"
|
|
|
7
7
|
import { getProgram } from "../get-program"
|
|
8
8
|
import defaultAxios from "axios"
|
|
9
9
|
import kleur from "kleur"
|
|
10
|
-
import { PARAM_HANDLERS_BY_PARAM_NAME } from "lib/param-handlers"
|
|
11
|
-
import { createConfigHandler } from "lib/create-config-manager"
|
|
10
|
+
import { PARAM_HANDLERS_BY_PARAM_NAME } from "cli/lib/param-handlers"
|
|
11
|
+
import { createConfigHandler } from "cli/lib/create-config-manager"
|
|
12
12
|
import dargs from "dargs"
|
|
13
|
-
import { versionCmd } from "lib/cmd-fns/version"
|
|
13
|
+
import { versionCmd } from "cli/lib/cmd-fns/version"
|
|
14
14
|
|
|
15
15
|
export type CliArgs = {
|
|
16
16
|
cmd: string[]
|
|
@@ -62,8 +62,8 @@ export const createContextAndRunProgram = async (process_args: any) => {
|
|
|
62
62
|
kleur.grey(
|
|
63
63
|
`[RES] ${res.status} ${res.config.method?.toUpperCase()} ${
|
|
64
64
|
res.config.url
|
|
65
|
-
}
|
|
66
|
-
)
|
|
65
|
+
}`,
|
|
66
|
+
),
|
|
67
67
|
)
|
|
68
68
|
return res
|
|
69
69
|
})
|
|
@@ -82,7 +82,11 @@ export const createContextAndRunProgram = async (process_args: any) => {
|
|
|
82
82
|
// end ignores ---
|
|
83
83
|
|
|
84
84
|
if (err.response?.status === 401) {
|
|
85
|
-
console.log(
|
|
85
|
+
console.log(
|
|
86
|
+
kleur.red(
|
|
87
|
+
"Authentication failed. Please run 'tsci login' to authenticate yourself.",
|
|
88
|
+
),
|
|
89
|
+
)
|
|
86
90
|
process.exit(1)
|
|
87
91
|
}
|
|
88
92
|
|
|
@@ -92,12 +96,12 @@ export const createContextAndRunProgram = async (process_args: any) => {
|
|
|
92
96
|
err.config.url
|
|
93
97
|
}\n\n${JSON.stringify(err.response?.data, null, " ")}`
|
|
94
98
|
.replace(/\\n/g, "\n")
|
|
95
|
-
.replace(/\\"/g, '"')
|
|
96
|
-
)
|
|
99
|
+
.replace(/\\"/g, '"'),
|
|
100
|
+
),
|
|
97
101
|
)
|
|
98
102
|
console.log(kleur.yellow("[Request Body]:"), err.config.data)
|
|
99
103
|
return Promise.reject(err)
|
|
100
|
-
}
|
|
104
|
+
},
|
|
101
105
|
)
|
|
102
106
|
|
|
103
107
|
const ctx: AppContext = {
|
|
@@ -13,7 +13,7 @@ import ignore from "ignore"
|
|
|
13
13
|
* Returns an array of files paths.
|
|
14
14
|
*/
|
|
15
15
|
export const getAllPackageFiles = async (
|
|
16
|
-
ctx: AppContext
|
|
16
|
+
ctx: AppContext,
|
|
17
17
|
): Promise<Array<string>> => {
|
|
18
18
|
await ensureNodeModulesIgnored()
|
|
19
19
|
|
|
@@ -56,7 +56,7 @@ const ensureNodeModulesIgnored = async () => {
|
|
|
56
56
|
if (!gitignore.includes("node_modules/")) {
|
|
57
57
|
await fs.appendFile(gitignorePath, "\nnode_modules/\n")
|
|
58
58
|
}
|
|
59
|
-
} catch (err) {
|
|
59
|
+
} catch (err: any) {
|
|
60
60
|
if (err.code === "ENOENT") {
|
|
61
61
|
await fs.writeFile(gitignorePath, "node_modules/\n")
|
|
62
62
|
} else {
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import * as ts from "typescript"
|
|
2
|
+
import * as fs from "fs"
|
|
3
|
+
import * as path from "path"
|
|
4
|
+
|
|
5
|
+
interface LintResult {
|
|
6
|
+
filePath: string
|
|
7
|
+
messages: LintMessage[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface LintMessage {
|
|
11
|
+
line: number
|
|
12
|
+
column: number
|
|
13
|
+
message: string
|
|
14
|
+
fix?: {
|
|
15
|
+
range: [number, number]
|
|
16
|
+
text: string
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function lintProject(
|
|
21
|
+
projectPath: string,
|
|
22
|
+
fix: boolean = false,
|
|
23
|
+
): LintResult[] {
|
|
24
|
+
const results: LintResult[] = []
|
|
25
|
+
const files = getTypeScriptFiles(projectPath)
|
|
26
|
+
|
|
27
|
+
for (const file of files) {
|
|
28
|
+
const sourceFile = ts.createSourceFile(
|
|
29
|
+
file,
|
|
30
|
+
fs.readFileSync(file, "utf8"),
|
|
31
|
+
ts.ScriptTarget.Latest,
|
|
32
|
+
true,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const result = lintFile(sourceFile, fix)
|
|
36
|
+
if (result.messages.length > 0) {
|
|
37
|
+
results.push({ filePath: file, messages: result.messages })
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (fix && result.messages.some((m) => m.fix)) {
|
|
41
|
+
const newContent = applyFixes(sourceFile.text, result.messages)
|
|
42
|
+
fs.writeFileSync(file, newContent)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return results
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function lintFile(
|
|
50
|
+
sourceFile: ts.SourceFile,
|
|
51
|
+
fix: boolean,
|
|
52
|
+
): { messages: LintMessage[] } {
|
|
53
|
+
const messages: LintMessage[] = []
|
|
54
|
+
|
|
55
|
+
function visit(node: ts.Node) {
|
|
56
|
+
if (
|
|
57
|
+
ts.isCallExpression(node) &&
|
|
58
|
+
ts.isIdentifier(node.expression) &&
|
|
59
|
+
node.expression.text === "capacitor"
|
|
60
|
+
) {
|
|
61
|
+
const valueArg = node.arguments.find((arg) =>
|
|
62
|
+
ts.isObjectLiteralExpression(arg),
|
|
63
|
+
)
|
|
64
|
+
if (valueArg && ts.isObjectLiteralExpression(valueArg)) {
|
|
65
|
+
const valueProp = valueArg.properties.find(
|
|
66
|
+
(prop) =>
|
|
67
|
+
ts.isPropertyAssignment(prop) &&
|
|
68
|
+
ts.isIdentifier(prop.name) &&
|
|
69
|
+
prop.name.text === "value",
|
|
70
|
+
)
|
|
71
|
+
if (
|
|
72
|
+
valueProp &&
|
|
73
|
+
ts.isPropertyAssignment(valueProp) &&
|
|
74
|
+
ts.isStringLiteral(valueProp.initializer)
|
|
75
|
+
) {
|
|
76
|
+
const value = valueProp.initializer.text
|
|
77
|
+
if (!value.match(/[µuμ]F$/)) {
|
|
78
|
+
const { line, character } =
|
|
79
|
+
sourceFile.getLineAndCharacterOfPosition(valueProp.getStart())
|
|
80
|
+
messages.push({
|
|
81
|
+
line: line + 1,
|
|
82
|
+
column: character + 1,
|
|
83
|
+
message: 'Capacitor value should include units (e.g., "100F")',
|
|
84
|
+
fix: fix
|
|
85
|
+
? {
|
|
86
|
+
range: [
|
|
87
|
+
valueProp.initializer.getStart(),
|
|
88
|
+
valueProp.initializer.getEnd(),
|
|
89
|
+
],
|
|
90
|
+
text: `"${value}F"`,
|
|
91
|
+
}
|
|
92
|
+
: undefined,
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
ts.forEachChild(node, visit)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
visit(sourceFile)
|
|
103
|
+
|
|
104
|
+
return { messages }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function getTypeScriptFiles(dir: string): string[] {
|
|
108
|
+
const files: string[] = []
|
|
109
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
110
|
+
|
|
111
|
+
for (const entry of entries) {
|
|
112
|
+
const fullPath = path.join(dir, entry.name)
|
|
113
|
+
if (entry.isDirectory()) {
|
|
114
|
+
if (entry.name !== "node_modules" && entry.name !== "dist") {
|
|
115
|
+
files.push(...getTypeScriptFiles(fullPath))
|
|
116
|
+
}
|
|
117
|
+
} else if (entry.isFile() && /\.tsx?$/.test(entry.name)) {
|
|
118
|
+
files.push(fullPath)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return files
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function applyFixes(source: string, messages: LintMessage[]): string {
|
|
126
|
+
const fixes = messages
|
|
127
|
+
.filter((m) => m.fix)
|
|
128
|
+
.sort((a, b) => b.fix!.range[0] - a.fix!.range[0])
|
|
129
|
+
|
|
130
|
+
let result = source
|
|
131
|
+
for (const message of fixes) {
|
|
132
|
+
const [start, end] = message.fix!.range
|
|
133
|
+
result = result.slice(0, start) + message.fix!.text + result.slice(end)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return result
|
|
137
|
+
}
|
|
@@ -4,6 +4,6 @@ import { $ } from "bun"
|
|
|
4
4
|
test.skip("tsci init", async () => {
|
|
5
5
|
await $`rm -rf ./tests/example-init`
|
|
6
6
|
console.log(
|
|
7
|
-
await $`bun cli.ts init --name init-test --dir ./tests/example-init`.text()
|
|
7
|
+
await $`bun cli.ts init --name init-test --dir ./tests/example-init`.text(),
|
|
8
8
|
)
|
|
9
9
|
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { test, expect } from "bun:test"
|
|
2
2
|
import { $ } from "bun"
|
|
3
3
|
|
|
4
|
-
test
|
|
4
|
+
// This test annoyingly opens a browser window, unskip if you're testing it
|
|
5
|
+
test.skip("tsci open", async () => {
|
|
5
6
|
const result = await $`bun cli.ts open -y --cwd ./example-project`.text()
|
|
6
7
|
expect(result).toContain("http")
|
|
7
8
|
expect(result).toContain("example-project")
|
|
@@ -3,7 +3,7 @@ import { $ } from "bun"
|
|
|
3
3
|
|
|
4
4
|
test("soupify", async () => {
|
|
5
5
|
const result =
|
|
6
|
-
await $`bun cli.ts soupify -y --file ./example-project/examples/basic-
|
|
6
|
+
await $`bun cli/cli.ts soupify -y --file ./example-project/examples/basic-chip.tsx`.text()
|
|
7
7
|
|
|
8
8
|
expect(result).toContain("10kohm")
|
|
9
9
|
})
|