@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.
Files changed (207) hide show
  1. package/.github/workflows/formatbot.yml +41 -0
  2. package/.github/workflows/release.yml +6 -1
  3. package/.github/workflows/test.yml +2 -2
  4. package/.github/workflows/typecheck.yml +29 -0
  5. package/DEVELOPMENT.md +4 -1
  6. package/README.md +2 -6
  7. package/{dev-server-api/src → api}/db/generic-json-level.ts +4 -7
  8. package/{dev-server-api/src → api}/db/zod-level-db.ts +9 -9
  9. package/{dev-server-api/src → api/lib}/middlewares/with-db.ts +2 -2
  10. package/{dev-server-api/src → api/lib}/middlewares/with-debug-request-logging.ts +1 -1
  11. package/{dev-server-api/src → api/lib}/middlewares/with-error-response.ts +2 -2
  12. package/{dev-server-api → api}/routes/api/db/download.ts +3 -3
  13. package/{dev-server-api → api}/routes/api/dev_package_examples/create.ts +1 -1
  14. package/{dev-server-api → api}/routes/api/dev_package_examples/get.ts +3 -3
  15. package/{dev-server-api → api}/routes/api/dev_package_examples/list.ts +3 -3
  16. package/{dev-server-api → api}/routes/api/dev_package_examples/update.ts +4 -4
  17. package/{dev-server-api → api}/routes/api/dev_server/reset.ts +1 -1
  18. package/{dev-server-api → api}/routes/api/export_files/create.ts +2 -6
  19. package/{dev-server-api → api}/routes/api/export_files/download.ts +1 -3
  20. package/{dev-server-api → api}/routes/api/export_requests/create.ts +3 -4
  21. package/{dev-server-api → api}/routes/api/export_requests/get.ts +5 -8
  22. package/{dev-server-api → api}/routes/api/export_requests/list.ts +2 -3
  23. package/{dev-server-api → api}/routes/api/export_requests/update.ts +3 -5
  24. package/{dev-server-api/routes → api/routes/api}/health.ts +1 -1
  25. package/{dev-server-api → api}/routes/api/package_info/create.ts +1 -1
  26. package/{dev-server-api → api}/routes/api/package_info/get.ts +3 -2
  27. package/{dev-server-api/routes/api → api/routes}/health.ts +1 -1
  28. package/{dev-server-api → api}/routes/index.ts +2 -2
  29. package/{dev-server-api → api}/server.ts +2 -2
  30. package/api/static-routes.ts +24 -0
  31. package/{dev-server-api → api}/tests/fixtures/get-test-server.ts +2 -1
  32. package/api/tests/fixtures/start-server.ts +41 -0
  33. package/{dev-server-api → api}/tests/routes/dev_package_examples/create.test.ts +2 -2
  34. package/{dev-server-api → api}/tests/routes/dev_package_examples/get.test.ts +2 -2
  35. package/{dev-server-api → api}/tests/routes/dev_package_examples/list.test.ts +2 -2
  36. package/{dev-server-api → api}/tests/routes/dev_package_examples/update.test.ts +3 -3
  37. package/{dev-server-api → api}/tests/routes/export_files/create.test.ts +1 -1
  38. package/{dev-server-api → api}/tests/routes/export_files/download.test.ts +3 -3
  39. package/{dev-server-api → api}/tests/routes/export_requests/create.test.ts +2 -2
  40. package/{dev-server-api → api}/tests/routes/export_requests/get.test.ts +2 -2
  41. package/{dev-server-api → api}/tests/routes/export_requests/list.test.ts +1 -1
  42. package/{dev-server-api → api}/tests/routes/export_requests/update.test.ts +1 -1
  43. package/biome.json +49 -0
  44. package/bun.lockb +0 -0
  45. package/{lib → cli/lib}/cmd-fns/add.ts +2 -2
  46. package/{lib → cli/lib}/cmd-fns/auth-login.ts +2 -2
  47. package/{lib → cli/lib}/cmd-fns/dev/check-if-initialized.ts +1 -1
  48. package/{lib → cli/lib}/cmd-fns/dev/derive-selector-from-pcb-component-id.ts +1 -1
  49. package/{lib → cli/lib}/cmd-fns/dev/dev-server-request-handler.ts +5 -5
  50. package/{lib → cli/lib}/cmd-fns/dev/find-available-port.ts +7 -5
  51. package/{lib → cli/lib}/cmd-fns/dev/fulfill-export-requests.ts +27 -27
  52. package/{lib → cli/lib}/cmd-fns/dev/get-dev-server-axios.ts +3 -3
  53. package/{lib → cli/lib}/cmd-fns/dev/index.ts +4 -4
  54. package/{lib → cli/lib}/cmd-fns/dev/infer-export-name-from-source.ts +2 -2
  55. package/{lib → cli/lib}/cmd-fns/dev/soupify-and-upload-example-file.ts +6 -5
  56. package/{lib → cli/lib}/cmd-fns/dev/start-edit-event-watcher.ts +41 -42
  57. package/{lib → cli/lib}/cmd-fns/dev/start-export-request-watcher.ts +3 -4
  58. package/{lib → cli/lib}/cmd-fns/dev/start-fs-watcher.ts +2 -1
  59. package/{lib → cli/lib}/cmd-fns/dev/upload-examples-from-directory.ts +4 -3
  60. package/{lib → cli/lib}/cmd-fns/dev-server-fulfill-export-requests.ts +3 -3
  61. package/{lib → cli/lib}/cmd-fns/dev-server-upload.ts +3 -3
  62. package/{lib → cli/lib}/cmd-fns/export-gerbers.ts +2 -2
  63. package/cli/lib/cmd-fns/go.ts +14 -0
  64. package/{lib → cli/lib}/cmd-fns/index.ts +2 -0
  65. package/{lib → cli/lib}/cmd-fns/init/create-or-modify-npmrc.ts +2 -2
  66. package/{lib → cli/lib}/cmd-fns/init/get-generated-npmrc.ts +1 -1
  67. package/{lib → cli/lib}/cmd-fns/init/index.ts +13 -9
  68. package/{lib → cli/lib}/cmd-fns/install.ts +1 -1
  69. package/{lib → cli/lib}/cmd-fns/lint.ts +16 -10
  70. package/{lib → cli/lib}/cmd-fns/open.ts +1 -1
  71. package/{lib → cli/lib}/cmd-fns/package-examples-create.ts +2 -2
  72. package/{lib → cli/lib}/cmd-fns/package-files-create.ts +1 -1
  73. package/{lib → cli/lib}/cmd-fns/package-files-upload-directory.ts +1 -1
  74. package/{lib → cli/lib}/cmd-fns/package-releases-create.ts +1 -1
  75. package/{lib → cli/lib}/cmd-fns/package-releases-list.ts +1 -1
  76. package/{lib → cli/lib}/cmd-fns/publish/index.ts +34 -34
  77. package/{lib → cli/lib}/cmd-fns/remove.ts +2 -2
  78. package/cli/lib/cmd-fns/render.ts +45 -0
  79. package/{lib → cli/lib}/cmd-fns/soupify.ts +2 -2
  80. package/{lib → cli/lib}/cmd-fns/uninstall.ts +1 -1
  81. package/{lib → cli/lib}/cmd-fns/version.ts +7 -8
  82. package/{lib → cli/lib}/create-config-manager.ts +1 -1
  83. package/{lib → cli/lib}/export-fns/export-bom-csv.ts +3 -3
  84. package/{lib → cli/lib}/export-fns/export-gerbers.ts +6 -6
  85. package/{lib → cli/lib}/export-fns/export-pnp-csv.ts +3 -3
  86. package/{lib → cli/lib}/get-program.ts +37 -21
  87. package/{lib → cli/lib}/param-handlers/interact-for-package-release-id.ts +2 -3
  88. package/{lib → cli/lib}/param-handlers/interact-for-runtime.ts +1 -1
  89. package/{lib → cli/lib}/param-handlers/param-handler-type.ts +1 -1
  90. package/{lib → cli/lib}/posthog.ts +6 -7
  91. package/{lib → cli/lib}/soupify.ts +4 -4
  92. package/{lib → cli/lib}/util/app-context.ts +1 -1
  93. package/{lib → cli/lib}/util/create-context-and-run-program.ts +14 -10
  94. package/{lib → cli/lib}/util/get-all-package-files.ts +2 -2
  95. package/cli/lib/util/lint-project.ts +137 -0
  96. package/{tests → cli/tests}/init.test.ts +1 -1
  97. package/{tests → cli/tests}/open.test.ts +2 -1
  98. package/{tests → cli/tests}/soupify.test.ts +1 -1
  99. package/dist/cli.js +311 -310
  100. package/example-project/package.json +2 -11
  101. package/example-project/src/manual-edits.ts +34 -34
  102. package/{dev-server-frontend/src → frontend}/components/command-k.tsx +2 -2
  103. package/{dev-server-frontend/src → frontend}/components/dialogs/generic-export-dialog.tsx +6 -10
  104. package/{dev-server-frontend/src → frontend}/components/dialogs/gerber-export-dialog.tsx +5 -5
  105. package/{dev-server-frontend/src → frontend}/components/select-example-search.tsx +7 -7
  106. package/{dev-server-frontend/src → frontend}/components/ui/alert-dialog.tsx +7 -7
  107. package/{dev-server-frontend/src → frontend}/components/ui/alert.tsx +2 -2
  108. package/{dev-server-frontend/src → frontend}/components/ui/breadcrumb.tsx +2 -2
  109. package/{dev-server-frontend/src → frontend}/components/ui/button.tsx +3 -3
  110. package/{dev-server-frontend/src → frontend}/components/ui/card.tsx +2 -2
  111. package/{dev-server-frontend/src → frontend}/components/ui/command.tsx +7 -7
  112. package/{dev-server-frontend/src → frontend}/components/ui/context-menu.tsx +9 -9
  113. package/{dev-server-frontend/src → frontend}/components/ui/dialog.tsx +6 -6
  114. package/{dev-server-frontend/src → frontend}/components/ui/menubar.tsx +13 -13
  115. package/{dev-server-frontend/src → frontend}/components/ui/navigation-menu.tsx +7 -7
  116. package/{dev-server-frontend/src → frontend}/components/ui/popover.tsx +2 -2
  117. package/{dev-server-frontend/src → frontend}/components/ui/select.tsx +7 -7
  118. package/{dev-server-frontend/src → frontend}/components/ui/tabs.tsx +4 -4
  119. package/{dev-server-frontend/src → frontend}/components/ui/toggle-group.tsx +3 -3
  120. package/{dev-server-frontend/src → frontend}/components/ui/toggle.tsx +2 -2
  121. package/{dev-server-frontend/src → frontend}/components/ui/tooltip.tsx +2 -2
  122. package/{dev-server-frontend → frontend}/components.json +1 -1
  123. package/{dev-server-frontend/src → frontend}/hooks/use-active-dev-package-example-lite.ts +2 -2
  124. package/{dev-server-frontend → frontend}/index.html +1 -1
  125. package/{dev-server-frontend/src → frontend}/main.tsx +2 -2
  126. package/{dev-server-frontend → frontend}/tailwind.config.js +4 -7
  127. package/frontend/views/App.tsx +22 -0
  128. package/{dev-server-frontend/src → frontend/views}/Header.tsx +5 -5
  129. package/{dev-server-frontend/src → frontend/views}/HeaderMenu.tsx +51 -23
  130. package/{dev-server-frontend/src/ExampleContentView.tsx → frontend/views/MainContentView.tsx} +7 -7
  131. package/frontend/vite.config.ts +50 -0
  132. package/package.json +57 -18
  133. package/renovate.json +2 -4
  134. package/scripts/build-cli.ts +12 -0
  135. package/tsconfig.json +17 -108
  136. package/tsup.config.ts +3 -3
  137. package/.github/workflows/server-tests.yml +0 -31
  138. package/build-cli.ts +0 -14
  139. package/dev-server-api/bun.lockb +0 -0
  140. package/dev-server-api/edgespec.config.ts +0 -4
  141. package/dev-server-api/package.json +0 -23
  142. package/dev-server-api/src/db/create-schema.ts +0 -54
  143. package/dev-server-api/src/lib/public-mapping/public-map-export-file.ts +0 -17
  144. package/dev-server-api/src/lib/public-mapping/public-map-export-request.ts +0 -23
  145. package/dev-server-api/static-routes.ts +0 -24
  146. package/dev-server-api/tests/fixtures/start-server.ts +0 -20
  147. package/dev-server-api/tsconfig.json +0 -28
  148. package/dev-server-frontend/.eslintrc.cjs +0 -20
  149. package/dev-server-frontend/package-lock.json +0 -8970
  150. package/dev-server-frontend/package.json +0 -70
  151. package/dev-server-frontend/postcss.config.js +0 -6
  152. package/dev-server-frontend/src/App.tsx +0 -22
  153. package/dev-server-frontend/tsconfig.json +0 -29
  154. package/dev-server-frontend/tsconfig.node.json +0 -13
  155. package/dev-server-frontend/vite.config.ts +0 -23
  156. package/example-project/package-lock.json +0 -609
  157. package/lib/util/lint-project.ts +0 -112
  158. /package/{dev-server-api → api}/README.md +0 -0
  159. /package/{dev-server-api/src → api}/db/get-db.ts +0 -0
  160. /package/{dev-server-api/src → api}/db/schema.ts +0 -0
  161. /package/{dev-server-api → api}/index.ts +0 -0
  162. /package/{dev-server-api/src → api/lib}/with-winter-spec.ts +0 -0
  163. /package/{dev-server-api/src → api}/lib/zod/export_parameters.ts +0 -0
  164. /package/{dev-server-api → api}/tests/routes/health.test.ts +0 -0
  165. /package/{cli.ts → cli/cli.ts} +0 -0
  166. /package/{lib → cli/lib}/cmd-fns/auth-logout.ts +0 -0
  167. /package/{lib → cli/lib}/cmd-fns/auth-sessions-create.ts +0 -0
  168. /package/{lib → cli/lib}/cmd-fns/auth-sessions-get.ts +0 -0
  169. /package/{lib → cli/lib}/cmd-fns/auth-sessions-list.ts +0 -0
  170. /package/{lib → cli/lib}/cmd-fns/config-clear.ts +0 -0
  171. /package/{lib → cli/lib}/cmd-fns/config-print-config.ts +0 -0
  172. /package/{lib → cli/lib}/cmd-fns/config-reveal-location.ts +0 -0
  173. /package/{lib → cli/lib}/cmd-fns/config-set-log-requests.ts +0 -0
  174. /package/{lib → cli/lib}/cmd-fns/config-set-registry.ts +0 -0
  175. /package/{lib → cli/lib}/cmd-fns/config-set-runtime.ts +0 -0
  176. /package/{lib → cli/lib}/cmd-fns/config-set-session.ts +0 -0
  177. /package/{lib → cli/lib}/cmd-fns/dev/mark-all-examples-loading.ts +0 -0
  178. /package/{lib → cli/lib}/cmd-fns/dev/start-dev-server.ts +0 -0
  179. /package/{lib → cli/lib}/cmd-fns/init/get-generated-readme.ts +0 -0
  180. /package/{lib → cli/lib}/cmd-fns/init/get-generated-tsconfig.ts +0 -0
  181. /package/{lib → cli/lib}/cmd-fns/package-examples-get.ts +0 -0
  182. /package/{lib → cli/lib}/cmd-fns/package-examples-list.ts +0 -0
  183. /package/{lib → cli/lib}/cmd-fns/package-files-download.ts +0 -0
  184. /package/{lib → cli/lib}/cmd-fns/package-files-get.ts +0 -0
  185. /package/{lib → cli/lib}/cmd-fns/package-files-list.ts +0 -0
  186. /package/{lib → cli/lib}/cmd-fns/package-releases-get.ts +0 -0
  187. /package/{lib → cli/lib}/cmd-fns/package-releases-update.ts +0 -0
  188. /package/{lib → cli/lib}/cmd-fns/packages-create.ts +0 -0
  189. /package/{lib → cli/lib}/cmd-fns/packages-get.ts +0 -0
  190. /package/{lib → cli/lib}/cmd-fns/packages-list.ts +0 -0
  191. /package/{lib → cli/lib}/param-handlers/index.ts +0 -0
  192. /package/{lib → cli/lib}/param-handlers/interact-for-local-directory.ts +0 -0
  193. /package/{lib → cli/lib}/param-handlers/interact-for-local-file.ts +0 -0
  194. /package/{lib → cli/lib}/param-handlers/interact-for-package-example-id.ts +0 -0
  195. /package/{lib → cli/lib}/param-handlers/interact-for-package-name-with-version.ts +0 -0
  196. /package/{lib → cli/lib}/param-handlers/interact-for-package-name.ts +0 -0
  197. /package/{lib → cli/lib}/param-handlers/interact-for-registry-url.ts +0 -0
  198. /package/example-project/examples/{basic-bug.tsx → basic-chip.tsx} +0 -0
  199. /package/{dev-server-frontend → frontend}/README.md +0 -0
  200. /package/{dev-server-frontend → frontend}/bun.lockb +0 -0
  201. /package/{dev-server-frontend/src → frontend}/components/global-context-providers.tsx +0 -0
  202. /package/{dev-server-frontend/src → frontend}/hooks/toast-if-api-not-connected.ts +0 -0
  203. /package/{dev-server-frontend/src → frontend}/hooks/use-dev-package-examples.tsx +0 -0
  204. /package/{dev-server-frontend/src → frontend}/hooks/use-global-store.ts +0 -0
  205. /package/{dev-server-frontend/src → frontend}/index.css +0 -0
  206. /package/{dev-server-frontend/src → frontend}/lib/utils.ts +0 -0
  207. /package/{dev-server-frontend/src → frontend}/vite-env.d.ts +0 -0
@@ -1,14 +1,13 @@
1
- import { PostHog } from 'posthog-node'
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
- POSTHOG_API_KEY,
10
- { host: 'https://us.i.posthog.com' }
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,6 +1,6 @@
1
1
  import { AxiosInstance } from "axios"
2
2
  import Configstore from "configstore"
3
- import { ContextConfigProps } from "lib/create-config-manager"
3
+ import { ContextConfigProps } from "cli/lib/create-config-manager"
4
4
 
5
5
  export type AppContext = {
6
6
  args: any
@@ -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(kleur.red("Authentication failed. Please run 'tsci login' to authenticate yourself."))
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("tsci open", async () => {
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-bug.tsx`.text()
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
  })