circuitscript 0.1.24 → 0.1.25
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/cjs/helpers.js +25 -19
- package/dist/esm/helpers.js +25 -19
- package/dist/types/helpers.d.ts +4 -2
- package/package.json +1 -1
package/dist/cjs/helpers.js
CHANGED
|
@@ -160,15 +160,34 @@ async function validateScript(filePath, scriptData, options) {
|
|
|
160
160
|
return visitorResolver;
|
|
161
161
|
}
|
|
162
162
|
exports.validateScript = validateScript;
|
|
163
|
+
async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks) {
|
|
164
|
+
const { inputPath = null, updateSource = false, saveAnnotatedCopy = undefined, } = options;
|
|
165
|
+
if (inputPath && (updateSource || saveAnnotatedCopy !== undefined)) {
|
|
166
|
+
const refdesVisitor = new RefdesAnnotationVisitor_js_1.RefdesAnnotationVisitor(true, scriptData, tokens, componentLinks);
|
|
167
|
+
await refdesVisitor.visitAsync(tree);
|
|
168
|
+
let usePath = inputPath;
|
|
169
|
+
if (saveAnnotatedCopy === true) {
|
|
170
|
+
const dir = path_1.default.dirname(inputPath);
|
|
171
|
+
const ext = path_1.default.extname(inputPath);
|
|
172
|
+
const basename = path_1.default.basename(inputPath, ext);
|
|
173
|
+
usePath = path_1.default.join(dir, `${basename}.annotated${ext}`);
|
|
174
|
+
}
|
|
175
|
+
else if (typeof saveAnnotatedCopy === 'string') {
|
|
176
|
+
usePath = saveAnnotatedCopy;
|
|
177
|
+
}
|
|
178
|
+
console.log('Annotations saved to ' + usePath);
|
|
179
|
+
(0, fs_1.writeFileSync)(usePath, refdesVisitor.getOutput());
|
|
180
|
+
}
|
|
181
|
+
}
|
|
163
182
|
async function renderScript(scriptData, outputPath, options) {
|
|
164
183
|
const parseHandlers = [
|
|
165
184
|
new KiCadNetListOutputHandler(),
|
|
166
185
|
];
|
|
167
|
-
return renderScriptCustom(scriptData, outputPath, options, parseHandlers);
|
|
186
|
+
return renderScriptCustom(scriptData, outputPath, options, parseHandlers, [DefaultPostAnnotationCallback]);
|
|
168
187
|
}
|
|
169
188
|
exports.renderScript = renderScript;
|
|
170
|
-
async function renderScriptCustom(scriptData, outputPath, options, parseHandlers) {
|
|
171
|
-
const { dumpNets = false, dumpData = false, showStats = false, enableErc = false, enableBom = false, bomOutputPath = undefined, environment
|
|
189
|
+
async function renderScriptCustom(scriptData, outputPath, options, parseHandlers, postAnnotationCallbacks) {
|
|
190
|
+
const { dumpNets = false, dumpData = false, showStats = false, enableErc = false, enableBom = false, bomOutputPath = undefined, environment } = options;
|
|
172
191
|
const errors = [];
|
|
173
192
|
const onErrorHandler = (message, context, error) => {
|
|
174
193
|
if (error && error instanceof utils_js_1.RuntimeExecutionError) {
|
|
@@ -222,22 +241,9 @@ async function renderScriptCustom(scriptData, outputPath, options, parseHandlers
|
|
|
222
241
|
catch (err) {
|
|
223
242
|
throw new utils_js_1.RenderError(`Error during component annotation: ${err}`, 'annotation');
|
|
224
243
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
await refdesVisitor.visitAsync(tree);
|
|
229
|
-
let usePath = inputPath;
|
|
230
|
-
if (saveAnnotatedCopy === true) {
|
|
231
|
-
const dir = path_1.default.dirname(inputPath);
|
|
232
|
-
const ext = path_1.default.extname(inputPath);
|
|
233
|
-
const basename = path_1.default.basename(inputPath, ext);
|
|
234
|
-
usePath = path_1.default.join(dir, `${basename}.annotated${ext}`);
|
|
235
|
-
}
|
|
236
|
-
else if (typeof saveAnnotatedCopy === 'string') {
|
|
237
|
-
usePath = saveAnnotatedCopy;
|
|
238
|
-
}
|
|
239
|
-
console.log('Annotations saved to ' + usePath);
|
|
240
|
-
(0, fs_1.writeFileSync)(usePath, refdesVisitor.getOutput());
|
|
244
|
+
const componentLinks = visitor.getComponentCtxLinks();
|
|
245
|
+
for (let i = 0; i < postAnnotationCallbacks.length; i++) {
|
|
246
|
+
await postAnnotationCallbacks[i](options, scriptData, tree, tokens, componentLinks);
|
|
241
247
|
}
|
|
242
248
|
if (dumpNets) {
|
|
243
249
|
const nets = visitor.dumpNets();
|
package/dist/esm/helpers.js
CHANGED
|
@@ -150,14 +150,33 @@ export async function validateScript(filePath, scriptData, options) {
|
|
|
150
150
|
await visitorResolver.visitAsync(tree);
|
|
151
151
|
return visitorResolver;
|
|
152
152
|
}
|
|
153
|
+
async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks) {
|
|
154
|
+
const { inputPath = null, updateSource = false, saveAnnotatedCopy = undefined, } = options;
|
|
155
|
+
if (inputPath && (updateSource || saveAnnotatedCopy !== undefined)) {
|
|
156
|
+
const refdesVisitor = new RefdesAnnotationVisitor(true, scriptData, tokens, componentLinks);
|
|
157
|
+
await refdesVisitor.visitAsync(tree);
|
|
158
|
+
let usePath = inputPath;
|
|
159
|
+
if (saveAnnotatedCopy === true) {
|
|
160
|
+
const dir = path.dirname(inputPath);
|
|
161
|
+
const ext = path.extname(inputPath);
|
|
162
|
+
const basename = path.basename(inputPath, ext);
|
|
163
|
+
usePath = path.join(dir, `${basename}.annotated${ext}`);
|
|
164
|
+
}
|
|
165
|
+
else if (typeof saveAnnotatedCopy === 'string') {
|
|
166
|
+
usePath = saveAnnotatedCopy;
|
|
167
|
+
}
|
|
168
|
+
console.log('Annotations saved to ' + usePath);
|
|
169
|
+
writeFileSync(usePath, refdesVisitor.getOutput());
|
|
170
|
+
}
|
|
171
|
+
}
|
|
153
172
|
export async function renderScript(scriptData, outputPath, options) {
|
|
154
173
|
const parseHandlers = [
|
|
155
174
|
new KiCadNetListOutputHandler(),
|
|
156
175
|
];
|
|
157
|
-
return renderScriptCustom(scriptData, outputPath, options, parseHandlers);
|
|
176
|
+
return renderScriptCustom(scriptData, outputPath, options, parseHandlers, [DefaultPostAnnotationCallback]);
|
|
158
177
|
}
|
|
159
|
-
export async function renderScriptCustom(scriptData, outputPath, options, parseHandlers) {
|
|
160
|
-
const { dumpNets = false, dumpData = false, showStats = false, enableErc = false, enableBom = false, bomOutputPath = undefined, environment
|
|
178
|
+
export async function renderScriptCustom(scriptData, outputPath, options, parseHandlers, postAnnotationCallbacks) {
|
|
179
|
+
const { dumpNets = false, dumpData = false, showStats = false, enableErc = false, enableBom = false, bomOutputPath = undefined, environment } = options;
|
|
161
180
|
const errors = [];
|
|
162
181
|
const onErrorHandler = (message, context, error) => {
|
|
163
182
|
if (error && error instanceof RuntimeExecutionError) {
|
|
@@ -211,22 +230,9 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
|
|
|
211
230
|
catch (err) {
|
|
212
231
|
throw new RenderError(`Error during component annotation: ${err}`, 'annotation');
|
|
213
232
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
await refdesVisitor.visitAsync(tree);
|
|
218
|
-
let usePath = inputPath;
|
|
219
|
-
if (saveAnnotatedCopy === true) {
|
|
220
|
-
const dir = path.dirname(inputPath);
|
|
221
|
-
const ext = path.extname(inputPath);
|
|
222
|
-
const basename = path.basename(inputPath, ext);
|
|
223
|
-
usePath = path.join(dir, `${basename}.annotated${ext}`);
|
|
224
|
-
}
|
|
225
|
-
else if (typeof saveAnnotatedCopy === 'string') {
|
|
226
|
-
usePath = saveAnnotatedCopy;
|
|
227
|
-
}
|
|
228
|
-
console.log('Annotations saved to ' + usePath);
|
|
229
|
-
writeFileSync(usePath, refdesVisitor.getOutput());
|
|
233
|
+
const componentLinks = visitor.getComponentCtxLinks();
|
|
234
|
+
for (let i = 0; i < postAnnotationCallbacks.length; i++) {
|
|
235
|
+
await postAnnotationCallbacks[i](options, scriptData, tree, tokens, componentLinks);
|
|
230
236
|
}
|
|
231
237
|
if (dumpNets) {
|
|
232
238
|
const nets = visitor.dumpNets();
|
package/dist/types/helpers.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { BaseError } from "./utils.js";
|
|
2
2
|
import { ParserVisitor } from "./visitor.js";
|
|
3
|
+
import { ParserRuleContext } from "antlr4ng";
|
|
3
4
|
import { SymbolValidatorVisitor } from "./validate/SymbolValidatorVisitor.js";
|
|
4
5
|
import { CommonTokenStream, DefaultErrorStrategy, Parser } from "antlr4ng";
|
|
5
|
-
import { CircuitScriptParser } from "./antlr/CircuitScriptParser.js";
|
|
6
|
+
import { CircuitScriptParser, ScriptContext } from "./antlr/CircuitScriptParser.js";
|
|
6
7
|
import { CircuitScriptLexer } from "./antlr/CircuitScriptLexer.js";
|
|
7
8
|
import { IParsedToken, SemanticTokensVisitor } from "./SemanticTokenVisitor.js";
|
|
8
9
|
import { LengthUnit } from "./globals.js";
|
|
9
10
|
export type SVGWindow = any;
|
|
10
11
|
import { NumericValue } from "./objects/ParamDefinition.js";
|
|
11
12
|
import { NodeScriptEnvironment } from "./environment.js";
|
|
13
|
+
import { ClassComponent } from "./objects/ClassComponent.js";
|
|
12
14
|
export declare enum JSModuleType {
|
|
13
15
|
CommonJs = "cjs",
|
|
14
16
|
ESM = "mjs"
|
|
@@ -44,7 +46,7 @@ type RenderScriptReturn = {
|
|
|
44
46
|
errors: BaseError[];
|
|
45
47
|
};
|
|
46
48
|
export declare function renderScript(scriptData: string, outputPath: string | null, options: ScriptOptions): Promise<RenderScriptReturn>;
|
|
47
|
-
export declare function renderScriptCustom(scriptData: string, outputPath: string | null, options: ScriptOptions, parseHandlers: ParseOutputHandler[]): Promise<RenderScriptReturn>;
|
|
49
|
+
export declare function renderScriptCustom(scriptData: string, outputPath: string | null, options: ScriptOptions, parseHandlers: ParseOutputHandler[], postAnnotationCallbacks: ((options: ScriptOptions, scriptData: string, tree: ScriptContext, tokens: CommonTokenStream, componentLinks: Map<ParserRuleContext, ClassComponent>) => void)[]): Promise<RenderScriptReturn>;
|
|
48
50
|
export declare abstract class ParseOutputHandler {
|
|
49
51
|
beforeRender: boolean;
|
|
50
52
|
afterRender: boolean;
|