circuitscript 0.3.1 → 0.3.2
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/RefdesAnnotationVisitor.js +2 -2
- package/dist/cjs/helpers.js +41 -23
- package/dist/cjs/visitor.js +26 -16
- package/dist/esm/RefdesAnnotationVisitor.js +2 -2
- package/dist/esm/helpers.js +41 -23
- package/dist/esm/visitor.js +26 -16
- package/dist/types/RefdesAnnotationVisitor.d.ts +1 -1
- package/package.json +1 -1
|
@@ -117,12 +117,12 @@ class RefdesAnnotationVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
117
117
|
return this.resultText;
|
|
118
118
|
}
|
|
119
119
|
getOutputForExternalRefdesFile() {
|
|
120
|
-
const result =
|
|
120
|
+
const result = {};
|
|
121
121
|
this.modifications.forEach((modification, ctx) => {
|
|
122
122
|
const { line: startLine, column: startColumn } = ctx.start;
|
|
123
123
|
const { line: stopLine, column: stopColumn } = ctx.stop;
|
|
124
124
|
const joinedRefdes = modification.refdes.join(',');
|
|
125
|
-
result
|
|
125
|
+
result[joinedRefdes] = `${startLine}:${startColumn}:${stopLine}:${stopColumn}`;
|
|
126
126
|
});
|
|
127
127
|
return result;
|
|
128
128
|
}
|
package/dist/cjs/helpers.js
CHANGED
|
@@ -162,7 +162,7 @@ exports.validateScript = validateScript;
|
|
|
162
162
|
async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks, importedLibraries, environment) {
|
|
163
163
|
const { inputPath = null, updateSource = false, saveAnnotatedCopy = undefined, } = options;
|
|
164
164
|
if (inputPath && (updateSource || saveAnnotatedCopy !== undefined)) {
|
|
165
|
-
const
|
|
165
|
+
const sourceAnnotatedFiles = [{
|
|
166
166
|
isMainFile: true,
|
|
167
167
|
scriptData,
|
|
168
168
|
tokens,
|
|
@@ -170,6 +170,7 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
|
|
|
170
170
|
filePath: inputPath,
|
|
171
171
|
outputType: RefdesOutputType.WithSource
|
|
172
172
|
}];
|
|
173
|
+
const externalRefdesLibraries = [];
|
|
173
174
|
for (const library of importedLibraries) {
|
|
174
175
|
let outputType = RefdesOutputType.None;
|
|
175
176
|
if (library.enableRefdesAnnotation) {
|
|
@@ -181,17 +182,23 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
|
|
|
181
182
|
if (outputType !== RefdesOutputType.None) {
|
|
182
183
|
const { libraryFilePath, libraryName, tokens: libTokens, tree: libTree } = library;
|
|
183
184
|
const libraryScriptData = await environment.readFile(libraryFilePath, { encoding: 'utf8' });
|
|
184
|
-
|
|
185
|
+
const annotatedFile = {
|
|
185
186
|
tokens: libTokens,
|
|
186
187
|
tree: libTree,
|
|
187
188
|
filePath: libraryFilePath,
|
|
188
189
|
scriptData: libraryScriptData,
|
|
189
190
|
libraryName,
|
|
190
191
|
outputType
|
|
191
|
-
}
|
|
192
|
+
};
|
|
193
|
+
if (outputType === RefdesOutputType.CreateExternalFile) {
|
|
194
|
+
externalRefdesLibraries.push(annotatedFile);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
sourceAnnotatedFiles.push(annotatedFile);
|
|
198
|
+
}
|
|
192
199
|
}
|
|
193
200
|
}
|
|
194
|
-
for (const item of
|
|
201
|
+
for (const item of sourceAnnotatedFiles) {
|
|
195
202
|
const { scriptData, tokens, tree, filePath, libraryName, isMainFile = false } = item;
|
|
196
203
|
const tmpVisitor = new RefdesAnnotationVisitor_js_1.RefdesAnnotationVisitor(true, scriptData, tokens, componentLinks);
|
|
197
204
|
await tmpVisitor.visit(tree);
|
|
@@ -205,31 +212,42 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
|
|
|
205
212
|
else if (isMainFile && typeof saveAnnotatedCopy === 'string') {
|
|
206
213
|
usePath = saveAnnotatedCopy;
|
|
207
214
|
}
|
|
208
|
-
|
|
209
|
-
environment.writeFileSync(usePath, tmpVisitor.getOutput());
|
|
210
|
-
}
|
|
211
|
-
else if (item.outputType === RefdesOutputType.CreateExternalFile) {
|
|
212
|
-
const dir = environment.dirname(usePath);
|
|
213
|
-
const ext = environment.extname(usePath);
|
|
214
|
-
const basename = environment.basename(filePath, ext);
|
|
215
|
-
usePath = environment.join(dir, `${basename}${globals_js_1.RefdesFileSuffix}`);
|
|
216
|
-
const output = tmpVisitor.getOutputForExternalRefdesFile();
|
|
217
|
-
const inputDir = environment.dirname(inputPath);
|
|
218
|
-
const relativeFilePath = environment.relative(inputDir, filePath);
|
|
219
|
-
const jsonFile = {
|
|
220
|
-
format: 'v1',
|
|
221
|
-
library: libraryName,
|
|
222
|
-
file: relativeFilePath,
|
|
223
|
-
items: output,
|
|
224
|
-
};
|
|
225
|
-
environment.writeFileSync(usePath, JSON.stringify(jsonFile, null, 4));
|
|
226
|
-
}
|
|
215
|
+
environment.writeFileSync(usePath, tmpVisitor.getOutput());
|
|
227
216
|
let display = 'Refdes annotations';
|
|
228
217
|
if (libraryName) {
|
|
229
218
|
display += ` for library ${libraryName}`;
|
|
230
219
|
}
|
|
231
220
|
console.log(`${display} saved to ${usePath}`);
|
|
232
221
|
}
|
|
222
|
+
if (externalRefdesLibraries.length > 0) {
|
|
223
|
+
const inputDir = environment.dirname(inputPath);
|
|
224
|
+
const inputExt = environment.extname(inputPath);
|
|
225
|
+
const inputBasename = environment.basename(inputPath, inputExt);
|
|
226
|
+
const refdesFilePath = environment.join(inputDir, `${inputBasename}${globals_js_1.RefdesFileSuffix}`);
|
|
227
|
+
const libraries = [];
|
|
228
|
+
for (const item of externalRefdesLibraries) {
|
|
229
|
+
const { scriptData, tokens, tree, filePath, libraryName } = item;
|
|
230
|
+
const tmpVisitor = new RefdesAnnotationVisitor_js_1.RefdesAnnotationVisitor(true, scriptData, tokens, componentLinks);
|
|
231
|
+
await tmpVisitor.visit(tree);
|
|
232
|
+
const output = tmpVisitor.getOutputForExternalRefdesFile();
|
|
233
|
+
const relativeFilePath = environment.relative(inputDir, filePath);
|
|
234
|
+
libraries.push({
|
|
235
|
+
name: libraryName,
|
|
236
|
+
path: relativeFilePath,
|
|
237
|
+
items: output,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
const sortedLibs = libraries.sort((a, b) => {
|
|
241
|
+
return a.name.localeCompare(b.name);
|
|
242
|
+
});
|
|
243
|
+
const jsonFile = {
|
|
244
|
+
format: 'v1',
|
|
245
|
+
description: 'Stores external refdes for libraries',
|
|
246
|
+
libraries: sortedLibs,
|
|
247
|
+
};
|
|
248
|
+
environment.writeFileSync(refdesFilePath, JSON.stringify(jsonFile, null, 4));
|
|
249
|
+
console.log(`External refdes annotations saved to ${refdesFilePath}`);
|
|
250
|
+
}
|
|
233
251
|
}
|
|
234
252
|
}
|
|
235
253
|
var RefdesOutputType;
|
package/dist/cjs/visitor.js
CHANGED
|
@@ -1386,24 +1386,34 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1386
1386
|
}
|
|
1387
1387
|
}
|
|
1388
1388
|
async checkLibraryHasRefdesFile(filePath) {
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
const
|
|
1393
|
-
const
|
|
1389
|
+
if (this.filePathStack.length === 0) {
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
const mainFilePath = this.environment.getAbsolutePath(this.filePathStack[0]);
|
|
1393
|
+
const mainDir = this.environment.dirname(mainFilePath);
|
|
1394
|
+
const mainExt = this.environment.extname(mainFilePath);
|
|
1395
|
+
const mainBasename = this.environment.basename(mainFilePath, mainExt);
|
|
1396
|
+
const refdesFilePath = this.environment.join(mainDir, `${mainBasename}${globals_js_1.RefdesFileSuffix}`);
|
|
1397
|
+
const exists = await this.environment.exists(refdesFilePath);
|
|
1394
1398
|
if (exists) {
|
|
1395
|
-
this.log(`
|
|
1396
|
-
const fileData = await this.environment.readFile(
|
|
1399
|
+
this.log(`Main schematic has refdes file: ${refdesFilePath}`);
|
|
1400
|
+
const fileData = await this.environment.readFile(refdesFilePath);
|
|
1397
1401
|
const jsonData = JSON.parse(fileData);
|
|
1398
|
-
const
|
|
1399
|
-
const
|
|
1400
|
-
const
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1402
|
+
const relativeLibraryPath = this.environment.relative(mainDir, filePath);
|
|
1403
|
+
const { libraries = [] } = jsonData;
|
|
1404
|
+
for (const library of libraries) {
|
|
1405
|
+
const { path: libraryPath, items } = library;
|
|
1406
|
+
if (libraryPath === relativeLibraryPath) {
|
|
1407
|
+
this.log(`Found refdes annotations for library at: ${libraryPath}`);
|
|
1408
|
+
const useFilePath = this.environment.join(mainDir, libraryPath);
|
|
1409
|
+
for (const refdes in items) {
|
|
1410
|
+
const val = items[refdes];
|
|
1411
|
+
const parts = val.split(':');
|
|
1412
|
+
const key = this.getRefdesFileAnnotation(useFilePath, Number(parts[0]), Number(parts[1]), Number(parts[2]), Number(parts[3]));
|
|
1413
|
+
this.refdesFileAnnotations.set(key, refdes);
|
|
1414
|
+
}
|
|
1415
|
+
break;
|
|
1416
|
+
}
|
|
1407
1417
|
}
|
|
1408
1418
|
}
|
|
1409
1419
|
}
|
|
@@ -117,12 +117,12 @@ export class RefdesAnnotationVisitor extends BaseVisitor {
|
|
|
117
117
|
return this.resultText;
|
|
118
118
|
}
|
|
119
119
|
getOutputForExternalRefdesFile() {
|
|
120
|
-
const result =
|
|
120
|
+
const result = {};
|
|
121
121
|
this.modifications.forEach((modification, ctx) => {
|
|
122
122
|
const { line: startLine, column: startColumn } = ctx.start;
|
|
123
123
|
const { line: stopLine, column: stopColumn } = ctx.stop;
|
|
124
124
|
const joinedRefdes = modification.refdes.join(',');
|
|
125
|
-
result
|
|
125
|
+
result[joinedRefdes] = `${startLine}:${startColumn}:${stopLine}:${stopColumn}`;
|
|
126
126
|
});
|
|
127
127
|
return result;
|
|
128
128
|
}
|
package/dist/esm/helpers.js
CHANGED
|
@@ -152,7 +152,7 @@ export async function validateScript(filePath, scriptData, options) {
|
|
|
152
152
|
async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks, importedLibraries, environment) {
|
|
153
153
|
const { inputPath = null, updateSource = false, saveAnnotatedCopy = undefined, } = options;
|
|
154
154
|
if (inputPath && (updateSource || saveAnnotatedCopy !== undefined)) {
|
|
155
|
-
const
|
|
155
|
+
const sourceAnnotatedFiles = [{
|
|
156
156
|
isMainFile: true,
|
|
157
157
|
scriptData,
|
|
158
158
|
tokens,
|
|
@@ -160,6 +160,7 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
|
|
|
160
160
|
filePath: inputPath,
|
|
161
161
|
outputType: RefdesOutputType.WithSource
|
|
162
162
|
}];
|
|
163
|
+
const externalRefdesLibraries = [];
|
|
163
164
|
for (const library of importedLibraries) {
|
|
164
165
|
let outputType = RefdesOutputType.None;
|
|
165
166
|
if (library.enableRefdesAnnotation) {
|
|
@@ -171,17 +172,23 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
|
|
|
171
172
|
if (outputType !== RefdesOutputType.None) {
|
|
172
173
|
const { libraryFilePath, libraryName, tokens: libTokens, tree: libTree } = library;
|
|
173
174
|
const libraryScriptData = await environment.readFile(libraryFilePath, { encoding: 'utf8' });
|
|
174
|
-
|
|
175
|
+
const annotatedFile = {
|
|
175
176
|
tokens: libTokens,
|
|
176
177
|
tree: libTree,
|
|
177
178
|
filePath: libraryFilePath,
|
|
178
179
|
scriptData: libraryScriptData,
|
|
179
180
|
libraryName,
|
|
180
181
|
outputType
|
|
181
|
-
}
|
|
182
|
+
};
|
|
183
|
+
if (outputType === RefdesOutputType.CreateExternalFile) {
|
|
184
|
+
externalRefdesLibraries.push(annotatedFile);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
sourceAnnotatedFiles.push(annotatedFile);
|
|
188
|
+
}
|
|
182
189
|
}
|
|
183
190
|
}
|
|
184
|
-
for (const item of
|
|
191
|
+
for (const item of sourceAnnotatedFiles) {
|
|
185
192
|
const { scriptData, tokens, tree, filePath, libraryName, isMainFile = false } = item;
|
|
186
193
|
const tmpVisitor = new RefdesAnnotationVisitor(true, scriptData, tokens, componentLinks);
|
|
187
194
|
await tmpVisitor.visit(tree);
|
|
@@ -195,31 +202,42 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
|
|
|
195
202
|
else if (isMainFile && typeof saveAnnotatedCopy === 'string') {
|
|
196
203
|
usePath = saveAnnotatedCopy;
|
|
197
204
|
}
|
|
198
|
-
|
|
199
|
-
environment.writeFileSync(usePath, tmpVisitor.getOutput());
|
|
200
|
-
}
|
|
201
|
-
else if (item.outputType === RefdesOutputType.CreateExternalFile) {
|
|
202
|
-
const dir = environment.dirname(usePath);
|
|
203
|
-
const ext = environment.extname(usePath);
|
|
204
|
-
const basename = environment.basename(filePath, ext);
|
|
205
|
-
usePath = environment.join(dir, `${basename}${RefdesFileSuffix}`);
|
|
206
|
-
const output = tmpVisitor.getOutputForExternalRefdesFile();
|
|
207
|
-
const inputDir = environment.dirname(inputPath);
|
|
208
|
-
const relativeFilePath = environment.relative(inputDir, filePath);
|
|
209
|
-
const jsonFile = {
|
|
210
|
-
format: 'v1',
|
|
211
|
-
library: libraryName,
|
|
212
|
-
file: relativeFilePath,
|
|
213
|
-
items: output,
|
|
214
|
-
};
|
|
215
|
-
environment.writeFileSync(usePath, JSON.stringify(jsonFile, null, 4));
|
|
216
|
-
}
|
|
205
|
+
environment.writeFileSync(usePath, tmpVisitor.getOutput());
|
|
217
206
|
let display = 'Refdes annotations';
|
|
218
207
|
if (libraryName) {
|
|
219
208
|
display += ` for library ${libraryName}`;
|
|
220
209
|
}
|
|
221
210
|
console.log(`${display} saved to ${usePath}`);
|
|
222
211
|
}
|
|
212
|
+
if (externalRefdesLibraries.length > 0) {
|
|
213
|
+
const inputDir = environment.dirname(inputPath);
|
|
214
|
+
const inputExt = environment.extname(inputPath);
|
|
215
|
+
const inputBasename = environment.basename(inputPath, inputExt);
|
|
216
|
+
const refdesFilePath = environment.join(inputDir, `${inputBasename}${RefdesFileSuffix}`);
|
|
217
|
+
const libraries = [];
|
|
218
|
+
for (const item of externalRefdesLibraries) {
|
|
219
|
+
const { scriptData, tokens, tree, filePath, libraryName } = item;
|
|
220
|
+
const tmpVisitor = new RefdesAnnotationVisitor(true, scriptData, tokens, componentLinks);
|
|
221
|
+
await tmpVisitor.visit(tree);
|
|
222
|
+
const output = tmpVisitor.getOutputForExternalRefdesFile();
|
|
223
|
+
const relativeFilePath = environment.relative(inputDir, filePath);
|
|
224
|
+
libraries.push({
|
|
225
|
+
name: libraryName,
|
|
226
|
+
path: relativeFilePath,
|
|
227
|
+
items: output,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
const sortedLibs = libraries.sort((a, b) => {
|
|
231
|
+
return a.name.localeCompare(b.name);
|
|
232
|
+
});
|
|
233
|
+
const jsonFile = {
|
|
234
|
+
format: 'v1',
|
|
235
|
+
description: 'Stores external refdes for libraries',
|
|
236
|
+
libraries: sortedLibs,
|
|
237
|
+
};
|
|
238
|
+
environment.writeFileSync(refdesFilePath, JSON.stringify(jsonFile, null, 4));
|
|
239
|
+
console.log(`External refdes annotations saved to ${refdesFilePath}`);
|
|
240
|
+
}
|
|
223
241
|
}
|
|
224
242
|
}
|
|
225
243
|
var RefdesOutputType;
|
package/dist/esm/visitor.js
CHANGED
|
@@ -1376,24 +1376,34 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1376
1376
|
});
|
|
1377
1377
|
};
|
|
1378
1378
|
async checkLibraryHasRefdesFile(filePath) {
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
const
|
|
1383
|
-
const
|
|
1379
|
+
if (this.filePathStack.length === 0) {
|
|
1380
|
+
return;
|
|
1381
|
+
}
|
|
1382
|
+
const mainFilePath = this.environment.getAbsolutePath(this.filePathStack[0]);
|
|
1383
|
+
const mainDir = this.environment.dirname(mainFilePath);
|
|
1384
|
+
const mainExt = this.environment.extname(mainFilePath);
|
|
1385
|
+
const mainBasename = this.environment.basename(mainFilePath, mainExt);
|
|
1386
|
+
const refdesFilePath = this.environment.join(mainDir, `${mainBasename}${RefdesFileSuffix}`);
|
|
1387
|
+
const exists = await this.environment.exists(refdesFilePath);
|
|
1384
1388
|
if (exists) {
|
|
1385
|
-
this.log(`
|
|
1386
|
-
const fileData = await this.environment.readFile(
|
|
1389
|
+
this.log(`Main schematic has refdes file: ${refdesFilePath}`);
|
|
1390
|
+
const fileData = await this.environment.readFile(refdesFilePath);
|
|
1387
1391
|
const jsonData = JSON.parse(fileData);
|
|
1388
|
-
const
|
|
1389
|
-
const
|
|
1390
|
-
const
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1392
|
+
const relativeLibraryPath = this.environment.relative(mainDir, filePath);
|
|
1393
|
+
const { libraries = [] } = jsonData;
|
|
1394
|
+
for (const library of libraries) {
|
|
1395
|
+
const { path: libraryPath, items } = library;
|
|
1396
|
+
if (libraryPath === relativeLibraryPath) {
|
|
1397
|
+
this.log(`Found refdes annotations for library at: ${libraryPath}`);
|
|
1398
|
+
const useFilePath = this.environment.join(mainDir, libraryPath);
|
|
1399
|
+
for (const refdes in items) {
|
|
1400
|
+
const val = items[refdes];
|
|
1401
|
+
const parts = val.split(':');
|
|
1402
|
+
const key = this.getRefdesFileAnnotation(useFilePath, Number(parts[0]), Number(parts[1]), Number(parts[2]), Number(parts[3]));
|
|
1403
|
+
this.refdesFileAnnotations.set(key, refdes);
|
|
1404
|
+
}
|
|
1405
|
+
break;
|
|
1406
|
+
}
|
|
1397
1407
|
}
|
|
1398
1408
|
}
|
|
1399
1409
|
}
|
|
@@ -27,7 +27,7 @@ export declare class RefdesAnnotationVisitor extends BaseVisitor {
|
|
|
27
27
|
private generateRefdesAnnotationComment;
|
|
28
28
|
private addRefdesAnnotationComment;
|
|
29
29
|
getOutput(): string;
|
|
30
|
-
getOutputForExternalRefdesFile(): string
|
|
30
|
+
getOutputForExternalRefdesFile(): Record<string, string>;
|
|
31
31
|
private generateModifiedText;
|
|
32
32
|
private buildContextTokenRanges;
|
|
33
33
|
private findContextForToken;
|