@tscircuit/cli 0.1.838 → 0.1.839
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/dist/build/build-worker-entrypoint.js +45 -8
- package/dist/main.js +346 -265
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -56027,7 +56027,8 @@ var require_queue = __commonJS((exports2, module2) => {
|
|
|
56027
56027
|
empty: noop2,
|
|
56028
56028
|
kill,
|
|
56029
56029
|
killAndDrain,
|
|
56030
|
-
error
|
|
56030
|
+
error,
|
|
56031
|
+
abort
|
|
56031
56032
|
};
|
|
56032
56033
|
return self2;
|
|
56033
56034
|
function running() {
|
|
@@ -56147,6 +56148,28 @@ var require_queue = __commonJS((exports2, module2) => {
|
|
|
56147
56148
|
self2.drain();
|
|
56148
56149
|
self2.drain = noop2;
|
|
56149
56150
|
}
|
|
56151
|
+
function abort() {
|
|
56152
|
+
var current = queueHead;
|
|
56153
|
+
queueHead = null;
|
|
56154
|
+
queueTail = null;
|
|
56155
|
+
while (current) {
|
|
56156
|
+
var next = current.next;
|
|
56157
|
+
var callback = current.callback;
|
|
56158
|
+
var errorHandler2 = current.errorHandler;
|
|
56159
|
+
var val = current.value;
|
|
56160
|
+
var context2 = current.context;
|
|
56161
|
+
current.value = null;
|
|
56162
|
+
current.callback = noop2;
|
|
56163
|
+
current.errorHandler = null;
|
|
56164
|
+
if (errorHandler2) {
|
|
56165
|
+
errorHandler2(new Error("abort"), val);
|
|
56166
|
+
}
|
|
56167
|
+
callback.call(context2, new Error("abort"));
|
|
56168
|
+
current.release(current);
|
|
56169
|
+
current = next;
|
|
56170
|
+
}
|
|
56171
|
+
self2.drain = noop2;
|
|
56172
|
+
}
|
|
56150
56173
|
function error(handler) {
|
|
56151
56174
|
errorHandler = handler;
|
|
56152
56175
|
}
|
|
@@ -73806,9 +73829,6 @@ var deepMerge = (...sources) => {
|
|
|
73806
73829
|
returnValue.signal = signals.at(-1);
|
|
73807
73830
|
}
|
|
73808
73831
|
}
|
|
73809
|
-
if (returnValue.context === undefined) {
|
|
73810
|
-
returnValue.context = {};
|
|
73811
|
-
}
|
|
73812
73832
|
return returnValue;
|
|
73813
73833
|
};
|
|
73814
73834
|
|
|
@@ -73838,12 +73858,14 @@ var normalizeRetryOptions = (retry2 = {}) => {
|
|
|
73838
73858
|
if (retry2.methods && !Array.isArray(retry2.methods)) {
|
|
73839
73859
|
throw new Error("retry.methods must be an array");
|
|
73840
73860
|
}
|
|
73861
|
+
retry2.methods &&= retry2.methods.map((method) => method.toLowerCase());
|
|
73841
73862
|
if (retry2.statusCodes && !Array.isArray(retry2.statusCodes)) {
|
|
73842
73863
|
throw new Error("retry.statusCodes must be an array");
|
|
73843
73864
|
}
|
|
73865
|
+
const normalizedRetry = Object.fromEntries(Object.entries(retry2).filter(([, value]) => value !== undefined));
|
|
73844
73866
|
return {
|
|
73845
73867
|
...defaultRetryOptions,
|
|
73846
|
-
...
|
|
73868
|
+
...normalizedRetry
|
|
73847
73869
|
};
|
|
73848
73870
|
};
|
|
73849
73871
|
|
|
@@ -73942,17 +73964,27 @@ class Ky {
|
|
|
73942
73964
|
let response = await ky.#fetch();
|
|
73943
73965
|
for (const hook of ky.#options.hooks.afterResponse) {
|
|
73944
73966
|
const clonedResponse = ky.#decorateResponse(response.clone());
|
|
73945
|
-
|
|
73946
|
-
|
|
73947
|
-
|
|
73967
|
+
let modifiedResponse;
|
|
73968
|
+
try {
|
|
73969
|
+
modifiedResponse = await hook(ky.request, ky.#getNormalizedOptions(), clonedResponse, { retryCount: ky.#retryCount });
|
|
73970
|
+
} catch (error) {
|
|
73971
|
+
ky.#cancelResponseBody(clonedResponse);
|
|
73972
|
+
ky.#cancelResponseBody(response);
|
|
73973
|
+
throw error;
|
|
73948
73974
|
}
|
|
73949
73975
|
if (modifiedResponse instanceof RetryMarker) {
|
|
73950
|
-
|
|
73951
|
-
|
|
73952
|
-
response.body?.cancel()
|
|
73953
|
-
]);
|
|
73976
|
+
ky.#cancelResponseBody(clonedResponse);
|
|
73977
|
+
ky.#cancelResponseBody(response);
|
|
73954
73978
|
throw new ForceRetryError(modifiedResponse.options);
|
|
73955
73979
|
}
|
|
73980
|
+
const nextResponse = modifiedResponse instanceof globalThis.Response ? modifiedResponse : response;
|
|
73981
|
+
if (clonedResponse !== nextResponse) {
|
|
73982
|
+
ky.#cancelResponseBody(clonedResponse);
|
|
73983
|
+
}
|
|
73984
|
+
if (response !== nextResponse) {
|
|
73985
|
+
ky.#cancelResponseBody(response);
|
|
73986
|
+
}
|
|
73987
|
+
response = nextResponse;
|
|
73956
73988
|
}
|
|
73957
73989
|
ky.#decorateResponse(response);
|
|
73958
73990
|
if (!response.ok && (typeof ky.#options.throwHttpErrors === "function" ? ky.#options.throwHttpErrors(response.status) : ky.#options.throwHttpErrors)) {
|
|
@@ -73969,20 +74001,16 @@ class Ky {
|
|
|
73969
74001
|
if (!supportsResponseStreams) {
|
|
73970
74002
|
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
73971
74003
|
}
|
|
73972
|
-
|
|
74004
|
+
const progressResponse = response.clone();
|
|
74005
|
+
ky.#cancelResponseBody(response);
|
|
74006
|
+
return streamResponse(progressResponse, ky.#options.onDownloadProgress);
|
|
73973
74007
|
}
|
|
73974
74008
|
return response;
|
|
73975
74009
|
};
|
|
73976
|
-
const result = ky.#retry(function_).finally(
|
|
74010
|
+
const result = ky.#retry(function_).finally(() => {
|
|
73977
74011
|
const originalRequest = ky.#originalRequest;
|
|
73978
|
-
|
|
73979
|
-
|
|
73980
|
-
cleanupPromises.push(originalRequest.body?.cancel());
|
|
73981
|
-
}
|
|
73982
|
-
if (!ky.request.bodyUsed) {
|
|
73983
|
-
cleanupPromises.push(ky.request.body?.cancel());
|
|
73984
|
-
}
|
|
73985
|
-
await Promise.all(cleanupPromises);
|
|
74012
|
+
ky.#cancelBody(originalRequest?.body ?? undefined);
|
|
74013
|
+
ky.#cancelBody(ky.request.body ?? undefined);
|
|
73986
74014
|
});
|
|
73987
74015
|
for (const [type, mimeType] of Object.entries(responseTypes)) {
|
|
73988
74016
|
if (type === "bytes" && typeof globalThis.Response?.prototype?.bytes !== "function") {
|
|
@@ -74098,7 +74126,8 @@ class Ky {
|
|
|
74098
74126
|
jitteredDelay = retryDelay;
|
|
74099
74127
|
}
|
|
74100
74128
|
}
|
|
74101
|
-
|
|
74129
|
+
const backoffLimit = this.#options.retry.backoffLimit ?? Number.POSITIVE_INFINITY;
|
|
74130
|
+
return Math.min(backoffLimit, jitteredDelay);
|
|
74102
74131
|
}
|
|
74103
74132
|
async#calculateRetryDelay(error) {
|
|
74104
74133
|
this.#retryCount++;
|
|
@@ -74151,6 +74180,17 @@ class Ky {
|
|
|
74151
74180
|
}
|
|
74152
74181
|
return response;
|
|
74153
74182
|
}
|
|
74183
|
+
#cancelBody(body) {
|
|
74184
|
+
if (!body) {
|
|
74185
|
+
return;
|
|
74186
|
+
}
|
|
74187
|
+
body.cancel().catch(() => {
|
|
74188
|
+
return;
|
|
74189
|
+
});
|
|
74190
|
+
}
|
|
74191
|
+
#cancelResponseBody(response) {
|
|
74192
|
+
this.#cancelBody(response.body ?? undefined);
|
|
74193
|
+
}
|
|
74154
74194
|
async#retry(function_) {
|
|
74155
74195
|
try {
|
|
74156
74196
|
return await function_();
|
|
@@ -74267,7 +74307,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
|
|
|
74267
74307
|
import { execSync as execSync2 } from "node:child_process";
|
|
74268
74308
|
var import_semver2 = __toESM2(require_semver2(), 1);
|
|
74269
74309
|
// package.json
|
|
74270
|
-
var version = "0.1.
|
|
74310
|
+
var version = "0.1.838";
|
|
74271
74311
|
var package_default = {
|
|
74272
74312
|
name: "@tscircuit/cli",
|
|
74273
74313
|
version,
|
|
@@ -74328,7 +74368,7 @@ var package_default = {
|
|
|
74328
74368
|
semver: "^7.6.3",
|
|
74329
74369
|
sharp: "0.32.6",
|
|
74330
74370
|
tempy: "^3.1.0",
|
|
74331
|
-
tscircuit: "^0.0.
|
|
74371
|
+
tscircuit: "^0.0.1224-libonly",
|
|
74332
74372
|
tsx: "^4.7.1",
|
|
74333
74373
|
"typed-ky": "^0.0.4",
|
|
74334
74374
|
zod: "^3.23.8"
|
|
@@ -172884,12 +172924,12 @@ var registerRemove = (program3) => {
|
|
|
172884
172924
|
};
|
|
172885
172925
|
|
|
172886
172926
|
// cli/build/register.ts
|
|
172887
|
-
import
|
|
172888
|
-
import
|
|
172927
|
+
import path51 from "node:path";
|
|
172928
|
+
import fs51 from "node:fs";
|
|
172889
172929
|
|
|
172890
172930
|
// cli/build/build-file.ts
|
|
172891
|
-
import
|
|
172892
|
-
import
|
|
172931
|
+
import path37 from "node:path";
|
|
172932
|
+
import fs37 from "node:fs";
|
|
172893
172933
|
|
|
172894
172934
|
// lib/shared/circuit-json-diagnostics.ts
|
|
172895
172935
|
function analyzeCircuitJson(circuitJson) {
|
|
@@ -172915,6 +172955,8 @@ function analyzeCircuitJson(circuitJson) {
|
|
|
172915
172955
|
|
|
172916
172956
|
// lib/shared/get-complete-platform-config.ts
|
|
172917
172957
|
import { getPlatformConfig } from "@tscircuit/eval/platform-config";
|
|
172958
|
+
import path36 from "node:path";
|
|
172959
|
+
import fs36 from "node:fs";
|
|
172918
172960
|
function getCompletePlatformConfig(userConfig) {
|
|
172919
172961
|
const basePlatformConfig = getPlatformConfig();
|
|
172920
172962
|
const defaultConfig = {
|
|
@@ -172923,7 +172965,23 @@ function getCompletePlatformConfig(userConfig) {
|
|
|
172923
172965
|
...basePlatformConfig.footprintFileParserMap,
|
|
172924
172966
|
kicad_mod: {
|
|
172925
172967
|
loadFromUrl: async (url) => {
|
|
172926
|
-
|
|
172968
|
+
let fetchUrl = url;
|
|
172969
|
+
if (url.startsWith("./") || url.startsWith("../")) {
|
|
172970
|
+
const absolutePath = path36.resolve(process.cwd(), url);
|
|
172971
|
+
fetchUrl = `file://${absolutePath}`;
|
|
172972
|
+
} else if (url.startsWith("/")) {
|
|
172973
|
+
if (fs36.existsSync(url)) {
|
|
172974
|
+
fetchUrl = `file://${url}`;
|
|
172975
|
+
} else {
|
|
172976
|
+
const relativePath = `.${url}`;
|
|
172977
|
+
const absolutePath = path36.resolve(process.cwd(), relativePath);
|
|
172978
|
+
if (fs36.existsSync(absolutePath)) {
|
|
172979
|
+
fetchUrl = `file://${absolutePath}`;
|
|
172980
|
+
} else {
|
|
172981
|
+
fetchUrl = `file://${url}`;
|
|
172982
|
+
}
|
|
172983
|
+
}
|
|
172984
|
+
}
|
|
172927
172985
|
return basePlatformConfig.footprintFileParserMap.kicad_mod.loadFromUrl(fetchUrl);
|
|
172928
172986
|
}
|
|
172929
172987
|
}
|
|
@@ -172951,9 +173009,9 @@ var buildFile = async (input, output, projectDir, options) => {
|
|
|
172951
173009
|
filePath: input,
|
|
172952
173010
|
platformConfig: completePlatformConfig
|
|
172953
173011
|
});
|
|
172954
|
-
|
|
172955
|
-
|
|
172956
|
-
console.log(`Circuit JSON written to ${
|
|
173012
|
+
fs37.mkdirSync(path37.dirname(output), { recursive: true });
|
|
173013
|
+
fs37.writeFileSync(output, JSON.stringify(result.circuitJson, null, 2));
|
|
173014
|
+
console.log(`Circuit JSON written to ${path37.relative(projectDir, output)}`);
|
|
172957
173015
|
const { errors, warnings } = analyzeCircuitJson(result.circuitJson);
|
|
172958
173016
|
if (!options?.ignoreWarnings) {
|
|
172959
173017
|
for (const warn of warnings) {
|
|
@@ -172965,7 +173023,9 @@ var buildFile = async (input, output, projectDir, options) => {
|
|
|
172965
173023
|
for (const err of errors) {
|
|
172966
173024
|
const msg = err.message || JSON.stringify(err);
|
|
172967
173025
|
console.error(kleur_default.red(msg));
|
|
172968
|
-
|
|
173026
|
+
if (err.stack) {
|
|
173027
|
+
console.log(err.stack);
|
|
173028
|
+
}
|
|
172969
173029
|
}
|
|
172970
173030
|
}
|
|
172971
173031
|
if (errors.length > 0 && !options?.ignoreErrors) {
|
|
@@ -172992,7 +173052,7 @@ var logTsxExtensionHint = (error, entryFilePath) => {
|
|
|
172992
173052
|
const isAggregateError = error instanceof AggregateError || String(error).includes("AggregateError");
|
|
172993
173053
|
if (!isTsEntry || !isAggregateError)
|
|
172994
173054
|
return;
|
|
172995
|
-
const entryFileName =
|
|
173055
|
+
const entryFileName = path37.basename(entryFilePath);
|
|
172996
173056
|
console.error([
|
|
172997
173057
|
"",
|
|
172998
173058
|
`It looks like "${entryFileName}" is a ".ts" file. tscircuit component files must use the ".tsx" extension.`,
|
|
@@ -173007,7 +173067,7 @@ var logTypeReexportHint = (error, entryFilePath) => {
|
|
|
173007
173067
|
if (!match)
|
|
173008
173068
|
return;
|
|
173009
173069
|
const [, exportName, fromSpecifier] = match;
|
|
173010
|
-
const entryFileName =
|
|
173070
|
+
const entryFileName = path37.basename(entryFilePath);
|
|
173011
173071
|
console.error([
|
|
173012
173072
|
"",
|
|
173013
173073
|
`It looks like "${entryFileName}" re-exports the type-only symbol "${exportName}" from "${fromSpecifier}" without the "type" modifier.`,
|
|
@@ -173023,12 +173083,12 @@ var logTypeReexportHint = (error, entryFilePath) => {
|
|
|
173023
173083
|
import { execSync as execSync3 } from "node:child_process";
|
|
173024
173084
|
|
|
173025
173085
|
// lib/shared/install-project-dependencies.ts
|
|
173026
|
-
import
|
|
173027
|
-
import
|
|
173086
|
+
import fs39 from "node:fs";
|
|
173087
|
+
import path39 from "node:path";
|
|
173028
173088
|
|
|
173029
173089
|
// lib/shared/collect-tsci-dependencies.ts
|
|
173030
|
-
import
|
|
173031
|
-
import
|
|
173090
|
+
import fs38 from "node:fs";
|
|
173091
|
+
import path38 from "node:path";
|
|
173032
173092
|
var DEFAULT_PATTERNS = ["**/*.{ts,tsx,js,jsx}"];
|
|
173033
173093
|
var DEFAULT_IGNORES = [
|
|
173034
173094
|
"**/node_modules/**",
|
|
@@ -173043,7 +173103,7 @@ function collectTsciDependencies({
|
|
|
173043
173103
|
patterns = DEFAULT_PATTERNS,
|
|
173044
173104
|
ignore = DEFAULT_IGNORES
|
|
173045
173105
|
} = {}) {
|
|
173046
|
-
const searchRoot =
|
|
173106
|
+
const searchRoot = path38.resolve(cwd);
|
|
173047
173107
|
const files = globbySync(patterns, {
|
|
173048
173108
|
cwd: searchRoot,
|
|
173049
173109
|
absolute: true,
|
|
@@ -173053,7 +173113,7 @@ function collectTsciDependencies({
|
|
|
173053
173113
|
const dependencies2 = new Set;
|
|
173054
173114
|
for (const filePath of files) {
|
|
173055
173115
|
try {
|
|
173056
|
-
const fileContents =
|
|
173116
|
+
const fileContents = fs38.readFileSync(filePath, "utf-8");
|
|
173057
173117
|
let match;
|
|
173058
173118
|
while (true) {
|
|
173059
173119
|
match = IMPORT_PATTERN.exec(fileContents);
|
|
@@ -173071,26 +173131,26 @@ async function installProjectDependencies({
|
|
|
173071
173131
|
cwd = process.cwd(),
|
|
173072
173132
|
skipTscircuitPackage = false
|
|
173073
173133
|
} = {}) {
|
|
173074
|
-
const projectRoot =
|
|
173075
|
-
const packageJsonPath =
|
|
173076
|
-
const npmrcPath =
|
|
173134
|
+
const projectRoot = path39.resolve(cwd);
|
|
173135
|
+
const packageJsonPath = path39.join(projectRoot, "package.json");
|
|
173136
|
+
const npmrcPath = path39.join(projectRoot, ".npmrc");
|
|
173077
173137
|
const packageManager = getPackageManager();
|
|
173078
|
-
if (!
|
|
173138
|
+
if (!fs39.existsSync(projectRoot)) {
|
|
173079
173139
|
throw new Error(`Directory not found: ${projectRoot}`);
|
|
173080
173140
|
}
|
|
173081
173141
|
let packageJsonCreated = false;
|
|
173082
|
-
if (!
|
|
173142
|
+
if (!fs39.existsSync(packageJsonPath)) {
|
|
173083
173143
|
console.log("No package.json found. Generating a new one.");
|
|
173084
173144
|
generatePackageJson(projectRoot);
|
|
173085
173145
|
packageJsonCreated = true;
|
|
173086
173146
|
} else {
|
|
173087
173147
|
console.log("Found existing package.json.");
|
|
173088
173148
|
}
|
|
173089
|
-
if (!
|
|
173149
|
+
if (!fs39.existsSync(npmrcPath)) {
|
|
173090
173150
|
console.log("Creating .npmrc with tscircuit registry configuration.");
|
|
173091
|
-
|
|
173151
|
+
fs39.writeFileSync(npmrcPath, "@tsci:registry=https://npm.tscircuit.com");
|
|
173092
173152
|
}
|
|
173093
|
-
const packageJson = JSON.parse(
|
|
173153
|
+
const packageJson = JSON.parse(fs39.readFileSync(packageJsonPath, "utf-8"));
|
|
173094
173154
|
if (skipTscircuitPackage) {
|
|
173095
173155
|
const isTscircuitPackage = (name) => name === "tscircuit";
|
|
173096
173156
|
if (packageJson.dependencies) {
|
|
@@ -173123,7 +173183,7 @@ async function installProjectDependencies({
|
|
|
173123
173183
|
console.log("No @tsci dependencies detected in circuit files.");
|
|
173124
173184
|
}
|
|
173125
173185
|
}
|
|
173126
|
-
|
|
173186
|
+
fs39.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
173127
173187
|
`);
|
|
173128
173188
|
console.log(`Installing dependencies using ${kleur_default.bold(packageManager.name)}...`);
|
|
173129
173189
|
try {
|
|
@@ -173219,20 +173279,20 @@ var resolveBuildOptions = ({
|
|
|
173219
173279
|
};
|
|
173220
173280
|
|
|
173221
173281
|
// cli/build/get-build-entrypoints.ts
|
|
173222
|
-
import
|
|
173223
|
-
import
|
|
173282
|
+
import fs40 from "node:fs";
|
|
173283
|
+
import path40 from "node:path";
|
|
173224
173284
|
var isSubPath2 = (maybeChild, maybeParent) => {
|
|
173225
|
-
const relative10 =
|
|
173226
|
-
return relative10 === "" || !relative10.startsWith("..") && !
|
|
173285
|
+
const relative10 = path40.relative(maybeParent, maybeChild);
|
|
173286
|
+
return relative10 === "" || !relative10.startsWith("..") && !path40.isAbsolute(relative10);
|
|
173227
173287
|
};
|
|
173228
173288
|
var findProjectRoot = (startDir) => {
|
|
173229
173289
|
let currentDir = startDir;
|
|
173230
|
-
while (currentDir !==
|
|
173231
|
-
const packageJsonPath =
|
|
173232
|
-
if (
|
|
173290
|
+
while (currentDir !== path40.dirname(currentDir)) {
|
|
173291
|
+
const packageJsonPath = path40.join(currentDir, "package.json");
|
|
173292
|
+
if (fs40.existsSync(packageJsonPath)) {
|
|
173233
173293
|
return currentDir;
|
|
173234
173294
|
}
|
|
173235
|
-
currentDir =
|
|
173295
|
+
currentDir = path40.dirname(currentDir);
|
|
173236
173296
|
}
|
|
173237
173297
|
return startDir;
|
|
173238
173298
|
};
|
|
@@ -173241,12 +173301,12 @@ async function getBuildEntrypoints({
|
|
|
173241
173301
|
rootDir = process.cwd(),
|
|
173242
173302
|
includeBoardFiles = true
|
|
173243
173303
|
}) {
|
|
173244
|
-
const resolvedRoot =
|
|
173304
|
+
const resolvedRoot = path40.resolve(rootDir);
|
|
173245
173305
|
const includeBoardFilePatterns = includeBoardFiles ? getBoardFilePatterns(resolvedRoot) : [];
|
|
173246
173306
|
const buildFromProjectDir = async () => {
|
|
173247
173307
|
const projectConfig2 = loadProjectConfig(resolvedRoot);
|
|
173248
|
-
const resolvedPreviewComponentPath = projectConfig2?.previewComponentPath ?
|
|
173249
|
-
const resolvedSiteDefaultComponentPath = projectConfig2?.siteDefaultComponentPath ?
|
|
173308
|
+
const resolvedPreviewComponentPath = projectConfig2?.previewComponentPath ? path40.resolve(resolvedRoot, projectConfig2.previewComponentPath) : undefined;
|
|
173309
|
+
const resolvedSiteDefaultComponentPath = projectConfig2?.siteDefaultComponentPath ? path40.resolve(resolvedRoot, projectConfig2.siteDefaultComponentPath) : undefined;
|
|
173250
173310
|
if (includeBoardFiles) {
|
|
173251
173311
|
const files = findBoardFiles({ projectDir: resolvedRoot });
|
|
173252
173312
|
if (files.length > 0) {
|
|
@@ -173284,11 +173344,11 @@ async function getBuildEntrypoints({
|
|
|
173284
173344
|
};
|
|
173285
173345
|
};
|
|
173286
173346
|
if (fileOrDir) {
|
|
173287
|
-
const resolved =
|
|
173288
|
-
if (
|
|
173347
|
+
const resolved = path40.resolve(resolvedRoot, fileOrDir);
|
|
173348
|
+
if (fs40.existsSync(resolved) && fs40.statSync(resolved).isDirectory()) {
|
|
173289
173349
|
const projectConfig3 = loadProjectConfig(resolvedRoot);
|
|
173290
|
-
const resolvedPreviewComponentPath2 = projectConfig3?.previewComponentPath ?
|
|
173291
|
-
const resolvedSiteDefaultComponentPath2 = projectConfig3?.siteDefaultComponentPath ?
|
|
173350
|
+
const resolvedPreviewComponentPath2 = projectConfig3?.previewComponentPath ? path40.resolve(resolvedRoot, projectConfig3.previewComponentPath) : undefined;
|
|
173351
|
+
const resolvedSiteDefaultComponentPath2 = projectConfig3?.siteDefaultComponentPath ? path40.resolve(resolvedRoot, projectConfig3.siteDefaultComponentPath) : undefined;
|
|
173292
173352
|
if (includeBoardFiles) {
|
|
173293
173353
|
const circuitFiles = findBoardFiles({
|
|
173294
173354
|
projectDir: resolvedRoot,
|
|
@@ -173322,11 +173382,11 @@ async function getBuildEntrypoints({
|
|
|
173322
173382
|
circuitFiles: mainEntrypoint ? [mainEntrypoint] : []
|
|
173323
173383
|
};
|
|
173324
173384
|
}
|
|
173325
|
-
const fileDir =
|
|
173385
|
+
const fileDir = path40.dirname(resolved);
|
|
173326
173386
|
const projectDir = findProjectRoot(fileDir);
|
|
173327
173387
|
const projectConfig2 = loadProjectConfig(projectDir);
|
|
173328
|
-
const resolvedPreviewComponentPath = projectConfig2?.previewComponentPath ?
|
|
173329
|
-
const resolvedSiteDefaultComponentPath = projectConfig2?.siteDefaultComponentPath ?
|
|
173388
|
+
const resolvedPreviewComponentPath = projectConfig2?.previewComponentPath ? path40.resolve(projectDir, projectConfig2.previewComponentPath) : undefined;
|
|
173389
|
+
const resolvedSiteDefaultComponentPath = projectConfig2?.siteDefaultComponentPath ? path40.resolve(projectDir, projectConfig2.siteDefaultComponentPath) : undefined;
|
|
173330
173390
|
return {
|
|
173331
173391
|
projectDir,
|
|
173332
173392
|
previewComponentPath: resolvedPreviewComponentPath,
|
|
@@ -173373,8 +173433,8 @@ ${scriptBlock} <script src="https://cdn.tailwindcss.com"></script>
|
|
|
173373
173433
|
};
|
|
173374
173434
|
|
|
173375
173435
|
// cli/build/build-preview-images.ts
|
|
173376
|
-
import
|
|
173377
|
-
import
|
|
173436
|
+
import fs41 from "node:fs";
|
|
173437
|
+
import path41 from "node:path";
|
|
173378
173438
|
import {
|
|
173379
173439
|
convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg2,
|
|
173380
173440
|
convertCircuitJsonToSchematicSvg as convertCircuitJsonToSchematicSvg2
|
|
@@ -173450,21 +173510,21 @@ var generatePreviewAssets = async ({
|
|
|
173450
173510
|
outputDir,
|
|
173451
173511
|
distDir
|
|
173452
173512
|
}) => {
|
|
173453
|
-
const prefixRelative =
|
|
173513
|
+
const prefixRelative = path41.relative(distDir, outputDir) || ".";
|
|
173454
173514
|
const prefix = prefixRelative === "." ? "" : `[${prefixRelative}] `;
|
|
173455
173515
|
let circuitJson;
|
|
173456
173516
|
try {
|
|
173457
|
-
const circuitJsonRaw =
|
|
173517
|
+
const circuitJsonRaw = fs41.readFileSync(build.outputPath, "utf-8");
|
|
173458
173518
|
circuitJson = JSON.parse(circuitJsonRaw);
|
|
173459
173519
|
} catch (error) {
|
|
173460
173520
|
console.error(`${prefix}Failed to read circuit JSON:`, error);
|
|
173461
173521
|
return;
|
|
173462
173522
|
}
|
|
173463
|
-
|
|
173523
|
+
fs41.mkdirSync(outputDir, { recursive: true });
|
|
173464
173524
|
try {
|
|
173465
173525
|
console.log(`${prefix}Generating PCB SVG...`);
|
|
173466
173526
|
const pcbSvg = convertCircuitJsonToPcbSvg2(circuitJson);
|
|
173467
|
-
|
|
173527
|
+
fs41.writeFileSync(path41.join(outputDir, "pcb.svg"), pcbSvg, "utf-8");
|
|
173468
173528
|
console.log(`${prefix}Written pcb.svg`);
|
|
173469
173529
|
} catch (error) {
|
|
173470
173530
|
console.error(`${prefix}Failed to generate PCB SVG:`, error);
|
|
@@ -173472,7 +173532,7 @@ var generatePreviewAssets = async ({
|
|
|
173472
173532
|
try {
|
|
173473
173533
|
console.log(`${prefix}Generating schematic SVG...`);
|
|
173474
173534
|
const schematicSvg = convertCircuitJsonToSchematicSvg2(circuitJson);
|
|
173475
|
-
|
|
173535
|
+
fs41.writeFileSync(path41.join(outputDir, "schematic.svg"), schematicSvg, "utf-8");
|
|
173476
173536
|
console.log(`${prefix}Written schematic.svg`);
|
|
173477
173537
|
} catch (error) {
|
|
173478
173538
|
console.error(`${prefix}Failed to generate schematic SVG:`, error);
|
|
@@ -173489,7 +173549,7 @@ var generatePreviewAssets = async ({
|
|
|
173489
173549
|
camPos: [10, 10, 10],
|
|
173490
173550
|
lookAt: [0, 0, 0]
|
|
173491
173551
|
});
|
|
173492
|
-
|
|
173552
|
+
fs41.writeFileSync(path41.join(outputDir, "3d.png"), Buffer.from(normalizeToUint8Array(pngBuffer)));
|
|
173493
173553
|
console.log(`${prefix}Written 3d.png`);
|
|
173494
173554
|
} catch (error) {
|
|
173495
173555
|
console.error(`${prefix}Failed to generate 3D PNG:`, error);
|
|
@@ -173504,14 +173564,14 @@ var buildPreviewImages = async ({
|
|
|
173504
173564
|
}) => {
|
|
173505
173565
|
const successfulBuilds = builtFiles.filter((file) => file.ok);
|
|
173506
173566
|
const previewEntrypoint = previewComponentPath || mainEntrypoint;
|
|
173507
|
-
const resolvedPreviewEntrypoint = previewEntrypoint ?
|
|
173567
|
+
const resolvedPreviewEntrypoint = previewEntrypoint ? path41.resolve(previewEntrypoint) : undefined;
|
|
173508
173568
|
if (allImages) {
|
|
173509
173569
|
if (successfulBuilds.length === 0) {
|
|
173510
173570
|
console.warn("No successful build output available for preview image generation.");
|
|
173511
173571
|
return;
|
|
173512
173572
|
}
|
|
173513
173573
|
for (const build of successfulBuilds) {
|
|
173514
|
-
const outputDir =
|
|
173574
|
+
const outputDir = path41.dirname(build.outputPath);
|
|
173515
173575
|
await generatePreviewAssets({
|
|
173516
173576
|
build,
|
|
173517
173577
|
outputDir,
|
|
@@ -173522,7 +173582,7 @@ var buildPreviewImages = async ({
|
|
|
173522
173582
|
}
|
|
173523
173583
|
const previewBuild = (() => {
|
|
173524
173584
|
if (resolvedPreviewEntrypoint) {
|
|
173525
|
-
const match = successfulBuilds.find((built) =>
|
|
173585
|
+
const match = successfulBuilds.find((built) => path41.resolve(built.sourcePath) === resolvedPreviewEntrypoint);
|
|
173526
173586
|
if (match)
|
|
173527
173587
|
return match;
|
|
173528
173588
|
}
|
|
@@ -173540,8 +173600,8 @@ var buildPreviewImages = async ({
|
|
|
173540
173600
|
};
|
|
173541
173601
|
|
|
173542
173602
|
// cli/build/build-preview-gltf.ts
|
|
173543
|
-
import
|
|
173544
|
-
import
|
|
173603
|
+
import fs42 from "node:fs";
|
|
173604
|
+
import path42 from "node:path";
|
|
173545
173605
|
import { convertCircuitJsonToGltf as convertCircuitJsonToGltf3 } from "circuit-json-to-gltf";
|
|
173546
173606
|
var buildPreviewGltf = async ({
|
|
173547
173607
|
builtFiles,
|
|
@@ -173551,10 +173611,10 @@ var buildPreviewGltf = async ({
|
|
|
173551
173611
|
}) => {
|
|
173552
173612
|
const successfulBuilds = builtFiles.filter((file) => file.ok);
|
|
173553
173613
|
const previewEntrypoint = previewComponentPath || mainEntrypoint;
|
|
173554
|
-
const resolvedPreviewEntrypoint = previewEntrypoint ?
|
|
173614
|
+
const resolvedPreviewEntrypoint = previewEntrypoint ? path42.resolve(previewEntrypoint) : undefined;
|
|
173555
173615
|
const previewBuild = (() => {
|
|
173556
173616
|
if (resolvedPreviewEntrypoint) {
|
|
173557
|
-
const match = successfulBuilds.find((built) =>
|
|
173617
|
+
const match = successfulBuilds.find((built) => path42.resolve(built.sourcePath) === resolvedPreviewEntrypoint);
|
|
173558
173618
|
if (match)
|
|
173559
173619
|
return match;
|
|
173560
173620
|
}
|
|
@@ -173566,16 +173626,16 @@ var buildPreviewGltf = async ({
|
|
|
173566
173626
|
}
|
|
173567
173627
|
let circuitJson;
|
|
173568
173628
|
try {
|
|
173569
|
-
const circuitJsonRaw =
|
|
173629
|
+
const circuitJsonRaw = fs42.readFileSync(previewBuild.outputPath, "utf-8");
|
|
173570
173630
|
circuitJson = JSON.parse(circuitJsonRaw);
|
|
173571
173631
|
} catch (error) {
|
|
173572
173632
|
console.error("Failed to read circuit JSON:", error);
|
|
173573
173633
|
return;
|
|
173574
173634
|
}
|
|
173575
173635
|
const sourcePath = previewBuild.sourcePath;
|
|
173576
|
-
const sourceBasename =
|
|
173636
|
+
const sourceBasename = path42.basename(sourcePath);
|
|
173577
173637
|
const gltfFilename = sourceBasename.replace(/(\.(board|circuit))?\.tsx?$/, ".gltf");
|
|
173578
|
-
const outputPath =
|
|
173638
|
+
const outputPath = path42.join(distDir, gltfFilename);
|
|
173579
173639
|
try {
|
|
173580
173640
|
console.log("Converting circuit to GLTF...");
|
|
173581
173641
|
const circuitJsonWithFileUrls = convertModelUrlsToFileUrls(circuitJson);
|
|
@@ -173583,7 +173643,7 @@ var buildPreviewGltf = async ({
|
|
|
173583
173643
|
format: "gltf"
|
|
173584
173644
|
});
|
|
173585
173645
|
const gltfContent = JSON.stringify(gltfData, null, 2);
|
|
173586
|
-
|
|
173646
|
+
fs42.writeFileSync(outputPath, gltfContent, "utf-8");
|
|
173587
173647
|
console.log(`Written ${gltfFilename}`);
|
|
173588
173648
|
} catch (error) {
|
|
173589
173649
|
console.error("Failed to generate GLTF:", error);
|
|
@@ -173591,8 +173651,8 @@ var buildPreviewGltf = async ({
|
|
|
173591
173651
|
};
|
|
173592
173652
|
|
|
173593
173653
|
// cli/build/generate-kicad-project.ts
|
|
173594
|
-
import
|
|
173595
|
-
import
|
|
173654
|
+
import fs43 from "node:fs";
|
|
173655
|
+
import path43 from "node:path";
|
|
173596
173656
|
var createKicadProContent = ({
|
|
173597
173657
|
projectName,
|
|
173598
173658
|
schematicFileName,
|
|
@@ -173632,10 +173692,10 @@ var generateKicadProject = async ({
|
|
|
173632
173692
|
boardFileName
|
|
173633
173693
|
});
|
|
173634
173694
|
if (writeFiles) {
|
|
173635
|
-
|
|
173636
|
-
|
|
173637
|
-
|
|
173638
|
-
|
|
173695
|
+
fs43.mkdirSync(outputDir, { recursive: true });
|
|
173696
|
+
fs43.writeFileSync(path43.join(outputDir, schematicFileName), schContent);
|
|
173697
|
+
fs43.writeFileSync(path43.join(outputDir, boardFileName), pcbContent);
|
|
173698
|
+
fs43.writeFileSync(path43.join(outputDir, projectFileName), proContent);
|
|
173639
173699
|
}
|
|
173640
173700
|
return {
|
|
173641
173701
|
pcbContent,
|
|
@@ -173647,13 +173707,13 @@ var generateKicadProject = async ({
|
|
|
173647
173707
|
};
|
|
173648
173708
|
|
|
173649
173709
|
// cli/build/build-kicad-pcm.ts
|
|
173650
|
-
import
|
|
173651
|
-
import
|
|
173710
|
+
import path46 from "node:path";
|
|
173711
|
+
import fs46 from "node:fs";
|
|
173652
173712
|
|
|
173653
173713
|
// lib/shared/generate-pcm-assets.ts
|
|
173654
173714
|
var import_jszip3 = __toESM2(require_lib4(), 1);
|
|
173655
|
-
import
|
|
173656
|
-
import
|
|
173715
|
+
import fs44 from "node:fs";
|
|
173716
|
+
import path44 from "node:path";
|
|
173657
173717
|
import crypto3 from "node:crypto";
|
|
173658
173718
|
async function generatePcmAssets(options) {
|
|
173659
173719
|
const {
|
|
@@ -173669,7 +173729,7 @@ async function generatePcmAssets(options) {
|
|
|
173669
173729
|
displayName = `${author}/${packageName}`
|
|
173670
173730
|
} = options;
|
|
173671
173731
|
const identifier = `com.tscircuit.${author}.${packageName}`.toLowerCase().replace(/[^a-z0-9.-]/g, "-").slice(0, 50);
|
|
173672
|
-
|
|
173732
|
+
fs44.mkdirSync(outputDir, { recursive: true });
|
|
173673
173733
|
console.log("Creating metadata.json...");
|
|
173674
173734
|
const metadata = {
|
|
173675
173735
|
$schema: "https://go.kicad.org/pcm/schemas/v1",
|
|
@@ -173695,13 +173755,13 @@ async function generatePcmAssets(options) {
|
|
|
173695
173755
|
]
|
|
173696
173756
|
};
|
|
173697
173757
|
const zipFileName = `${identifier}-${version2}.zip`;
|
|
173698
|
-
const zipFilePath =
|
|
173758
|
+
const zipFilePath = path44.join(outputDir, zipFileName);
|
|
173699
173759
|
await createPcmZip({
|
|
173700
173760
|
kicadLibraryPath,
|
|
173701
173761
|
metadata,
|
|
173702
173762
|
outputPath: zipFilePath
|
|
173703
173763
|
});
|
|
173704
|
-
const zipBuffer =
|
|
173764
|
+
const zipBuffer = fs44.readFileSync(zipFilePath);
|
|
173705
173765
|
const sha256 = crypto3.createHash("sha256").update(zipBuffer).digest("hex");
|
|
173706
173766
|
const zipSize = zipBuffer.length;
|
|
173707
173767
|
const downloadUrl = baseUrl ? `${baseUrl}/pcm/${zipFileName}` : `./${zipFileName}`;
|
|
@@ -173735,9 +173795,9 @@ async function generatePcmAssets(options) {
|
|
|
173735
173795
|
}
|
|
173736
173796
|
]
|
|
173737
173797
|
};
|
|
173738
|
-
const packagesJsonPath =
|
|
173739
|
-
|
|
173740
|
-
const packagesJsonBuffer =
|
|
173798
|
+
const packagesJsonPath = path44.join(outputDir, "packages.json");
|
|
173799
|
+
fs44.writeFileSync(packagesJsonPath, JSON.stringify(packagesJson, null, 2));
|
|
173800
|
+
const packagesJsonBuffer = fs44.readFileSync(packagesJsonPath);
|
|
173741
173801
|
const packagesJsonSha256 = crypto3.createHash("sha256").update(packagesJsonBuffer).digest("hex");
|
|
173742
173802
|
const packagesJsonUrl = baseUrl ? `${baseUrl}/pcm/packages.json` : "./packages.json";
|
|
173743
173803
|
const repositoryJson = {
|
|
@@ -173755,8 +173815,8 @@ async function generatePcmAssets(options) {
|
|
|
173755
173815
|
update_timestamp: Math.floor(Date.now() / 1000)
|
|
173756
173816
|
}
|
|
173757
173817
|
};
|
|
173758
|
-
const repositoryJsonPath =
|
|
173759
|
-
|
|
173818
|
+
const repositoryJsonPath = path44.join(outputDir, "repository.json");
|
|
173819
|
+
fs44.writeFileSync(repositoryJsonPath, JSON.stringify(repositoryJson, null, 2));
|
|
173760
173820
|
return {
|
|
173761
173821
|
outputDir,
|
|
173762
173822
|
repositoryJsonPath,
|
|
@@ -173768,14 +173828,14 @@ async function generatePcmAssets(options) {
|
|
|
173768
173828
|
}
|
|
173769
173829
|
function addDirectoryToZip(opts) {
|
|
173770
173830
|
const { zip, dirPath, zipPath } = opts;
|
|
173771
|
-
const entries =
|
|
173831
|
+
const entries = fs44.readdirSync(dirPath, { withFileTypes: true });
|
|
173772
173832
|
for (const entry of entries) {
|
|
173773
|
-
const fullPath =
|
|
173833
|
+
const fullPath = path44.join(dirPath, entry.name);
|
|
173774
173834
|
const entryZipPath = zipPath ? `${zipPath}/${entry.name}` : entry.name;
|
|
173775
173835
|
if (entry.isDirectory()) {
|
|
173776
173836
|
addDirectoryToZip({ zip, dirPath: fullPath, zipPath: entryZipPath });
|
|
173777
173837
|
} else {
|
|
173778
|
-
const content =
|
|
173838
|
+
const content = fs44.readFileSync(fullPath);
|
|
173779
173839
|
zip.file(entryZipPath, content);
|
|
173780
173840
|
}
|
|
173781
173841
|
}
|
|
@@ -173784,18 +173844,18 @@ async function createPcmZip(options) {
|
|
|
173784
173844
|
const { kicadLibraryPath, metadata, outputPath } = options;
|
|
173785
173845
|
const zip = new import_jszip3.default;
|
|
173786
173846
|
zip.file("metadata.json", JSON.stringify(metadata, null, 2));
|
|
173787
|
-
const footprintsDir =
|
|
173788
|
-
if (
|
|
173847
|
+
const footprintsDir = path44.join(kicadLibraryPath, "footprints");
|
|
173848
|
+
if (fs44.existsSync(footprintsDir)) {
|
|
173789
173849
|
console.log("Adding footprints directory...");
|
|
173790
173850
|
addDirectoryToZip({ zip, dirPath: footprintsDir, zipPath: "footprints" });
|
|
173791
173851
|
}
|
|
173792
|
-
const symbolsDir =
|
|
173793
|
-
if (
|
|
173852
|
+
const symbolsDir = path44.join(kicadLibraryPath, "symbols");
|
|
173853
|
+
if (fs44.existsSync(symbolsDir)) {
|
|
173794
173854
|
console.log("Adding symbols directory...");
|
|
173795
173855
|
addDirectoryToZip({ zip, dirPath: symbolsDir, zipPath: "symbols" });
|
|
173796
173856
|
}
|
|
173797
|
-
const modelsDir =
|
|
173798
|
-
if (
|
|
173857
|
+
const modelsDir = path44.join(kicadLibraryPath, "3dmodels");
|
|
173858
|
+
if (fs44.existsSync(modelsDir)) {
|
|
173799
173859
|
console.log("Adding 3dmodels directory...");
|
|
173800
173860
|
addDirectoryToZip({ zip, dirPath: modelsDir, zipPath: "3dmodels" });
|
|
173801
173861
|
}
|
|
@@ -173805,12 +173865,12 @@ async function createPcmZip(options) {
|
|
|
173805
173865
|
compression: "DEFLATE",
|
|
173806
173866
|
compressionOptions: { level: 9 }
|
|
173807
173867
|
});
|
|
173808
|
-
|
|
173868
|
+
fs44.writeFileSync(outputPath, zipBuffer);
|
|
173809
173869
|
}
|
|
173810
173870
|
|
|
173811
173871
|
// lib/utils/resolve-kicad-library-name.ts
|
|
173812
|
-
import
|
|
173813
|
-
import
|
|
173872
|
+
import path45 from "node:path";
|
|
173873
|
+
import fs45 from "node:fs";
|
|
173814
173874
|
function resolveKicadLibraryName({
|
|
173815
173875
|
projectDir
|
|
173816
173876
|
}) {
|
|
@@ -173818,9 +173878,9 @@ function resolveKicadLibraryName({
|
|
|
173818
173878
|
if (projectConfig2?.kicadLibraryName) {
|
|
173819
173879
|
return projectConfig2.kicadLibraryName;
|
|
173820
173880
|
}
|
|
173821
|
-
const packageJsonPath =
|
|
173822
|
-
if (
|
|
173823
|
-
const packageJson = JSON.parse(
|
|
173881
|
+
const packageJsonPath = path45.join(projectDir, "package.json");
|
|
173882
|
+
if (fs45.existsSync(packageJsonPath)) {
|
|
173883
|
+
const packageJson = JSON.parse(fs45.readFileSync(packageJsonPath, "utf-8"));
|
|
173824
173884
|
const unscopedName = getUnscopedPackageName(packageJson.name || "");
|
|
173825
173885
|
if (unscopedName) {
|
|
173826
173886
|
return unscopedName.replace("@tsci/", "").replace(/\./g, "-");
|
|
@@ -173835,18 +173895,18 @@ async function buildKicadPcm({
|
|
|
173835
173895
|
projectDir,
|
|
173836
173896
|
distDir
|
|
173837
173897
|
}) {
|
|
173838
|
-
const packageJsonPath =
|
|
173839
|
-
if (!
|
|
173898
|
+
const packageJsonPath = path46.join(projectDir, "package.json");
|
|
173899
|
+
if (!fs46.existsSync(packageJsonPath)) {
|
|
173840
173900
|
throw new Error("No package.json found for KiCad PCM generation");
|
|
173841
173901
|
}
|
|
173842
|
-
const packageJson = JSON.parse(
|
|
173902
|
+
const packageJson = JSON.parse(fs46.readFileSync(packageJsonPath, "utf-8"));
|
|
173843
173903
|
const projectConfig2 = loadProjectConfig(projectDir);
|
|
173844
|
-
const packageName = packageJson.name?.split("/").pop()?.split(".").pop() ||
|
|
173904
|
+
const packageName = packageJson.name?.split("/").pop()?.split(".").pop() || path46.basename(projectDir);
|
|
173845
173905
|
const version2 = packageJson.version || "1.0.0";
|
|
173846
173906
|
const author = getPackageAuthor(packageJson.name || "") || "tscircuit";
|
|
173847
173907
|
const description = packageJson.description || "";
|
|
173848
173908
|
const libraryName = resolveKicadLibraryName({ projectDir });
|
|
173849
|
-
const kicadLibOutputDir =
|
|
173909
|
+
const kicadLibOutputDir = path46.join(distDir, "kicad-library");
|
|
173850
173910
|
const kicadPcmPackageId = `com_tscircuit_${author}_${packageName}`.replace(/\./g, "_");
|
|
173851
173911
|
console.log("Converting to KiCad library for PCM...");
|
|
173852
173912
|
await convertToKicadLibrary({
|
|
@@ -173856,7 +173916,7 @@ async function buildKicadPcm({
|
|
|
173856
173916
|
isPcm: true,
|
|
173857
173917
|
kicadPcmPackageId
|
|
173858
173918
|
});
|
|
173859
|
-
const pcmOutputDir =
|
|
173919
|
+
const pcmOutputDir = path46.join(distDir, "pcm");
|
|
173860
173920
|
const envDeploymentUrl = process.env.TSCIRCUIT_DEPLOYMENT_URL?.replace(/\/+$/, "");
|
|
173861
173921
|
const baseUrl = envDeploymentUrl ?? `https://${author}--${packageName}.tscircuit.app`;
|
|
173862
173922
|
console.log("Generating PCM assets...");
|
|
@@ -173870,13 +173930,13 @@ async function buildKicadPcm({
|
|
|
173870
173930
|
baseUrl,
|
|
173871
173931
|
displayName: projectConfig2?.kicadLibraryName || undefined
|
|
173872
173932
|
});
|
|
173873
|
-
console.log(` KiCad PCM assets generated at ${kleur_default.dim(
|
|
173933
|
+
console.log(` KiCad PCM assets generated at ${kleur_default.dim(path46.relative(process.cwd(), pcmOutputDir))}`);
|
|
173874
173934
|
console.log(` Repository URL: ${kleur_default.cyan(`${baseUrl}/pcm/repository.json`)}`);
|
|
173875
173935
|
}
|
|
173876
173936
|
|
|
173877
173937
|
// cli/build/transpile/index.ts
|
|
173878
|
-
import
|
|
173879
|
-
import
|
|
173938
|
+
import path48 from "node:path";
|
|
173939
|
+
import fs48 from "node:fs";
|
|
173880
173940
|
import { rollup } from "rollup";
|
|
173881
173941
|
import typescript from "@rollup/plugin-typescript";
|
|
173882
173942
|
import resolve11 from "@rollup/plugin-node-resolve";
|
|
@@ -173885,11 +173945,11 @@ import json from "@rollup/plugin-json";
|
|
|
173885
173945
|
import dts from "rollup-plugin-dts";
|
|
173886
173946
|
|
|
173887
173947
|
// cli/build/transpile/static-asset-plugin.ts
|
|
173888
|
-
import
|
|
173889
|
-
import
|
|
173948
|
+
import fs47 from "node:fs";
|
|
173949
|
+
import path47 from "node:path";
|
|
173890
173950
|
import { createHash } from "node:crypto";
|
|
173891
173951
|
function normalizePathSeparators(filePath) {
|
|
173892
|
-
return filePath.split(
|
|
173952
|
+
return filePath.split(path47.sep).join("/");
|
|
173893
173953
|
}
|
|
173894
173954
|
var STATIC_ASSET_EXTENSIONS = new Set([
|
|
173895
173955
|
".glb",
|
|
@@ -173920,24 +173980,24 @@ var createStaticAssetPlugin = ({
|
|
|
173920
173980
|
return {
|
|
173921
173981
|
name: "tsci-static-assets",
|
|
173922
173982
|
resolveId(source, importer) {
|
|
173923
|
-
const ext =
|
|
173983
|
+
const ext = path47.extname(source).toLowerCase();
|
|
173924
173984
|
if (!STATIC_ASSET_EXTENSIONS.has(ext))
|
|
173925
173985
|
return null;
|
|
173926
|
-
if (
|
|
173927
|
-
return
|
|
173986
|
+
if (path47.isAbsolute(source)) {
|
|
173987
|
+
return fs47.existsSync(source) ? { id: normalizePathSeparators(source), external: true } : null;
|
|
173928
173988
|
}
|
|
173929
173989
|
if (importer) {
|
|
173930
|
-
const importerNative = importer.split("/").join(
|
|
173931
|
-
const resolvedFromImporter =
|
|
173932
|
-
if (
|
|
173990
|
+
const importerNative = importer.split("/").join(path47.sep);
|
|
173991
|
+
const resolvedFromImporter = path47.resolve(path47.dirname(importerNative), source);
|
|
173992
|
+
if (fs47.existsSync(resolvedFromImporter)) {
|
|
173933
173993
|
return {
|
|
173934
173994
|
id: normalizePathSeparators(resolvedFromImporter),
|
|
173935
173995
|
external: true
|
|
173936
173996
|
};
|
|
173937
173997
|
}
|
|
173938
173998
|
}
|
|
173939
|
-
const resolvedFromProject =
|
|
173940
|
-
if (
|
|
173999
|
+
const resolvedFromProject = path47.resolve(resolvedBaseUrl, source);
|
|
174000
|
+
if (fs47.existsSync(resolvedFromProject)) {
|
|
173941
174001
|
return {
|
|
173942
174002
|
id: normalizePathSeparators(resolvedFromProject),
|
|
173943
174003
|
external: true
|
|
@@ -173950,8 +174010,8 @@ var createStaticAssetPlugin = ({
|
|
|
173950
174010
|
const wildcard = isWildcard ? source.slice(patternPrefix.length) : "";
|
|
173951
174011
|
for (const target of targets) {
|
|
173952
174012
|
const targetPath = isWildcard ? target.replace("*", wildcard) : target;
|
|
173953
|
-
const resolvedTarget =
|
|
173954
|
-
if (
|
|
174013
|
+
const resolvedTarget = path47.resolve(resolvedBaseUrl, targetPath);
|
|
174014
|
+
if (fs47.existsSync(resolvedTarget)) {
|
|
173955
174015
|
return {
|
|
173956
174016
|
id: normalizePathSeparators(resolvedTarget),
|
|
173957
174017
|
external: true
|
|
@@ -173977,18 +174037,18 @@ var createStaticAssetPlugin = ({
|
|
|
173977
174037
|
if (chunk.type !== "chunk")
|
|
173978
174038
|
continue;
|
|
173979
174039
|
for (const importedId of chunk.imports) {
|
|
173980
|
-
const ext =
|
|
174040
|
+
const ext = path47.extname(importedId).toLowerCase();
|
|
173981
174041
|
if (!STATIC_ASSET_EXTENSIONS.has(ext))
|
|
173982
174042
|
continue;
|
|
173983
174043
|
if (!copiedAssets.has(importedId)) {
|
|
173984
|
-
const assetDir =
|
|
173985
|
-
|
|
173986
|
-
const nativePath = importedId.split("/").join(
|
|
173987
|
-
const fileBuffer =
|
|
174044
|
+
const assetDir = path47.join(outputDir, "assets");
|
|
174045
|
+
fs47.mkdirSync(assetDir, { recursive: true });
|
|
174046
|
+
const nativePath = importedId.split("/").join(path47.sep);
|
|
174047
|
+
const fileBuffer = fs47.readFileSync(nativePath);
|
|
173988
174048
|
const hash = createHash("sha1").update(fileBuffer).digest("hex").slice(0, 8);
|
|
173989
|
-
const fileName = `${
|
|
173990
|
-
const outputFilePath =
|
|
173991
|
-
|
|
174049
|
+
const fileName = `${path47.basename(importedId, ext)}-${hash}${ext}`;
|
|
174050
|
+
const outputFilePath = path47.join(assetDir, fileName);
|
|
174051
|
+
fs47.writeFileSync(outputFilePath, fileBuffer);
|
|
173992
174052
|
copiedAssets.set(importedId, `./assets/${fileName}`);
|
|
173993
174053
|
assetIdToOutputPath.set(importedId, `./assets/${fileName}`);
|
|
173994
174054
|
}
|
|
@@ -174010,17 +174070,17 @@ function escapeRegExp(string) {
|
|
|
174010
174070
|
|
|
174011
174071
|
// cli/build/transpile/index.ts
|
|
174012
174072
|
var createExternalFunction = (projectDir, tsconfigPath) => (id) => {
|
|
174013
|
-
if (id.startsWith(".") || id.startsWith("/") ||
|
|
174073
|
+
if (id.startsWith(".") || id.startsWith("/") || path48.isAbsolute(id)) {
|
|
174014
174074
|
return false;
|
|
174015
174075
|
}
|
|
174016
174076
|
let baseUrl = projectDir;
|
|
174017
174077
|
let pathMappings = {};
|
|
174018
|
-
if (tsconfigPath &&
|
|
174078
|
+
if (tsconfigPath && fs48.existsSync(tsconfigPath)) {
|
|
174019
174079
|
try {
|
|
174020
|
-
const tsconfigContent =
|
|
174080
|
+
const tsconfigContent = fs48.readFileSync(tsconfigPath, "utf-8");
|
|
174021
174081
|
const tsconfig = JSON.parse(tsconfigContent);
|
|
174022
174082
|
if (tsconfig.compilerOptions?.baseUrl) {
|
|
174023
|
-
baseUrl =
|
|
174083
|
+
baseUrl = path48.resolve(path48.dirname(tsconfigPath), tsconfig.compilerOptions.baseUrl);
|
|
174024
174084
|
}
|
|
174025
174085
|
if (tsconfig.compilerOptions?.paths) {
|
|
174026
174086
|
pathMappings = tsconfig.compilerOptions.paths;
|
|
@@ -174034,17 +174094,17 @@ var createExternalFunction = (projectDir, tsconfigPath) => (id) => {
|
|
|
174034
174094
|
}
|
|
174035
174095
|
}
|
|
174036
174096
|
const potentialPaths = [
|
|
174037
|
-
|
|
174038
|
-
|
|
174039
|
-
|
|
174040
|
-
|
|
174041
|
-
|
|
174042
|
-
|
|
174043
|
-
|
|
174044
|
-
|
|
174045
|
-
|
|
174097
|
+
path48.join(baseUrl, id),
|
|
174098
|
+
path48.join(baseUrl, `${id}.ts`),
|
|
174099
|
+
path48.join(baseUrl, `${id}.tsx`),
|
|
174100
|
+
path48.join(baseUrl, `${id}.js`),
|
|
174101
|
+
path48.join(baseUrl, `${id}.jsx`),
|
|
174102
|
+
path48.join(baseUrl, id, "index.ts"),
|
|
174103
|
+
path48.join(baseUrl, id, "index.tsx"),
|
|
174104
|
+
path48.join(baseUrl, id, "index.js"),
|
|
174105
|
+
path48.join(baseUrl, id, "index.jsx")
|
|
174046
174106
|
];
|
|
174047
|
-
if (potentialPaths.some((p4) =>
|
|
174107
|
+
if (potentialPaths.some((p4) => fs48.existsSync(p4))) {
|
|
174048
174108
|
return false;
|
|
174049
174109
|
}
|
|
174050
174110
|
return true;
|
|
@@ -174055,17 +174115,17 @@ var transpileFile = async ({
|
|
|
174055
174115
|
projectDir
|
|
174056
174116
|
}) => {
|
|
174057
174117
|
try {
|
|
174058
|
-
|
|
174059
|
-
const tsconfigPath =
|
|
174060
|
-
const hasTsConfig =
|
|
174118
|
+
fs48.mkdirSync(outputDir, { recursive: true });
|
|
174119
|
+
const tsconfigPath = path48.join(projectDir, "tsconfig.json");
|
|
174120
|
+
const hasTsConfig = fs48.existsSync(tsconfigPath);
|
|
174061
174121
|
let tsconfigBaseUrl = projectDir;
|
|
174062
174122
|
let tsconfigPathMappings;
|
|
174063
174123
|
if (hasTsConfig) {
|
|
174064
174124
|
try {
|
|
174065
|
-
const tsconfigContent =
|
|
174125
|
+
const tsconfigContent = fs48.readFileSync(tsconfigPath, "utf-8");
|
|
174066
174126
|
const tsconfig = JSON.parse(tsconfigContent);
|
|
174067
174127
|
if (tsconfig.compilerOptions?.baseUrl) {
|
|
174068
|
-
tsconfigBaseUrl =
|
|
174128
|
+
tsconfigBaseUrl = path48.resolve(path48.dirname(tsconfigPath), tsconfig.compilerOptions.baseUrl);
|
|
174069
174129
|
}
|
|
174070
174130
|
if (tsconfig.compilerOptions?.paths) {
|
|
174071
174131
|
tsconfigPathMappings = tsconfig.compilerOptions.paths;
|
|
@@ -174120,27 +174180,27 @@ var transpileFile = async ({
|
|
|
174120
174180
|
external: createExternalFunction(projectDir, hasTsConfig ? tsconfigPath : undefined),
|
|
174121
174181
|
plugins: getPlugins()
|
|
174122
174182
|
});
|
|
174123
|
-
const esmOutputPath =
|
|
174183
|
+
const esmOutputPath = path48.join(outputDir, "index.js");
|
|
174124
174184
|
await esmBundle.write({
|
|
174125
174185
|
file: esmOutputPath,
|
|
174126
174186
|
format: "es",
|
|
174127
174187
|
sourcemap: false
|
|
174128
174188
|
});
|
|
174129
|
-
console.log(`ESM bundle written to ${
|
|
174189
|
+
console.log(`ESM bundle written to ${path48.relative(projectDir, esmOutputPath)}`);
|
|
174130
174190
|
console.log("Building CommonJS bundle...");
|
|
174131
174191
|
const cjsBundle = await rollup({
|
|
174132
174192
|
input,
|
|
174133
174193
|
external: createExternalFunction(projectDir, hasTsConfig ? tsconfigPath : undefined),
|
|
174134
174194
|
plugins: getPlugins()
|
|
174135
174195
|
});
|
|
174136
|
-
const cjsOutputPath =
|
|
174196
|
+
const cjsOutputPath = path48.join(outputDir, "index.cjs");
|
|
174137
174197
|
console.log("Writing CJS bundle to:", cjsOutputPath);
|
|
174138
174198
|
await cjsBundle.write({
|
|
174139
174199
|
file: cjsOutputPath,
|
|
174140
174200
|
format: "cjs",
|
|
174141
174201
|
sourcemap: false
|
|
174142
174202
|
});
|
|
174143
|
-
console.log(`CommonJS bundle written to ${
|
|
174203
|
+
console.log(`CommonJS bundle written to ${path48.relative(projectDir, cjsOutputPath)}`);
|
|
174144
174204
|
console.log("Generating type declarations...");
|
|
174145
174205
|
const dtsBundle = await rollup({
|
|
174146
174206
|
input,
|
|
@@ -174165,9 +174225,9 @@ var transpileFile = async ({
|
|
|
174165
174225
|
dtsContent = dtsContent.replace(/import \* as [\w_]+ from ['"]react\/jsx-runtime['"];?\s*\n?/g, "");
|
|
174166
174226
|
dtsContent = dtsContent.replace(/[\w_]+\.JSX\.Element/g, "any");
|
|
174167
174227
|
dtsContent = dtsContent.replace(/export\s*{\s*};\s*$/gm, "").trim();
|
|
174168
|
-
const dtsOutputPath =
|
|
174169
|
-
|
|
174170
|
-
console.log(`Type declarations written to ${
|
|
174228
|
+
const dtsOutputPath = path48.join(outputDir, "index.d.ts");
|
|
174229
|
+
fs48.writeFileSync(dtsOutputPath, dtsContent);
|
|
174230
|
+
console.log(`Type declarations written to ${path48.relative(projectDir, dtsOutputPath)}`);
|
|
174171
174231
|
console.log(kleur_default.green("Transpilation complete!"));
|
|
174172
174232
|
return true;
|
|
174173
174233
|
} catch (err) {
|
|
@@ -174180,17 +174240,17 @@ var transpileFile = async ({
|
|
|
174180
174240
|
};
|
|
174181
174241
|
|
|
174182
174242
|
// cli/utils/validate-main-in-dist.ts
|
|
174183
|
-
import
|
|
174184
|
-
import
|
|
174243
|
+
import fs49 from "node:fs";
|
|
174244
|
+
import path49 from "node:path";
|
|
174185
174245
|
var validateMainInDist = (projectDir, distDir) => {
|
|
174186
|
-
const packageJsonPath =
|
|
174187
|
-
if (!
|
|
174246
|
+
const packageJsonPath = path49.join(projectDir, "package.json");
|
|
174247
|
+
if (!fs49.existsSync(packageJsonPath))
|
|
174188
174248
|
return;
|
|
174189
|
-
const packageJson = JSON.parse(
|
|
174249
|
+
const packageJson = JSON.parse(fs49.readFileSync(packageJsonPath, "utf-8"));
|
|
174190
174250
|
if (typeof packageJson.main !== "string")
|
|
174191
174251
|
return;
|
|
174192
|
-
const resolvedMainPath =
|
|
174193
|
-
const isMainInDist = resolvedMainPath === distDir || resolvedMainPath.startsWith(`${distDir}${
|
|
174252
|
+
const resolvedMainPath = path49.resolve(projectDir, packageJson.main);
|
|
174253
|
+
const isMainInDist = resolvedMainPath === distDir || resolvedMainPath.startsWith(`${distDir}${path49.sep}`);
|
|
174194
174254
|
if (!isMainInDist) {
|
|
174195
174255
|
console.warn('When using transpilation, your package\'s "main" field should point inside the `dist/*` directory, usually to "dist/index.js"');
|
|
174196
174256
|
}
|
|
@@ -174212,19 +174272,19 @@ async function getLatestTscircuitCdnUrl() {
|
|
|
174212
174272
|
}
|
|
174213
174273
|
|
|
174214
174274
|
// cli/build/worker-pool.ts
|
|
174215
|
-
import
|
|
174216
|
-
import
|
|
174275
|
+
import path50 from "node:path";
|
|
174276
|
+
import fs50 from "node:fs";
|
|
174217
174277
|
import { Worker } from "node:worker_threads";
|
|
174218
174278
|
var getWorkerEntrypointPath = () => {
|
|
174219
|
-
const tsPath =
|
|
174220
|
-
if (
|
|
174279
|
+
const tsPath = path50.join(import.meta.dir, "build-worker-entrypoint.ts");
|
|
174280
|
+
if (fs50.existsSync(tsPath)) {
|
|
174221
174281
|
return tsPath;
|
|
174222
174282
|
}
|
|
174223
|
-
const jsBundledPath =
|
|
174224
|
-
if (
|
|
174283
|
+
const jsBundledPath = path50.join(import.meta.dir, "build", "build-worker-entrypoint.js");
|
|
174284
|
+
if (fs50.existsSync(jsBundledPath)) {
|
|
174225
174285
|
return jsBundledPath;
|
|
174226
174286
|
}
|
|
174227
|
-
return
|
|
174287
|
+
return path50.join(import.meta.dir, "build-worker-entrypoint.js");
|
|
174228
174288
|
};
|
|
174229
174289
|
|
|
174230
174290
|
class WorkerPool {
|
|
@@ -174288,7 +174348,9 @@ class WorkerPool {
|
|
|
174288
174348
|
threadWorker.busy = false;
|
|
174289
174349
|
}
|
|
174290
174350
|
if (this.onLog) {
|
|
174291
|
-
this.onLog([
|
|
174351
|
+
this.onLog([
|
|
174352
|
+
`Worker error: ${error instanceof Error ? error.message : String(error)}`
|
|
174353
|
+
]);
|
|
174292
174354
|
}
|
|
174293
174355
|
});
|
|
174294
174356
|
threadWorker.worker.on("exit", (code) => {
|
|
@@ -174380,23 +174442,23 @@ async function buildFilesWithWorkerPool(options) {
|
|
|
174380
174442
|
}
|
|
174381
174443
|
|
|
174382
174444
|
// cli/build/register.ts
|
|
174383
|
-
var normalizeRelativePath = (projectDir, targetPath) =>
|
|
174445
|
+
var normalizeRelativePath = (projectDir, targetPath) => path51.relative(projectDir, targetPath).split(path51.sep).join("/");
|
|
174384
174446
|
var registerBuild = (program3) => {
|
|
174385
174447
|
program3.command("build").description("Run tscircuit eval and output circuit json").argument("[file]", "Path to the entry file").option("--ci", "Run install and optional prebuild/build commands (or default CI build)").option("--ignore-errors", "Do not exit with code 1 on errors").option("--ignore-warnings", "Do not log warnings").option("--disable-pcb", "Disable PCB outputs").option("--disable-parts-engine", "Disable the parts engine").option("--site", "Generate a static site in the dist directory").option("--transpile", "Transpile the entry file to JavaScript").option("--preview-images", "Generate preview images in the dist directory").option("--all-images", "Generate preview images for every successful build output").option("--kicad", "Generate KiCad project directories for each successful build output").option("--kicad-library", "Generate KiCad library in dist/kicad-library").option("--preview-gltf", "Generate a GLTF file from the preview entrypoint").option("--kicad-pcm", "Generate KiCad PCM (Plugin and Content Manager) assets in dist/pcm").option("--use-cdn-javascript", "Use CDN-hosted JavaScript instead of bundled standalone file for --site").option("--concurrency <number>", "Number of files to build in parallel (default: 1)", "1").action(async (file, options) => {
|
|
174386
174448
|
try {
|
|
174387
|
-
const resolvedRoot =
|
|
174449
|
+
const resolvedRoot = path51.resolve(process.cwd());
|
|
174388
174450
|
let projectDir;
|
|
174389
174451
|
if (file) {
|
|
174390
|
-
const resolved =
|
|
174391
|
-
if (
|
|
174452
|
+
const resolved = path51.resolve(resolvedRoot, file);
|
|
174453
|
+
if (fs51.existsSync(resolved) && fs51.statSync(resolved).isDirectory()) {
|
|
174392
174454
|
projectDir = resolvedRoot;
|
|
174393
174455
|
} else {
|
|
174394
|
-
let currentDir =
|
|
174395
|
-
while (currentDir !==
|
|
174396
|
-
if (
|
|
174456
|
+
let currentDir = path51.dirname(resolved);
|
|
174457
|
+
while (currentDir !== path51.dirname(currentDir)) {
|
|
174458
|
+
if (fs51.existsSync(path51.join(currentDir, "package.json"))) {
|
|
174397
174459
|
break;
|
|
174398
174460
|
}
|
|
174399
|
-
currentDir =
|
|
174461
|
+
currentDir = path51.dirname(currentDir);
|
|
174400
174462
|
}
|
|
174401
174463
|
projectDir = currentDir;
|
|
174402
174464
|
}
|
|
@@ -174436,8 +174498,8 @@ var registerBuild = (program3) => {
|
|
|
174436
174498
|
}
|
|
174437
174499
|
return config;
|
|
174438
174500
|
})();
|
|
174439
|
-
const distDir =
|
|
174440
|
-
|
|
174501
|
+
const distDir = path51.join(projectDir, "dist");
|
|
174502
|
+
fs51.mkdirSync(distDir, { recursive: true });
|
|
174441
174503
|
const concurrencyValue = Math.max(1, Number.parseInt(resolvedOptions?.concurrency || "1", 10));
|
|
174442
174504
|
if (concurrencyValue > 1) {
|
|
174443
174505
|
console.log(`Building ${circuitFiles.length} file(s) with concurrency ${concurrencyValue}...`);
|
|
@@ -174455,7 +174517,7 @@ var registerBuild = (program3) => {
|
|
|
174455
174517
|
platformConfig: platformConfig2
|
|
174456
174518
|
};
|
|
174457
174519
|
const processBuildResult = async (filePath, outputPath, buildOutcome) => {
|
|
174458
|
-
const relative10 =
|
|
174520
|
+
const relative10 = path51.relative(projectDir, filePath);
|
|
174459
174521
|
const outputDirName = relative10.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
174460
174522
|
builtFiles.push({
|
|
174461
174523
|
sourcePath: filePath,
|
|
@@ -174465,9 +174527,9 @@ var registerBuild = (program3) => {
|
|
|
174465
174527
|
if (!buildOutcome.ok) {
|
|
174466
174528
|
hasErrors = true;
|
|
174467
174529
|
} else if (resolvedOptions?.site) {
|
|
174468
|
-
const normalizedSourcePath = relative10.split(
|
|
174469
|
-
const relativeOutputPath =
|
|
174470
|
-
const normalizedOutputPath = relativeOutputPath.split(
|
|
174530
|
+
const normalizedSourcePath = relative10.split(path51.sep).join("/");
|
|
174531
|
+
const relativeOutputPath = path51.join(outputDirName, "circuit.json");
|
|
174532
|
+
const normalizedOutputPath = relativeOutputPath.split(path51.sep).join("/");
|
|
174471
174533
|
staticFileReferences.push({
|
|
174472
174534
|
filePath: normalizedSourcePath,
|
|
174473
174535
|
fileStaticAssetUrl: `./${normalizedOutputPath}`
|
|
@@ -174475,12 +174537,12 @@ var registerBuild = (program3) => {
|
|
|
174475
174537
|
}
|
|
174476
174538
|
if (buildOutcome.ok && shouldGenerateKicad) {
|
|
174477
174539
|
let circuitJson = buildOutcome.circuitJson;
|
|
174478
|
-
if (!circuitJson &&
|
|
174479
|
-
circuitJson = JSON.parse(
|
|
174540
|
+
if (!circuitJson && fs51.existsSync(outputPath)) {
|
|
174541
|
+
circuitJson = JSON.parse(fs51.readFileSync(outputPath, "utf-8"));
|
|
174480
174542
|
}
|
|
174481
174543
|
if (circuitJson) {
|
|
174482
|
-
const projectOutputDir =
|
|
174483
|
-
const projectName =
|
|
174544
|
+
const projectOutputDir = path51.join(distDir, outputDirName, "kicad");
|
|
174545
|
+
const projectName = path51.basename(outputDirName);
|
|
174484
174546
|
const project = await generateKicadProject({
|
|
174485
174547
|
circuitJson,
|
|
174486
174548
|
outputDir: projectOutputDir,
|
|
@@ -174496,19 +174558,19 @@ var registerBuild = (program3) => {
|
|
|
174496
174558
|
};
|
|
174497
174559
|
const buildSequentially = async () => {
|
|
174498
174560
|
for (const filePath of circuitFiles) {
|
|
174499
|
-
const relative10 =
|
|
174561
|
+
const relative10 = path51.relative(projectDir, filePath);
|
|
174500
174562
|
console.log(`Building ${relative10}...`);
|
|
174501
174563
|
const outputDirName = relative10.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
174502
|
-
const outputPath =
|
|
174564
|
+
const outputPath = path51.join(distDir, outputDirName, "circuit.json");
|
|
174503
174565
|
const buildOutcome = await buildFile(filePath, outputPath, projectDir, buildOptions);
|
|
174504
174566
|
await processBuildResult(filePath, outputPath, buildOutcome);
|
|
174505
174567
|
}
|
|
174506
174568
|
};
|
|
174507
174569
|
const buildWithWorkers = async () => {
|
|
174508
174570
|
const filesToBuild = circuitFiles.map((filePath) => {
|
|
174509
|
-
const relative10 =
|
|
174571
|
+
const relative10 = path51.relative(projectDir, filePath);
|
|
174510
174572
|
const outputDirName = relative10.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
174511
|
-
const outputPath =
|
|
174573
|
+
const outputPath = path51.join(distDir, outputDirName, "circuit.json");
|
|
174512
174574
|
return { filePath, outputPath };
|
|
174513
174575
|
});
|
|
174514
174576
|
await buildFilesWithWorkerPool({
|
|
@@ -174522,7 +174584,7 @@ var registerBuild = (program3) => {
|
|
|
174522
174584
|
}
|
|
174523
174585
|
},
|
|
174524
174586
|
onJobComplete: async (result) => {
|
|
174525
|
-
const relative10 =
|
|
174587
|
+
const relative10 = path51.relative(projectDir, result.filePath);
|
|
174526
174588
|
if (result.ok) {
|
|
174527
174589
|
console.log(kleur_default.green(`✓ ${relative10}`));
|
|
174528
174590
|
} else {
|
|
@@ -174592,14 +174654,14 @@ var registerBuild = (program3) => {
|
|
|
174592
174654
|
if (resolvedOptions?.useCdnJavascript) {
|
|
174593
174655
|
standaloneScriptSrc = await getLatestTscircuitCdnUrl();
|
|
174594
174656
|
} else {
|
|
174595
|
-
|
|
174657
|
+
fs51.writeFileSync(path51.join(distDir, "standalone.min.js"), standalone_min_default);
|
|
174596
174658
|
}
|
|
174597
174659
|
const indexHtml = getStaticIndexHtmlFile({
|
|
174598
174660
|
files: staticFileReferences,
|
|
174599
174661
|
standaloneScriptSrc,
|
|
174600
174662
|
defaultMainComponentPath: siteDefaultComponentPath ? normalizeRelativePath(projectDir, siteDefaultComponentPath) : undefined
|
|
174601
174663
|
});
|
|
174602
|
-
|
|
174664
|
+
fs51.writeFileSync(path51.join(distDir, "index.html"), indexHtml);
|
|
174603
174665
|
}
|
|
174604
174666
|
if (resolvedOptions?.kicadLibrary) {
|
|
174605
174667
|
console.log("Generating KiCad library...");
|
|
@@ -174619,14 +174681,14 @@ var registerBuild = (program3) => {
|
|
|
174619
174681
|
}
|
|
174620
174682
|
} else {
|
|
174621
174683
|
const libraryName = resolveKicadLibraryName({ projectDir });
|
|
174622
|
-
const kicadLibOutputDir =
|
|
174684
|
+
const kicadLibOutputDir = path51.join(distDir, "kicad-library");
|
|
174623
174685
|
try {
|
|
174624
174686
|
await convertToKicadLibrary({
|
|
174625
174687
|
filePath: entryFile,
|
|
174626
174688
|
libraryName,
|
|
174627
174689
|
outputDir: kicadLibOutputDir
|
|
174628
174690
|
});
|
|
174629
|
-
console.log(` KiCad library generated at ${kleur_default.dim(
|
|
174691
|
+
console.log(` KiCad library generated at ${kleur_default.dim(path51.relative(process.cwd(), kicadLibOutputDir))}`);
|
|
174630
174692
|
} catch (err) {
|
|
174631
174693
|
console.error(`Error generating KiCad library: ${err instanceof Error ? err.message : err}`);
|
|
174632
174694
|
if (!resolvedOptions?.ignoreErrors) {
|
|
@@ -174687,7 +174749,7 @@ var registerBuild = (program3) => {
|
|
|
174687
174749
|
if (configAppliedOpts.length > 0) {
|
|
174688
174750
|
console.log(` Config ${kleur_default.magenta(configAppliedOpts.join(", "))} ${kleur_default.dim("(from tscircuit.config.json)")}`);
|
|
174689
174751
|
}
|
|
174690
|
-
console.log(` Output ${kleur_default.dim(
|
|
174752
|
+
console.log(` Output ${kleur_default.dim(path51.relative(process.cwd(), distDir) || "dist")}`);
|
|
174691
174753
|
console.log(hasErrors ? kleur_default.yellow(`
|
|
174692
174754
|
⚠ Build completed with errors`) : kleur_default.green(`
|
|
174693
174755
|
✓ Done`));
|
|
@@ -174701,8 +174763,8 @@ var registerBuild = (program3) => {
|
|
|
174701
174763
|
};
|
|
174702
174764
|
|
|
174703
174765
|
// lib/shared/snapshot-project.ts
|
|
174704
|
-
import
|
|
174705
|
-
import
|
|
174766
|
+
import fs53 from "node:fs";
|
|
174767
|
+
import path52 from "node:path";
|
|
174706
174768
|
import looksSame2 from "looks-same";
|
|
174707
174769
|
import {
|
|
174708
174770
|
convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg3,
|
|
@@ -174713,7 +174775,7 @@ import { renderGLTFToPNGBufferFromGLBBuffer as renderGLTFToPNGBufferFromGLBBuffe
|
|
|
174713
174775
|
|
|
174714
174776
|
// lib/shared/compare-images.ts
|
|
174715
174777
|
import looksSame from "looks-same";
|
|
174716
|
-
import
|
|
174778
|
+
import fs52 from "node:fs/promises";
|
|
174717
174779
|
var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
174718
174780
|
const { equal: equal2 } = await looksSame(buffer1, buffer2, {
|
|
174719
174781
|
strict: false,
|
|
@@ -174729,7 +174791,7 @@ var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
|
174729
174791
|
tolerance: 2
|
|
174730
174792
|
});
|
|
174731
174793
|
} else {
|
|
174732
|
-
await
|
|
174794
|
+
await fs52.writeFile(diffPath, buffer2);
|
|
174733
174795
|
}
|
|
174734
174796
|
}
|
|
174735
174797
|
return { equal: equal2 };
|
|
@@ -174754,7 +174816,7 @@ var snapshotProject = async ({
|
|
|
174754
174816
|
...DEFAULT_IGNORED_PATTERNS,
|
|
174755
174817
|
...ignored.map(normalizeIgnorePattern)
|
|
174756
174818
|
];
|
|
174757
|
-
const resolvedPaths = filePaths.map((f2) =>
|
|
174819
|
+
const resolvedPaths = filePaths.map((f2) => path52.resolve(projectDir, f2));
|
|
174758
174820
|
const boardFiles = findBoardFiles({
|
|
174759
174821
|
projectDir,
|
|
174760
174822
|
ignore,
|
|
@@ -174768,7 +174830,7 @@ var snapshotProject = async ({
|
|
|
174768
174830
|
const mismatches = [];
|
|
174769
174831
|
let didUpdate = false;
|
|
174770
174832
|
for (const file of boardFiles) {
|
|
174771
|
-
const relativeFilePath =
|
|
174833
|
+
const relativeFilePath = path52.relative(projectDir, file);
|
|
174772
174834
|
let circuitJson;
|
|
174773
174835
|
let pcbSvg;
|
|
174774
174836
|
let schSvg;
|
|
@@ -174823,17 +174885,17 @@ var snapshotProject = async ({
|
|
|
174823
174885
|
} catch (error) {
|
|
174824
174886
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
174825
174887
|
if (errorMessage.includes("No pcb_board found in circuit JSON")) {
|
|
174826
|
-
const fileDir =
|
|
174827
|
-
const relativeDir =
|
|
174828
|
-
const snapDir2 = snapshotsDirName ?
|
|
174829
|
-
const base2 =
|
|
174830
|
-
const snap3dPath =
|
|
174831
|
-
const existing3dSnapshot =
|
|
174888
|
+
const fileDir = path52.dirname(file);
|
|
174889
|
+
const relativeDir = path52.relative(projectDir, fileDir);
|
|
174890
|
+
const snapDir2 = snapshotsDirName ? path52.join(projectDir, snapshotsDirName, relativeDir) : path52.join(fileDir, "__snapshots__");
|
|
174891
|
+
const base2 = path52.basename(file).replace(/\.tsx$/, "");
|
|
174892
|
+
const snap3dPath = path52.join(snapDir2, `${base2}-3d.snap.png`);
|
|
174893
|
+
const existing3dSnapshot = fs53.existsSync(snap3dPath);
|
|
174832
174894
|
if (existing3dSnapshot) {
|
|
174833
174895
|
onError(kleur_default.red(`
|
|
174834
174896
|
❌ Failed to generate 3D snapshot for ${relativeFilePath}:
|
|
174835
174897
|
`) + kleur_default.red(` No pcb_board found in circuit JSON
|
|
174836
|
-
`) + kleur_default.red(` Existing snapshot: ${
|
|
174898
|
+
`) + kleur_default.red(` Existing snapshot: ${path52.relative(projectDir, snap3dPath)}
|
|
174837
174899
|
`));
|
|
174838
174900
|
return onExit2(1);
|
|
174839
174901
|
} else {
|
|
@@ -174849,9 +174911,9 @@ var snapshotProject = async ({
|
|
|
174849
174911
|
}
|
|
174850
174912
|
}
|
|
174851
174913
|
}
|
|
174852
|
-
const snapDir = snapshotsDirName ?
|
|
174853
|
-
|
|
174854
|
-
const base =
|
|
174914
|
+
const snapDir = snapshotsDirName ? path52.join(projectDir, snapshotsDirName, path52.relative(projectDir, path52.dirname(file))) : path52.join(path52.dirname(file), "__snapshots__");
|
|
174915
|
+
fs53.mkdirSync(snapDir, { recursive: true });
|
|
174916
|
+
const base = path52.basename(file).replace(/\.tsx$/, "");
|
|
174855
174917
|
const snapshots = [];
|
|
174856
174918
|
if (pcbOnly || !schematicOnly) {
|
|
174857
174919
|
snapshots.push({ type: "pcb", content: pcbSvg, isBinary: false });
|
|
@@ -174869,31 +174931,31 @@ var snapshotProject = async ({
|
|
|
174869
174931
|
for (const snapshot of snapshots) {
|
|
174870
174932
|
const { type } = snapshot;
|
|
174871
174933
|
const is3d = type === "3d";
|
|
174872
|
-
const snapPath =
|
|
174873
|
-
const existing =
|
|
174934
|
+
const snapPath = path52.join(snapDir, `${base}-${type}.snap.${is3d ? "png" : "svg"}`);
|
|
174935
|
+
const existing = fs53.existsSync(snapPath);
|
|
174874
174936
|
const newContentBuffer = snapshot.isBinary ? snapshot.content : Buffer.from(snapshot.content, "utf8");
|
|
174875
174937
|
const newContentForFile = snapshot.content;
|
|
174876
174938
|
if (!existing) {
|
|
174877
|
-
|
|
174878
|
-
console.log("✅", kleur_default.gray(
|
|
174939
|
+
fs53.writeFileSync(snapPath, newContentForFile);
|
|
174940
|
+
console.log("✅", kleur_default.gray(path52.relative(projectDir, snapPath)));
|
|
174879
174941
|
didUpdate = true;
|
|
174880
174942
|
continue;
|
|
174881
174943
|
}
|
|
174882
|
-
const oldContentBuffer =
|
|
174944
|
+
const oldContentBuffer = fs53.readFileSync(snapPath);
|
|
174883
174945
|
const diffPath = snapPath.replace(is3d ? ".snap.png" : ".snap.svg", is3d ? ".diff.png" : ".diff.svg");
|
|
174884
174946
|
const { equal: equal2 } = await compareAndCreateDiff(oldContentBuffer, newContentBuffer, diffPath);
|
|
174885
174947
|
if (update) {
|
|
174886
174948
|
if (!forceUpdate && equal2) {
|
|
174887
|
-
console.log("✅", kleur_default.gray(
|
|
174949
|
+
console.log("✅", kleur_default.gray(path52.relative(projectDir, snapPath)));
|
|
174888
174950
|
} else {
|
|
174889
|
-
|
|
174890
|
-
console.log("✅", kleur_default.gray(
|
|
174951
|
+
fs53.writeFileSync(snapPath, newContentForFile);
|
|
174952
|
+
console.log("✅", kleur_default.gray(path52.relative(projectDir, snapPath)));
|
|
174891
174953
|
didUpdate = true;
|
|
174892
174954
|
}
|
|
174893
174955
|
} else if (!equal2) {
|
|
174894
174956
|
mismatches.push(`${snapPath} (diff: ${diffPath})`);
|
|
174895
174957
|
} else {
|
|
174896
|
-
console.log("✅", kleur_default.gray(
|
|
174958
|
+
console.log("✅", kleur_default.gray(path52.relative(projectDir, snapPath)));
|
|
174897
174959
|
}
|
|
174898
174960
|
}
|
|
174899
174961
|
}
|
|
@@ -174932,22 +174994,22 @@ var registerSnapshot = (program3) => {
|
|
|
174932
174994
|
};
|
|
174933
174995
|
|
|
174934
174996
|
// lib/shared/setup-github-actions.ts
|
|
174935
|
-
import
|
|
174936
|
-
import
|
|
174997
|
+
import fs54 from "node:fs";
|
|
174998
|
+
import path53 from "node:path";
|
|
174937
174999
|
var setupGithubActions = (projectDir = process.cwd()) => {
|
|
174938
175000
|
const findGitRoot = (startDir) => {
|
|
174939
|
-
let dir =
|
|
174940
|
-
while (dir !==
|
|
174941
|
-
if (
|
|
175001
|
+
let dir = path53.resolve(startDir);
|
|
175002
|
+
while (dir !== path53.parse(dir).root) {
|
|
175003
|
+
if (fs54.existsSync(path53.join(dir, ".git"))) {
|
|
174942
175004
|
return dir;
|
|
174943
175005
|
}
|
|
174944
|
-
dir =
|
|
175006
|
+
dir = path53.dirname(dir);
|
|
174945
175007
|
}
|
|
174946
175008
|
return null;
|
|
174947
175009
|
};
|
|
174948
175010
|
const gitRoot = findGitRoot(projectDir) ?? projectDir;
|
|
174949
|
-
const workflowsDir =
|
|
174950
|
-
|
|
175011
|
+
const workflowsDir = path53.join(gitRoot, ".github", "workflows");
|
|
175012
|
+
fs54.mkdirSync(workflowsDir, { recursive: true });
|
|
174951
175013
|
const buildWorkflow = `name: tscircuit Build
|
|
174952
175014
|
|
|
174953
175015
|
on:
|
|
@@ -174986,8 +175048,8 @@ jobs:
|
|
|
174986
175048
|
- run: bun install
|
|
174987
175049
|
- run: bunx tsci snapshot
|
|
174988
175050
|
`;
|
|
174989
|
-
writeFileIfNotExists(
|
|
174990
|
-
writeFileIfNotExists(
|
|
175051
|
+
writeFileIfNotExists(path53.join(workflowsDir, "tscircuit-build.yml"), buildWorkflow);
|
|
175052
|
+
writeFileIfNotExists(path53.join(workflowsDir, "tscircuit-snapshot.yml"), snapshotWorkflow);
|
|
174991
175053
|
};
|
|
174992
175054
|
|
|
174993
175055
|
// cli/setup/register.ts
|
|
@@ -175025,8 +175087,8 @@ function registerAuthSetupNpmrc(program3) {
|
|
|
175025
175087
|
}
|
|
175026
175088
|
|
|
175027
175089
|
// cli/convert/register.ts
|
|
175028
|
-
import
|
|
175029
|
-
import
|
|
175090
|
+
import fs55 from "node:fs/promises";
|
|
175091
|
+
import path54 from "node:path";
|
|
175030
175092
|
import { parseKicadModToCircuitJson } from "kicad-component-converter";
|
|
175031
175093
|
|
|
175032
175094
|
// node_modules/@tscircuit/mm/dist/index.js
|
|
@@ -175147,15 +175209,15 @@ var convertCircuitJsonToTscircuit = (circuitJson, opts) => {
|
|
|
175147
175209
|
var registerConvert = (program3) => {
|
|
175148
175210
|
program3.command("convert").description("Convert a .kicad_mod footprint to a tscircuit component").argument("<file>", "Path to the .kicad_mod file").option("-o, --output <path>", "Output TSX file path").option("-n, --name <component>", "Component name for export").action(async (file, options) => {
|
|
175149
175211
|
try {
|
|
175150
|
-
const inputPath =
|
|
175151
|
-
const modContent = await
|
|
175212
|
+
const inputPath = path54.resolve(file);
|
|
175213
|
+
const modContent = await fs55.readFile(inputPath, "utf-8");
|
|
175152
175214
|
const circuitJson = await parseKicadModToCircuitJson(modContent);
|
|
175153
|
-
const componentName = options.name ??
|
|
175215
|
+
const componentName = options.name ?? path54.basename(inputPath, ".kicad_mod");
|
|
175154
175216
|
const tsx = convertCircuitJsonToTscircuit(circuitJson, {
|
|
175155
175217
|
componentName
|
|
175156
175218
|
});
|
|
175157
|
-
const outputPath = options.output ?
|
|
175158
|
-
await
|
|
175219
|
+
const outputPath = options.output ? path54.resolve(options.output) : path54.join(path54.dirname(inputPath), `${componentName}.tsx`);
|
|
175220
|
+
await fs55.writeFile(outputPath, tsx);
|
|
175159
175221
|
console.log(kleur_default.green(`Converted ${outputPath}`));
|
|
175160
175222
|
} catch (error) {
|
|
175161
175223
|
console.error(kleur_default.red("Failed to convert footprint:"), error instanceof Error ? error.message : error);
|
|
@@ -175271,7 +175333,7 @@ var registerInstall = (program3) => {
|
|
|
175271
175333
|
};
|
|
175272
175334
|
|
|
175273
175335
|
// cli/transpile/register.ts
|
|
175274
|
-
import
|
|
175336
|
+
import path55 from "node:path";
|
|
175275
175337
|
var registerTranspile = (program3) => {
|
|
175276
175338
|
program3.command("transpile").description("Transpile TypeScript/TSX to JavaScript (ESM, CommonJS, and type declarations)").argument("[file]", "Path to the entry file").action(async (file) => {
|
|
175277
175339
|
try {
|
|
@@ -175279,7 +175341,7 @@ var registerTranspile = (program3) => {
|
|
|
175279
175341
|
fileOrDir: file,
|
|
175280
175342
|
includeBoardFiles: false
|
|
175281
175343
|
});
|
|
175282
|
-
const distDir =
|
|
175344
|
+
const distDir = path55.join(projectDir, "dist");
|
|
175283
175345
|
validateMainInDist(projectDir, distDir);
|
|
175284
175346
|
console.log("Transpiling entry file...");
|
|
175285
175347
|
const entryFile = mainEntrypoint || circuitFiles[0];
|
|
@@ -175307,6 +175369,8 @@ var registerTranspile = (program3) => {
|
|
|
175307
175369
|
};
|
|
175308
175370
|
|
|
175309
175371
|
// lib/shared/register-static-asset-loaders.ts
|
|
175372
|
+
import fs56 from "node:fs";
|
|
175373
|
+
import path56 from "node:path";
|
|
175310
175374
|
var TEXT_STATIC_ASSET_EXTENSIONS = [
|
|
175311
175375
|
".gltf",
|
|
175312
175376
|
".step",
|
|
@@ -175317,17 +175381,34 @@ var TEXT_STATIC_ASSET_EXTENSIONS = [
|
|
|
175317
175381
|
];
|
|
175318
175382
|
var staticAssetFilter = new RegExp(`(${TEXT_STATIC_ASSET_EXTENSIONS.map((ext) => ext.replace(".", "\\.")).join("|")})$`, "i");
|
|
175319
175383
|
var registered = false;
|
|
175384
|
+
var getBaseUrlFromTsConfig = () => {
|
|
175385
|
+
const tsconfigPath = path56.join(process.cwd(), "tsconfig.json");
|
|
175386
|
+
try {
|
|
175387
|
+
if (!fs56.existsSync(tsconfigPath)) {
|
|
175388
|
+
return null;
|
|
175389
|
+
}
|
|
175390
|
+
const tsconfigContent = fs56.readFileSync(tsconfigPath, "utf-8");
|
|
175391
|
+
const tsconfig = JSON.parse(tsconfigContent);
|
|
175392
|
+
if (tsconfig.compilerOptions?.baseUrl) {
|
|
175393
|
+
return tsconfig.compilerOptions.baseUrl;
|
|
175394
|
+
}
|
|
175395
|
+
} catch {}
|
|
175396
|
+
return null;
|
|
175397
|
+
};
|
|
175320
175398
|
var registerStaticAssetLoaders = () => {
|
|
175321
175399
|
if (registered)
|
|
175322
175400
|
return;
|
|
175323
175401
|
registered = true;
|
|
175324
175402
|
if (typeof Bun !== "undefined" && typeof Bun.plugin === "function") {
|
|
175403
|
+
const baseUrl = getBaseUrlFromTsConfig();
|
|
175325
175404
|
Bun.plugin({
|
|
175326
175405
|
name: "tsci-static-assets",
|
|
175327
175406
|
setup(build) {
|
|
175328
175407
|
build.onLoad({ filter: staticAssetFilter }, (args) => {
|
|
175408
|
+
const baseDir = baseUrl ? path56.resolve(process.cwd(), baseUrl) : process.cwd();
|
|
175409
|
+
const relativePath = path56.relative(baseDir, args.path).split(path56.sep).join("/");
|
|
175329
175410
|
return {
|
|
175330
|
-
contents: `export default ${JSON.stringify(
|
|
175411
|
+
contents: `export default ${JSON.stringify(`./${relativePath}`)};`,
|
|
175331
175412
|
loader: "js"
|
|
175332
175413
|
};
|
|
175333
175414
|
});
|