@tscircuit/cli 0.1.131 → 0.1.132
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 +121 -51
- 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.131";
|
|
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
|
|
@@ -496989,7 +497059,7 @@ var snapshotProject = async ({
|
|
|
496989
497059
|
...ignored.map(normalizeIgnorePattern)
|
|
496990
497060
|
];
|
|
496991
497061
|
const boardFiles = globbySync("**/*.board.tsx", { cwd: projectDir, ignore });
|
|
496992
|
-
let files = boardFiles.map((f) =>
|
|
497062
|
+
let files = boardFiles.map((f) => path26.join(projectDir, f));
|
|
496993
497063
|
if (files.length === 0) {
|
|
496994
497064
|
const entry = await getEntrypoint({
|
|
496995
497065
|
projectDir,
|
|
@@ -497006,9 +497076,9 @@ var snapshotProject = async ({
|
|
|
497006
497076
|
const pcbSvg = convertCircuitJsonToPcbSvg(circuitJson);
|
|
497007
497077
|
const schSvg = convertCircuitJsonToSchematicSvg(circuitJson);
|
|
497008
497078
|
const svg3d = threeD ? await convertCircuitJsonToSimple3dSvg(circuitJson) : null;
|
|
497009
|
-
const snapDir =
|
|
497010
|
-
|
|
497011
|
-
const base =
|
|
497079
|
+
const snapDir = path26.join(path26.dirname(file), "__snapshots__");
|
|
497080
|
+
fs26.mkdirSync(snapDir, { recursive: true });
|
|
497081
|
+
const base = path26.basename(file).replace(/\.tsx$/, "");
|
|
497012
497082
|
const snapshotPairs = [
|
|
497013
497083
|
["pcb", pcbSvg],
|
|
497014
497084
|
["schematic", schSvg]
|
|
@@ -497017,11 +497087,11 @@ var snapshotProject = async ({
|
|
|
497017
497087
|
snapshotPairs.push(["3d", svg3d]);
|
|
497018
497088
|
}
|
|
497019
497089
|
for (const [type, svg] of snapshotPairs) {
|
|
497020
|
-
const snapPath =
|
|
497021
|
-
if (update || !
|
|
497022
|
-
|
|
497090
|
+
const snapPath = path26.join(snapDir, `${base}-${type}.snap.svg`);
|
|
497091
|
+
if (update || !fs26.existsSync(snapPath)) {
|
|
497092
|
+
fs26.writeFileSync(snapPath, svg);
|
|
497023
497093
|
} else {
|
|
497024
|
-
const existing =
|
|
497094
|
+
const existing = fs26.readFileSync(snapPath, "utf-8");
|
|
497025
497095
|
if (existing !== svg)
|
|
497026
497096
|
mismatches.push(snapPath);
|
|
497027
497097
|
}
|
|
@@ -497055,22 +497125,22 @@ var registerSnapshot = (program3) => {
|
|
|
497055
497125
|
};
|
|
497056
497126
|
|
|
497057
497127
|
// lib/shared/setup-github-actions.ts
|
|
497058
|
-
import
|
|
497059
|
-
import
|
|
497128
|
+
import fs27 from "node:fs";
|
|
497129
|
+
import path27 from "node:path";
|
|
497060
497130
|
var setupGithubActions = (projectDir = process.cwd()) => {
|
|
497061
497131
|
const findGitRoot = (startDir) => {
|
|
497062
|
-
let dir =
|
|
497063
|
-
while (dir !==
|
|
497064
|
-
if (
|
|
497132
|
+
let dir = path27.resolve(startDir);
|
|
497133
|
+
while (dir !== path27.parse(dir).root) {
|
|
497134
|
+
if (fs27.existsSync(path27.join(dir, ".git"))) {
|
|
497065
497135
|
return dir;
|
|
497066
497136
|
}
|
|
497067
|
-
dir =
|
|
497137
|
+
dir = path27.dirname(dir);
|
|
497068
497138
|
}
|
|
497069
497139
|
return null;
|
|
497070
497140
|
};
|
|
497071
497141
|
const gitRoot = findGitRoot(projectDir) ?? projectDir;
|
|
497072
|
-
const workflowsDir =
|
|
497073
|
-
|
|
497142
|
+
const workflowsDir = path27.join(gitRoot, ".github", "workflows");
|
|
497143
|
+
fs27.mkdirSync(workflowsDir, { recursive: true });
|
|
497074
497144
|
const buildWorkflow = `name: tscircuit Build
|
|
497075
497145
|
|
|
497076
497146
|
on:
|
|
@@ -497109,8 +497179,8 @@ jobs:
|
|
|
497109
497179
|
git commit -m "Update snapshots" || echo "No changes to commit"
|
|
497110
497180
|
git push
|
|
497111
497181
|
`;
|
|
497112
|
-
writeFileIfNotExists(
|
|
497113
|
-
writeFileIfNotExists(
|
|
497182
|
+
writeFileIfNotExists(path27.join(workflowsDir, "tscircuit-build.yml"), buildWorkflow);
|
|
497183
|
+
writeFileIfNotExists(path27.join(workflowsDir, "tscircuit-snapshot.yml"), snapshotWorkflow);
|
|
497114
497184
|
};
|
|
497115
497185
|
|
|
497116
497186
|
// cli/setup/register.ts
|