@tscircuit/cli 0.1.131 → 0.1.133
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/README.md +3 -3
- package/dist/main.js +137 -60
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,9 +39,9 @@ Options:
|
|
|
39
39
|
-h, --help display help for command
|
|
40
40
|
|
|
41
41
|
Commands:
|
|
42
|
-
init [directory] Initialize a new TSCircuit project in the
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
init [directory] Initialize a new TSCircuit project in the specified
|
|
43
|
+
directory (or current directory if none is
|
|
44
|
+
provided)
|
|
45
45
|
dev [options] [file] Start development server for a package
|
|
46
46
|
clone [options] <package> Clone a package from the registry
|
|
47
47
|
push [options] [file] Save snippet code to Registry API
|
package/dist/main.js
CHANGED
|
@@ -442169,7 +442169,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
|
|
|
442169
442169
|
import { execSync as execSync2 } from "node:child_process";
|
|
442170
442170
|
var import_semver2 = __toESM2(require_semver2(), 1);
|
|
442171
442171
|
// package.json
|
|
442172
|
-
var version = "0.1.
|
|
442172
|
+
var version = "0.1.132";
|
|
442173
442173
|
var package_default = {
|
|
442174
442174
|
name: "@tscircuit/cli",
|
|
442175
442175
|
version,
|
|
@@ -496271,6 +496271,10 @@ var registerRemove = (program3) => {
|
|
|
496271
496271
|
};
|
|
496272
496272
|
|
|
496273
496273
|
// cli/build/register.ts
|
|
496274
|
+
import path25 from "node:path";
|
|
496275
|
+
import fs25 from "node:fs";
|
|
496276
|
+
|
|
496277
|
+
// cli/build/build-file.ts
|
|
496274
496278
|
import path23 from "node:path";
|
|
496275
496279
|
import fs23 from "node:fs";
|
|
496276
496280
|
|
|
@@ -496296,46 +496300,112 @@ function analyzeCircuitJson(circuitJson) {
|
|
|
496296
496300
|
return { errors, warnings };
|
|
496297
496301
|
}
|
|
496298
496302
|
|
|
496299
|
-
// cli/build/
|
|
496300
|
-
var
|
|
496301
|
-
|
|
496302
|
-
const
|
|
496303
|
-
|
|
496304
|
-
|
|
496305
|
-
|
|
496306
|
-
const
|
|
496307
|
-
|
|
496308
|
-
|
|
496309
|
-
|
|
496310
|
-
|
|
496311
|
-
fs23.writeFileSync(outputPath, JSON.stringify(result.circuitJson, null, 2));
|
|
496312
|
-
console.log(`Circuit JSON written to ${path23.relative(projectDir, outputPath)}`);
|
|
496313
|
-
const { errors, warnings } = analyzeCircuitJson(result.circuitJson);
|
|
496314
|
-
if (!options?.ignoreWarnings) {
|
|
496315
|
-
for (const warn of warnings) {
|
|
496316
|
-
const msg = warn.message || JSON.stringify(warn);
|
|
496317
|
-
console.log(kleur_default.yellow(msg));
|
|
496318
|
-
}
|
|
496303
|
+
// cli/build/build-file.ts
|
|
496304
|
+
var buildFile = async (input, output, projectDir, options) => {
|
|
496305
|
+
try {
|
|
496306
|
+
const result = await generateCircuitJson({ filePath: input });
|
|
496307
|
+
fs23.mkdirSync(path23.dirname(output), { recursive: true });
|
|
496308
|
+
fs23.writeFileSync(output, JSON.stringify(result.circuitJson, null, 2));
|
|
496309
|
+
console.log(`Circuit JSON written to ${path23.relative(projectDir, output)}`);
|
|
496310
|
+
const { errors, warnings } = analyzeCircuitJson(result.circuitJson);
|
|
496311
|
+
if (!options?.ignoreWarnings) {
|
|
496312
|
+
for (const warn of warnings) {
|
|
496313
|
+
const msg = warn.message || JSON.stringify(warn);
|
|
496314
|
+
console.log(kleur_default.yellow(msg));
|
|
496319
496315
|
}
|
|
496320
|
-
|
|
496321
|
-
|
|
496322
|
-
|
|
496323
|
-
|
|
496324
|
-
|
|
496316
|
+
}
|
|
496317
|
+
if (!options?.ignoreErrors) {
|
|
496318
|
+
for (const err of errors) {
|
|
496319
|
+
const msg = err.message || JSON.stringify(err);
|
|
496320
|
+
console.error(kleur_default.red(msg));
|
|
496325
496321
|
}
|
|
496326
|
-
|
|
496327
|
-
|
|
496322
|
+
}
|
|
496323
|
+
return errors.length === 0;
|
|
496324
|
+
} catch (err) {
|
|
496325
|
+
console.error(`Build failed: ${err}`);
|
|
496326
|
+
return false;
|
|
496327
|
+
}
|
|
496328
|
+
};
|
|
496329
|
+
|
|
496330
|
+
// cli/build/get-build-entrypoints.ts
|
|
496331
|
+
import fs24 from "node:fs";
|
|
496332
|
+
import path24 from "node:path";
|
|
496333
|
+
async function getBuildEntrypoints({
|
|
496334
|
+
fileOrDir,
|
|
496335
|
+
rootDir = process.cwd()
|
|
496336
|
+
}) {
|
|
496337
|
+
const resolvedRoot = path24.resolve(rootDir);
|
|
496338
|
+
if (fileOrDir) {
|
|
496339
|
+
const resolved = path24.resolve(resolvedRoot, fileOrDir);
|
|
496340
|
+
if (fs24.existsSync(resolved) && fs24.statSync(resolved).isDirectory()) {
|
|
496341
|
+
const projectDir2 = resolved;
|
|
496342
|
+
const circuitFiles2 = [];
|
|
496343
|
+
const mainEntrypoint2 = await getEntrypoint({
|
|
496344
|
+
projectDir: projectDir2,
|
|
496345
|
+
onError: () => {}
|
|
496346
|
+
});
|
|
496347
|
+
const files2 = globbySync("**/*.circuit.tsx", {
|
|
496348
|
+
cwd: projectDir2,
|
|
496349
|
+
ignore: DEFAULT_IGNORED_PATTERNS
|
|
496350
|
+
});
|
|
496351
|
+
for (const f of files2) {
|
|
496352
|
+
circuitFiles2.push(path24.join(projectDir2, f));
|
|
496328
496353
|
}
|
|
496329
|
-
|
|
496330
|
-
|
|
496331
|
-
|
|
496354
|
+
return {
|
|
496355
|
+
projectDir: projectDir2,
|
|
496356
|
+
mainEntrypoint: mainEntrypoint2 || undefined,
|
|
496357
|
+
circuitFiles: circuitFiles2
|
|
496358
|
+
};
|
|
496359
|
+
}
|
|
496360
|
+
return { projectDir: path24.dirname(resolved), circuitFiles: [resolved] };
|
|
496361
|
+
}
|
|
496362
|
+
const projectDir = resolvedRoot;
|
|
496363
|
+
const circuitFiles = [];
|
|
496364
|
+
const mainEntrypoint = await getEntrypoint({ projectDir, onError: () => {} });
|
|
496365
|
+
const files = globbySync("**/*.circuit.tsx", {
|
|
496366
|
+
cwd: projectDir,
|
|
496367
|
+
ignore: DEFAULT_IGNORED_PATTERNS
|
|
496368
|
+
});
|
|
496369
|
+
for (const f of files) {
|
|
496370
|
+
circuitFiles.push(path24.join(projectDir, f));
|
|
496371
|
+
}
|
|
496372
|
+
return {
|
|
496373
|
+
projectDir,
|
|
496374
|
+
mainEntrypoint: mainEntrypoint || undefined,
|
|
496375
|
+
circuitFiles
|
|
496376
|
+
};
|
|
496377
|
+
}
|
|
496378
|
+
|
|
496379
|
+
// cli/build/register.ts
|
|
496380
|
+
var registerBuild = (program3) => {
|
|
496381
|
+
program3.command("build").description("Run tscircuit eval and output circuit json").argument("[file]", "Path to the entry file").option("--ignore-errors", "Do not exit with code 1 on errors").option("--ignore-warnings", "Do not log warnings").action(async (file, options) => {
|
|
496382
|
+
const { projectDir, mainEntrypoint, circuitFiles } = await getBuildEntrypoints({ fileOrDir: file });
|
|
496383
|
+
const distDir = path25.join(projectDir, "dist");
|
|
496384
|
+
fs25.mkdirSync(distDir, { recursive: true });
|
|
496385
|
+
let hasErrors = false;
|
|
496386
|
+
if (mainEntrypoint) {
|
|
496387
|
+
const outputPath = path25.join(distDir, "circuit.json");
|
|
496388
|
+
const ok = await buildFile(mainEntrypoint, outputPath, projectDir, options);
|
|
496389
|
+
if (!ok)
|
|
496390
|
+
hasErrors = true;
|
|
496391
|
+
}
|
|
496392
|
+
for (const filePath of circuitFiles) {
|
|
496393
|
+
const relative6 = path25.relative(projectDir, filePath);
|
|
496394
|
+
const isCircuit = filePath.endsWith(".circuit.tsx");
|
|
496395
|
+
const outputPath = isCircuit ? path25.join(distDir, relative6.replace(/\.circuit\.tsx$/, ""), "circuit.json") : path25.join(distDir, "circuit.json");
|
|
496396
|
+
const ok = await buildFile(filePath, outputPath, projectDir, options);
|
|
496397
|
+
if (!ok)
|
|
496398
|
+
hasErrors = true;
|
|
496399
|
+
}
|
|
496400
|
+
if (hasErrors && !options?.ignoreErrors) {
|
|
496401
|
+
process.exit(1);
|
|
496332
496402
|
}
|
|
496333
496403
|
});
|
|
496334
496404
|
};
|
|
496335
496405
|
|
|
496336
496406
|
// lib/shared/snapshot-project.ts
|
|
496337
|
-
import
|
|
496338
|
-
import
|
|
496407
|
+
import fs26 from "node:fs";
|
|
496408
|
+
import path26 from "node:path";
|
|
496339
496409
|
init_dist6();
|
|
496340
496410
|
|
|
496341
496411
|
// node_modules/circuit-json-to-simple-3d/dist/index.js
|
|
@@ -496988,17 +497058,24 @@ var snapshotProject = async ({
|
|
|
496988
497058
|
...DEFAULT_IGNORED_PATTERNS,
|
|
496989
497059
|
...ignored.map(normalizeIgnorePattern)
|
|
496990
497060
|
];
|
|
496991
|
-
const boardFiles = globbySync("**/*.board.tsx",
|
|
496992
|
-
|
|
497061
|
+
const boardFiles = globbySync(["**/*.board.tsx", "**/*.circuit.tsx"], {
|
|
497062
|
+
cwd: projectDir,
|
|
497063
|
+
ignore
|
|
497064
|
+
});
|
|
497065
|
+
let files = boardFiles.map((f) => path26.join(projectDir, f));
|
|
497066
|
+
const entry = await getEntrypoint({
|
|
497067
|
+
projectDir,
|
|
497068
|
+
onError,
|
|
497069
|
+
onSuccess: () => {}
|
|
497070
|
+
});
|
|
497071
|
+
if (entry) {
|
|
497072
|
+
const resolved = path26.resolve(projectDir, entry);
|
|
497073
|
+
if (!files.includes(resolved)) {
|
|
497074
|
+
files.unshift(resolved);
|
|
497075
|
+
}
|
|
497076
|
+
}
|
|
496993
497077
|
if (files.length === 0) {
|
|
496994
|
-
|
|
496995
|
-
projectDir,
|
|
496996
|
-
onError,
|
|
496997
|
-
onSuccess: () => {}
|
|
496998
|
-
});
|
|
496999
|
-
if (!entry)
|
|
497000
|
-
return onExit(1);
|
|
497001
|
-
files = [entry];
|
|
497078
|
+
return onExit(1);
|
|
497002
497079
|
}
|
|
497003
497080
|
const mismatches = [];
|
|
497004
497081
|
for (const file of files) {
|
|
@@ -497006,9 +497083,9 @@ var snapshotProject = async ({
|
|
|
497006
497083
|
const pcbSvg = convertCircuitJsonToPcbSvg(circuitJson);
|
|
497007
497084
|
const schSvg = convertCircuitJsonToSchematicSvg(circuitJson);
|
|
497008
497085
|
const svg3d = threeD ? await convertCircuitJsonToSimple3dSvg(circuitJson) : null;
|
|
497009
|
-
const snapDir =
|
|
497010
|
-
|
|
497011
|
-
const base =
|
|
497086
|
+
const snapDir = path26.join(path26.dirname(file), "__snapshots__");
|
|
497087
|
+
fs26.mkdirSync(snapDir, { recursive: true });
|
|
497088
|
+
const base = path26.basename(file).replace(/\.tsx$/, "");
|
|
497012
497089
|
const snapshotPairs = [
|
|
497013
497090
|
["pcb", pcbSvg],
|
|
497014
497091
|
["schematic", schSvg]
|
|
@@ -497017,11 +497094,11 @@ var snapshotProject = async ({
|
|
|
497017
497094
|
snapshotPairs.push(["3d", svg3d]);
|
|
497018
497095
|
}
|
|
497019
497096
|
for (const [type, svg] of snapshotPairs) {
|
|
497020
|
-
const snapPath =
|
|
497021
|
-
if (update || !
|
|
497022
|
-
|
|
497097
|
+
const snapPath = path26.join(snapDir, `${base}-${type}.snap.svg`);
|
|
497098
|
+
if (update || !fs26.existsSync(snapPath)) {
|
|
497099
|
+
fs26.writeFileSync(snapPath, svg);
|
|
497023
497100
|
} else {
|
|
497024
|
-
const existing =
|
|
497101
|
+
const existing = fs26.readFileSync(snapPath, "utf-8");
|
|
497025
497102
|
if (existing !== svg)
|
|
497026
497103
|
mismatches.push(snapPath);
|
|
497027
497104
|
}
|
|
@@ -497055,22 +497132,22 @@ var registerSnapshot = (program3) => {
|
|
|
497055
497132
|
};
|
|
497056
497133
|
|
|
497057
497134
|
// lib/shared/setup-github-actions.ts
|
|
497058
|
-
import
|
|
497059
|
-
import
|
|
497135
|
+
import fs27 from "node:fs";
|
|
497136
|
+
import path27 from "node:path";
|
|
497060
497137
|
var setupGithubActions = (projectDir = process.cwd()) => {
|
|
497061
497138
|
const findGitRoot = (startDir) => {
|
|
497062
|
-
let dir =
|
|
497063
|
-
while (dir !==
|
|
497064
|
-
if (
|
|
497139
|
+
let dir = path27.resolve(startDir);
|
|
497140
|
+
while (dir !== path27.parse(dir).root) {
|
|
497141
|
+
if (fs27.existsSync(path27.join(dir, ".git"))) {
|
|
497065
497142
|
return dir;
|
|
497066
497143
|
}
|
|
497067
|
-
dir =
|
|
497144
|
+
dir = path27.dirname(dir);
|
|
497068
497145
|
}
|
|
497069
497146
|
return null;
|
|
497070
497147
|
};
|
|
497071
497148
|
const gitRoot = findGitRoot(projectDir) ?? projectDir;
|
|
497072
|
-
const workflowsDir =
|
|
497073
|
-
|
|
497149
|
+
const workflowsDir = path27.join(gitRoot, ".github", "workflows");
|
|
497150
|
+
fs27.mkdirSync(workflowsDir, { recursive: true });
|
|
497074
497151
|
const buildWorkflow = `name: tscircuit Build
|
|
497075
497152
|
|
|
497076
497153
|
on:
|
|
@@ -497109,8 +497186,8 @@ jobs:
|
|
|
497109
497186
|
git commit -m "Update snapshots" || echo "No changes to commit"
|
|
497110
497187
|
git push
|
|
497111
497188
|
`;
|
|
497112
|
-
writeFileIfNotExists(
|
|
497113
|
-
writeFileIfNotExists(
|
|
497189
|
+
writeFileIfNotExists(path27.join(workflowsDir, "tscircuit-build.yml"), buildWorkflow);
|
|
497190
|
+
writeFileIfNotExists(path27.join(workflowsDir, "tscircuit-snapshot.yml"), snapshotWorkflow);
|
|
497114
497191
|
};
|
|
497115
497192
|
|
|
497116
497193
|
// cli/setup/register.ts
|