circuitscript 0.0.12 → 0.0.14

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/src/main.ts CHANGED
@@ -4,20 +4,17 @@ import { program } from 'commander';
4
4
  import figlet from 'figlet';
5
5
  import path from 'path';
6
6
  import { fileURLToPath } from 'url';
7
- import { readFileSync, watch, writeFileSync } from 'fs';
7
+ import { readFileSync, watch } from 'fs';
8
8
 
9
- import { MainVisitor } from './visitor.js';
10
9
  import { prepareSizing } from './sizing.js';
11
- import { LayoutEngine } from './layout.js';
12
- import { generateSVG2 } from './render.js';
13
- import { SequenceAction } from './objects/ExecutionScope.js';
14
- import { parseFileWithVisitor } from './parser.js';
15
- import { generateKiCADNetList } from './export.js';
16
- import { SimpleStopwatch } from './utils.js';
10
+ import { renderScript } from './helpers.js';
17
11
 
18
12
  export default async function main(): Promise<void> {
19
13
  const toolSrcPath = fileURLToPath(import.meta.url);
14
+
20
15
  const toolDirectory = path.dirname(toolSrcPath) + '/../../';
16
+ const fontsPath = toolDirectory + '/fonts';
17
+ const defaultLibsPath = toolDirectory + '/libs';
21
18
 
22
19
  const packageJson = JSON.parse(readFileSync(toolDirectory + 'package.json').toString());;
23
20
  const {version} = packageJson;
@@ -56,10 +53,6 @@ export default async function main(): Promise<void> {
56
53
 
57
54
  let currentDirectory = options.currentDirectory ?? null;
58
55
 
59
-
60
- const fontsPath = toolDirectory + '/fonts';
61
- const defaultLibsPath = toolDirectory + '/libs';
62
-
63
56
  if (watchFileChanges) {
64
57
  console.log('watching for file changes...');
65
58
  }
@@ -97,7 +90,7 @@ export default async function main(): Promise<void> {
97
90
  }
98
91
 
99
92
  if (watchFileChanges) {
100
- watch(inputFilePath, (event, targetFile) => {
93
+ watch(inputFilePath, event => {
101
94
  if (event === 'change') {
102
95
  const scriptData = readFileSync(inputFilePath,
103
96
  {encoding: 'utf-8'});
@@ -109,112 +102,4 @@ export default async function main(): Promise<void> {
109
102
  }
110
103
  }
111
104
 
112
-
113
- export function renderScript(scriptData: string, outputPath: string, options): string {
114
-
115
- const {
116
- currentDirectory = null,
117
- defaultLibsPath,
118
- dumpNets = false,
119
- dumpData = false,
120
- kicadNetlistPath = null,
121
- showStats = false} = options;
122
-
123
- const visitor = new MainVisitor(true);
124
-
125
- visitor.onImportFile = visitor.createImportFileHandler(currentDirectory, defaultLibsPath);
126
-
127
- visitor.print('reading file');
128
- visitor.print('done reading file');
129
-
130
- const { tree, parser,
131
- hasParseError, hasError,
132
- parserTimeTaken,
133
- lexerTimeTaken } = parseFileWithVisitor(visitor, scriptData);
134
-
135
- showStats && console.log('Lexing took:', lexerTimeTaken);
136
- showStats && console.log('Parsing took:', parserTimeTaken);
137
-
138
- if (dumpNets){
139
- console.log(visitor.dumpNets());
140
- }
141
- // console.log(visitor.dumpUniqueNets());
142
-
143
- dumpData && writeFileSync('dump/tree.lisp', tree.toStringTree(null, parser));
144
- dumpData && writeFileSync('dump/raw-parser.txt', visitor.logger.dump());
145
-
146
- if (hasError || hasParseError) {
147
- console.log('Error while parsing');
148
- return;
149
- }
150
-
151
- visitor.annotateComponents();
152
-
153
- if(kicadNetlistPath){
154
- const kicadNetList = generateKiCADNetList(visitor.getNetList());
155
- writeFileSync(kicadNetlistPath, kicadNetList);
156
- console.log('Generated KiCad netlist file');
157
- }
158
-
159
-
160
- // await writeFile('dump/raw-netlist.json', JSON.stringify(visitor.dump2(), null, 2));
161
-
162
- const { sequence, nets } = visitor.getGraph();
163
-
164
- // const tmpInstances = visitor.getExecutor().scope.instances;
165
- // for (const [instanceName, instance] of tmpInstances){
166
- // console.log(instanceName);
167
- // console.log(instance.pinNets);
168
- // }
169
-
170
-
171
- const tmpSequence = sequence.map(item => {
172
- const tmp = [...item];
173
-
174
- const action = tmp[0];
175
-
176
- if (action === SequenceAction.Wire) {
177
- tmp[2] = tmp[2].map(item2 => {
178
- return [item2.direction, item2.value].join(",");
179
- }).join(" ");
180
- } else if (action === SequenceAction.Frame) {
181
- tmp[1] = item[1].frameId;
182
-
183
- } else if (action !== SequenceAction.WireJump) {
184
- tmp[1] = item[1].instanceName;
185
- }
186
-
187
- return tmp.join(" | ");
188
- });
189
-
190
- dumpData && writeFileSync('dump/raw-sequence.txt', tmpSequence.join('\n'));
191
- let svgOutput: string = null;
192
-
193
- try {
194
- const layoutEngine = new LayoutEngine();
195
- const layoutTimer = new SimpleStopwatch();
196
-
197
- const graph = layoutEngine.runLayout(sequence, nets);
198
-
199
- layoutEngine.printWarnings();
200
-
201
- showStats && console.log('Layout took:', layoutTimer.lap());
202
-
203
- dumpData && writeFileSync('dump/raw-layout.txt', layoutEngine.logger.dump());
204
-
205
- const generateSvgTimer = new SimpleStopwatch();
206
- svgOutput = generateSVG2(graph);
207
- showStats && console.log('Render took:', generateSvgTimer.lap());
208
-
209
- if (outputPath){
210
- writeFileSync(outputPath, svgOutput);
211
- }
212
- } catch (err) {
213
- console.log('Failed to render:');
214
- console.log(err)
215
- }
216
-
217
- return svgOutput;
218
- }
219
-
220
105
  main();
package/src/parser.ts CHANGED
@@ -91,14 +91,14 @@ export class CircuitscriptParserErrorListener extends ErrorListener {
91
91
  this.syntaxErrorCounter++;
92
92
  }
93
93
 
94
- reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs) {
95
- }
94
+ // reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs) {
95
+ // }
96
96
 
97
- reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs) {
98
- }
97
+ // reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs) {
98
+ // }
99
99
 
100
- reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs) {
101
- }
100
+ // reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs) {
101
+ // }
102
102
 
103
103
  hasParseErrors(): boolean {
104
104
  return (this.syntaxErrorCounter > 0);
@@ -1,5 +1,5 @@
1
1
  import fs from 'fs';
2
- import { renderScript } from './main.js';
2
+ import { renderScript } from './helpers.js';
3
3
 
4
4
  const mainDir = './__tests__/renderData/';
5
5
 
package/src/sizing.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import { Box, SVG, SVGTypeMapping, registerWindow } from '@svgdotjs/svg.js';
2
2
  import { config, createSVGWindow } from 'svgdom';
3
3
  import { HorizontalAlign, VerticalAlign } from './geometry.js';
4
+ import { defaultFont } from './globals.js';
4
5
 
5
6
  let MainCanvas = null;
6
7
 
7
8
  const supportedFonts = {
8
9
  // 'Roboto': 'Roboto-Regular.ttf',
9
- 'Inter': 'Inter-Regular.ttf',
10
- 'Inter-Bold': 'Inter-Bold.ttf',
10
+ // 'Inter': 'Inter-Regular.ttf',
11
+ // 'Inter-Bold': 'Inter-Bold.ttf',
11
12
  }
12
13
 
13
14
  export async function prepareSizing(fontsPath): Promise<void> {
@@ -68,18 +69,14 @@ export function measureTextSize2(text: string, fontFamily: string,
68
69
  break;
69
70
  }
70
71
 
71
- if (fontWeight === 'bold'){
72
- fontFamily = 'Inter-Bold';
73
- } else {
74
- fontFamily = 'Inter-Regular';
75
- }
72
+ fontFamily = defaultFont;
76
73
 
77
74
  const tmpTextElement = MainCanvas.text(text).font({
78
75
  family: fontFamily,
79
76
  size: fontSize,
80
77
  anchor: anchor,
81
78
  'dominant-baseline': dominantBaseline,
82
- // weight: fontWeight,
79
+ weight: fontWeight,
83
80
  }).fill('#333');
84
81
 
85
82
  const textbox = tmpTextElement.bbox();
File without changes