node-opcua-generator 2.55.0 → 2.60.0
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/.mocharc.yml +8 -8
- package/LICENSE +20 -20
- package/dist/factory_code_generator.js +5 -4
- package/dist/factory_code_generator.js.map +1 -1
- package/dist/generate_extension_object_code.js +100 -103
- package/dist/generate_extension_object_code.js.map +1 -1
- package/dist/generator.d.ts +3 -1
- package/dist/generator.js.map +1 -1
- package/dist/opcua_code_generator.js +1 -3
- package/dist/opcua_code_generator.js.map +1 -1
- package/dist/utils/write_func.d.ts +1 -1
- package/dist/utils/write_func.js +1 -1
- package/dist/utils/write_func.js.map +1 -1
- package/package.json +21 -19
- package/source/factory_code_generator.ts +899 -893
- package/source/generate_extension_object_code.ts +115 -118
- package/source/generator.ts +4 -4
- package/source/index.ts +6 -6
- package/source/opcua_code_generator.ts +15 -17
- package/source/utils/index.ts +2 -2
- package/source/utils/line_file.ts +23 -23
- package/source/utils/normalize_require_file.ts +21 -21
- package/source/utils/write_func.ts +18 -18
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
1
2
|
/* istanbul ignore file */
|
|
2
3
|
/**
|
|
3
4
|
* @module node-opcua-generator
|
|
@@ -5,10 +6,10 @@
|
|
|
5
6
|
// tslint:disable:max-line-length
|
|
6
7
|
// tslint:disable:no-inner-declarations
|
|
7
8
|
//
|
|
8
|
-
import * as chalk from "chalk";
|
|
9
9
|
import * as fs from "fs";
|
|
10
|
+
import * as chalk from "chalk";
|
|
10
11
|
// node 14 onward : import { readFile } from "fs/promises";
|
|
11
|
-
const { readFile }= fs.promises;
|
|
12
|
+
const { readFile } = fs.promises;
|
|
12
13
|
|
|
13
14
|
// import * as prettier from "prettier";
|
|
14
15
|
|
|
@@ -32,12 +33,12 @@ import { makeWrite } from "./utils/write_func";
|
|
|
32
33
|
const doDebug = checkDebugFlag(__filename);
|
|
33
34
|
const debugLog = make_debugLog(__filename);
|
|
34
35
|
|
|
35
|
-
|
|
36
36
|
const f = new LineFile1();
|
|
37
37
|
|
|
38
38
|
const write = makeWrite(f);
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
// eslint-disable-next-line max-statements
|
|
41
|
+
function writeEnumeratedType(enumerationSchema: EnumerationDefinitionSchema): void {
|
|
41
42
|
const arrayValues = Object.keys(enumerationSchema.enumValues)
|
|
42
43
|
.filter((a: string) => a.match("[0-9]+"))
|
|
43
44
|
.map((a: string) => parseInt(a, 10))
|
|
@@ -51,7 +52,7 @@ function writeEnumeratedType(enumerationSchema: EnumerationDefinitionSchema) {
|
|
|
51
52
|
const maxEnumValue = Math.max.apply(null, arrayValues);
|
|
52
53
|
|
|
53
54
|
// make sure there is a Invalid key in the enum => else insert one (but only if not flaggable)
|
|
54
|
-
const hasInvalid =
|
|
55
|
+
const hasInvalid = Object.prototype.hasOwnProperty.call(enumerationSchema.enumValues, "Invalid");
|
|
55
56
|
if (!hasInvalid && !isFlaggable) {
|
|
56
57
|
enumerationSchema.enumValues[(enumerationSchema.enumValues.Invalid = 0xffffffff)] = "Invalid";
|
|
57
58
|
}
|
|
@@ -137,46 +138,45 @@ function writeStructuredTypeWithSchema(structuredType: StructuredTypeSchema) {
|
|
|
137
138
|
writeStructuredType(write, structuredType);
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
export async function generate(filename: string, generatedTypescriptFilename: string) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
const dataTypeNodeId = new NodeId(NodeId.NodeIdType.NUMERIC, dataType, 0);
|
|
154
|
-
const binaryEncodingNodeId = new NodeId(NodeId.NodeIdType.NUMERIC, binEncoding, 0);
|
|
155
|
-
const xmlEncodingNodeId = new NodeId(NodeId.NodeIdType.NUMERIC, xmlEncoding, 0);
|
|
156
|
-
const jsonEncodingNodeId = new NodeId(NodeId.NodeIdType.NUMERIC, jsonEncoding, 0);
|
|
157
|
-
const data: DataTypeAndEncodingId = {
|
|
158
|
-
binaryEncodingNodeId,
|
|
159
|
-
dataTypeNodeId,
|
|
160
|
-
jsonEncodingNodeId,
|
|
161
|
-
xmlEncodingNodeId
|
|
162
|
-
};
|
|
163
|
-
if (doDebug) {
|
|
164
|
-
debugLog(
|
|
165
|
-
" data=",
|
|
166
|
-
chalk.cyan(name.padEnd(43, " ")),
|
|
167
|
-
data.dataTypeNodeId.toString().padEnd(43, " "),
|
|
168
|
-
data.binaryEncodingNodeId.toString().padEnd(43, " ")
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
return data;
|
|
141
|
+
export async function generate(filename: string, generatedTypescriptFilename: string): Promise<void> {
|
|
142
|
+
const content = await readFile(filename, "ascii");
|
|
143
|
+
|
|
144
|
+
const idProvider: MapDataTypeAndEncodingIdProvider = {
|
|
145
|
+
getDataTypeAndEncodingId(name: string): DataTypeAndEncodingId | null {
|
|
146
|
+
const dataType = (DataTypeIds as any)[name] || 0;
|
|
147
|
+
const binEncoding = (ObjectIds as any)[name + "_Encoding_DefaultBinary"] || 0;
|
|
148
|
+
const xmlEncoding = (ObjectIds as any)[name + "_Encoding_DefaultXml"] || 0;
|
|
149
|
+
const jsonEncoding = (ObjectIds as any)[name + "_Encoding_DefaultJson"] || 0;
|
|
150
|
+
if (dataType === undefined) {
|
|
151
|
+
return null;
|
|
172
152
|
}
|
|
173
|
-
|
|
153
|
+
const dataTypeNodeId = new NodeId(NodeId.NodeIdType.NUMERIC, dataType, 0);
|
|
154
|
+
const binaryEncodingNodeId = new NodeId(NodeId.NodeIdType.NUMERIC, binEncoding, 0);
|
|
155
|
+
const xmlEncodingNodeId = new NodeId(NodeId.NodeIdType.NUMERIC, xmlEncoding, 0);
|
|
156
|
+
const jsonEncodingNodeId = new NodeId(NodeId.NodeIdType.NUMERIC, jsonEncoding, 0);
|
|
157
|
+
const data: DataTypeAndEncodingId = {
|
|
158
|
+
binaryEncodingNodeId,
|
|
159
|
+
dataTypeNodeId,
|
|
160
|
+
jsonEncodingNodeId,
|
|
161
|
+
xmlEncodingNodeId
|
|
162
|
+
};
|
|
163
|
+
if (doDebug) {
|
|
164
|
+
debugLog(
|
|
165
|
+
" data=",
|
|
166
|
+
chalk.cyan(name.padEnd(43, " ")),
|
|
167
|
+
data.dataTypeNodeId.toString().padEnd(43, " "),
|
|
168
|
+
data.binaryEncodingNodeId.toString().padEnd(43, " ")
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return data;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
const dataTypeFactory = new DataTypeFactory([getStandardDataTypeFactory()]);
|
|
176
|
+
await parseBinaryXSDAsync(content, idProvider, dataTypeFactory);
|
|
177
177
|
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
write(
|
|
179
|
+
`// tslint:disable:no-this-assignment
|
|
180
180
|
// tslint:disable:max-classes-per-file
|
|
181
181
|
// tslint:disable:no-empty-interface
|
|
182
182
|
// tslint:disable:no-trailing-whitespace
|
|
@@ -256,91 +256,91 @@ import {
|
|
|
256
256
|
decodeVariant, encodeVariant, Variant, VariantLike,
|
|
257
257
|
VariantOptions
|
|
258
258
|
} from "node-opcua-variant";`
|
|
259
|
-
|
|
259
|
+
);
|
|
260
260
|
|
|
261
|
-
|
|
261
|
+
write(``);
|
|
262
262
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
263
|
+
write(`export class DataTypeDefinition extends BaseUAObject {`);
|
|
264
|
+
write(` constructor(options: any) {`);
|
|
265
|
+
write(` options = options; // do not remove`);
|
|
266
|
+
write(` super();`);
|
|
267
|
+
write(` }`);
|
|
268
|
+
write(`}`);
|
|
269
|
+
write(``);
|
|
270
270
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
alreadyDone[enumerationSchema.name] = enumerationSchema;
|
|
301
|
-
writeEnumeratedType(enumerationSchema);
|
|
271
|
+
const alreadyDone: { [key: string]: any } = {};
|
|
272
|
+
/* tslint:disable:no-string-literal */
|
|
273
|
+
alreadyDone["ExtensionObject"] = true;
|
|
274
|
+
alreadyDone["NodeId"] = true;
|
|
275
|
+
|
|
276
|
+
alreadyDone["ExpandedNodeId"] = true;
|
|
277
|
+
alreadyDone["Variant"] = true;
|
|
278
|
+
alreadyDone["XmlElement"] = true;
|
|
279
|
+
|
|
280
|
+
alreadyDone["NodeIdType"] = true;
|
|
281
|
+
alreadyDone["TwoByteNodeId"] = true;
|
|
282
|
+
alreadyDone["FourByteNodeId"] = true;
|
|
283
|
+
alreadyDone["NumericNodeId"] = true;
|
|
284
|
+
alreadyDone["StringNodeId"] = true;
|
|
285
|
+
alreadyDone["GuidNodeId"] = true;
|
|
286
|
+
alreadyDone["ByteStringNodeId"] = true;
|
|
287
|
+
|
|
288
|
+
alreadyDone["DiagnosticInfo"] = true;
|
|
289
|
+
alreadyDone["Variant"] = true;
|
|
290
|
+
alreadyDone["DataValue"] = true;
|
|
291
|
+
alreadyDone["LocalizedText"] = true;
|
|
292
|
+
alreadyDone["QualifiedName"] = true;
|
|
293
|
+
alreadyDone["BrowseDirection"] = true;
|
|
294
|
+
alreadyDone["TimestampsToReturn"] = true;
|
|
295
|
+
|
|
296
|
+
function processEnumeratedType(enumerationSchema: EnumerationDefinitionSchema): void {
|
|
297
|
+
if (alreadyDone[enumerationSchema.name]) {
|
|
298
|
+
return;
|
|
302
299
|
}
|
|
300
|
+
alreadyDone[enumerationSchema.name] = enumerationSchema;
|
|
301
|
+
writeEnumeratedType(enumerationSchema);
|
|
302
|
+
}
|
|
303
303
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
304
|
+
function processStructuredType(structuredType: StructuredTypeSchema): void {
|
|
305
|
+
if (alreadyDone[structuredType.name]) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
alreadyDone[structuredType.name] = structuredType;
|
|
309
309
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
310
|
+
// make sure
|
|
311
|
+
if (dataTypeFactory.hasStructuredType(structuredType.baseType)) {
|
|
312
|
+
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structuredType.baseType));
|
|
313
|
+
}
|
|
314
|
+
for (const field of structuredType.fields) {
|
|
315
|
+
if (field.category === FieldCategory.complex) {
|
|
316
|
+
const fieldSchema = dataTypeFactory.getStructuredTypeSchema(field.fieldType);
|
|
317
|
+
processStructuredType(fieldSchema);
|
|
313
318
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
processStructuredType(fieldSchema);
|
|
318
|
-
}
|
|
319
|
-
if (field.category === FieldCategory.enumeration) {
|
|
320
|
-
const fieldSchema = dataTypeFactory.getEnumeration(field.fieldType)!;
|
|
321
|
-
processEnumeratedType(fieldSchema);
|
|
322
|
-
}
|
|
319
|
+
if (field.category === FieldCategory.enumeration) {
|
|
320
|
+
const fieldSchema = dataTypeFactory.getEnumeration(field.fieldType)!;
|
|
321
|
+
processEnumeratedType(fieldSchema);
|
|
323
322
|
}
|
|
324
|
-
writeStructuredTypeWithSchema(structuredType);
|
|
325
323
|
}
|
|
324
|
+
writeStructuredTypeWithSchema(structuredType);
|
|
325
|
+
}
|
|
326
326
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
327
|
+
processStructuredType(dataTypeFactory.getStructuredTypeSchema("LocalizedText"));
|
|
328
|
+
processStructuredType(dataTypeFactory.getStructuredTypeSchema("AxisInformation"));
|
|
329
|
+
// processStructuredType(dataTypeFactory.getStructuredTypeSchema("DiagnosticInfo"));
|
|
330
|
+
processStructuredType(dataTypeFactory.getStructuredTypeSchema("SimpleAttributeOperand"));
|
|
331
331
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structureType));
|
|
337
|
-
// if (++i > 250) { break; }
|
|
332
|
+
for (const structureType of [...dataTypeFactory.structuredTypesNames()].sort()) {
|
|
333
|
+
if (!dataTypeFactory.hasStructuredType(structureType)) {
|
|
334
|
+
continue;
|
|
338
335
|
}
|
|
336
|
+
processStructuredType(dataTypeFactory.getStructuredTypeSchema(structureType));
|
|
337
|
+
// if (++i > 250) { break; }
|
|
338
|
+
}
|
|
339
339
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
340
|
+
write(``);
|
|
341
|
+
f.saveFormat(generatedTypescriptFilename, (code) => {
|
|
342
|
+
return code;
|
|
343
|
+
/*
|
|
344
344
|
const options: prettier.Options = {
|
|
345
345
|
bracketSpacing: true,
|
|
346
346
|
insertPragma: true,
|
|
@@ -349,8 +349,5 @@ import {
|
|
|
349
349
|
};
|
|
350
350
|
return prettier.format(code, options).replace("\n", os.EOL);
|
|
351
351
|
*/
|
|
352
|
-
|
|
353
|
-
} catch (err) {
|
|
354
|
-
throw err;
|
|
355
|
-
}
|
|
352
|
+
});
|
|
356
353
|
}
|
package/source/generator.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// tslint:disable:no-console
|
|
7
7
|
import * as fs from "fs";
|
|
8
8
|
// node 14 onward : import { mkdir } from "fs/promises";
|
|
9
|
-
const { mkdir }= fs.promises;
|
|
9
|
+
const { mkdir } = fs.promises;
|
|
10
10
|
|
|
11
11
|
import * as path from "path";
|
|
12
12
|
import * as ts from "typescript";
|
|
@@ -80,7 +80,7 @@ function get_caller_source_filename() {
|
|
|
80
80
|
return schemaFile;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
export async function generateCode(schemaName: string, localSchemaFile: string, generatedCodeFolder?: string) {
|
|
83
|
+
export async function generateCode(schemaName: string, localSchemaFile: string, generatedCodeFolder?: string): Promise<void> {
|
|
84
84
|
const schemaTypescriptFile = schemaName + "_Schema.ts";
|
|
85
85
|
|
|
86
86
|
const currentFolder = process.cwd();
|
|
@@ -143,7 +143,7 @@ export async function generateCode(schemaName: string, localSchemaFile: string,
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
export async function generateTypeScriptCodeFromSchema(schemaName: string) {
|
|
146
|
+
export async function generateTypeScriptCodeFromSchema(schemaName: string): Promise<void> {
|
|
147
147
|
const currentFolder = process.cwd();
|
|
148
148
|
const schemaFilename = path.join(currentFolder, "schemas", schemaName + "_schema.ts");
|
|
149
149
|
const generatedCodeFolder = path.join(process.cwd(), "_generated_");
|
|
@@ -182,7 +182,7 @@ export async function registerObject(schema: string, generateCodeFolder?: string
|
|
|
182
182
|
return null;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
export function unregisterObject(schema:
|
|
185
|
+
export function unregisterObject(schema: { name: string }, folder: string): void {
|
|
186
186
|
const generateTypeScriptSource = get_class_TScript_filename(schema.name, folder);
|
|
187
187
|
if (fs.existsSync(generateTypeScriptSource)) {
|
|
188
188
|
fs.unlinkSync(generateTypeScriptSource);
|
package/source/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
/**
|
|
3
|
-
* @module node-opcua-generator
|
|
4
|
-
*/
|
|
5
|
-
export { generateTypeScriptCodeFromSchema, registerObject, unregisterObject } from "./generator";
|
|
6
|
-
export { generate } from "./generate_extension_object_code";
|
|
1
|
+
/* istanbul ignore file */
|
|
2
|
+
/**
|
|
3
|
+
* @module node-opcua-generator
|
|
4
|
+
*/
|
|
5
|
+
export { generateTypeScriptCodeFromSchema, registerObject, unregisterObject } from "./generator";
|
|
6
|
+
export { generate } from "./generate_extension_object_code";
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
/**
|
|
3
|
-
* @module node-opcua-generator
|
|
4
|
-
*/
|
|
5
|
-
// tslint:disable:no-console
|
|
6
|
-
import { generateTypeScriptCodeFromSchema } from "./generator";
|
|
7
|
-
|
|
8
|
-
console.log(process.argv);
|
|
9
|
-
|
|
10
|
-
async function main() {
|
|
11
|
-
const className = "LocalizedText";
|
|
12
|
-
generateTypeScriptCodeFromSchema(className);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
main()
|
|
16
|
-
.then()
|
|
17
|
-
.catch();
|
|
1
|
+
/* istanbul ignore file */
|
|
2
|
+
/**
|
|
3
|
+
* @module node-opcua-generator
|
|
4
|
+
*/
|
|
5
|
+
// tslint:disable:no-console
|
|
6
|
+
import { generateTypeScriptCodeFromSchema } from "./generator";
|
|
7
|
+
|
|
8
|
+
console.log(process.argv);
|
|
9
|
+
|
|
10
|
+
async function main() {
|
|
11
|
+
const className = "LocalizedText";
|
|
12
|
+
generateTypeScriptCodeFromSchema(className);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
main().then().catch();
|
package/source/utils/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./line_file";
|
|
2
|
-
export * from "./normalize_require_file";
|
|
1
|
+
export * from "./line_file";
|
|
2
|
+
export * from "./normalize_require_file";
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-utils
|
|
3
|
-
*/
|
|
4
|
-
import { writeFileSync } from "fs";
|
|
5
|
-
import { LineFile } from "node-opcua-utils";
|
|
6
|
-
|
|
7
|
-
export class LineFile1 extends LineFile {
|
|
8
|
-
constructor() {
|
|
9
|
-
super();
|
|
10
|
-
this.write("// --------- This code has been automatically generated !!! " + new Date().toISOString());
|
|
11
|
-
this.write("/**");
|
|
12
|
-
this.write(" * @module node-opcua-types");
|
|
13
|
-
this.write(" */");
|
|
14
|
-
}
|
|
15
|
-
public save(filename: string): void {
|
|
16
|
-
writeFileSync(filename, this.toString(), "ascii");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public saveFormat(filename: string, formatter: (code: string) => string): void {
|
|
20
|
-
const code = formatter(this.toString());
|
|
21
|
-
writeFileSync(filename, code, "ascii");
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-utils
|
|
3
|
+
*/
|
|
4
|
+
import { writeFileSync } from "fs";
|
|
5
|
+
import { LineFile } from "node-opcua-utils";
|
|
6
|
+
|
|
7
|
+
export class LineFile1 extends LineFile {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this.write("// --------- This code has been automatically generated !!! " + new Date().toISOString());
|
|
11
|
+
this.write("/**");
|
|
12
|
+
this.write(" * @module node-opcua-types");
|
|
13
|
+
this.write(" */");
|
|
14
|
+
}
|
|
15
|
+
public save(filename: string): void {
|
|
16
|
+
writeFileSync(filename, this.toString(), "ascii");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public saveFormat(filename: string, formatter: (code: string) => string): void {
|
|
20
|
+
const code = formatter(this.toString());
|
|
21
|
+
writeFileSync(filename, code, "ascii");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import * as path from "path";
|
|
2
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
3
|
-
/**
|
|
4
|
-
* @method normalize_require_file
|
|
5
|
-
* @param baseFolder
|
|
6
|
-
* @param fullPathToFile
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @example:
|
|
10
|
-
* normalize_require_file("/home/bob/folder1/","/home/bob/folder1/folder2/toto.js").should.eql("./folder2/toto");
|
|
11
|
-
*/
|
|
12
|
-
export function normalize_require_file(baseFolder: string, fullPathToFile: string): string {
|
|
13
|
-
let localFile = path.relative(baseFolder, fullPathToFile).replace(/\\/g, "/");
|
|
14
|
-
// append ./ if necessary
|
|
15
|
-
if (localFile.substr(0, 1) !== ".") {
|
|
16
|
-
localFile = "./" + localFile;
|
|
17
|
-
}
|
|
18
|
-
// remove extension
|
|
19
|
-
localFile = localFile.substr(0, localFile.length - path.extname(localFile).length);
|
|
20
|
-
return localFile;
|
|
21
|
-
}
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
3
|
+
/**
|
|
4
|
+
* @method normalize_require_file
|
|
5
|
+
* @param baseFolder
|
|
6
|
+
* @param fullPathToFile
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
* @example:
|
|
10
|
+
* normalize_require_file("/home/bob/folder1/","/home/bob/folder1/folder2/toto.js").should.eql("./folder2/toto");
|
|
11
|
+
*/
|
|
12
|
+
export function normalize_require_file(baseFolder: string, fullPathToFile: string): string {
|
|
13
|
+
let localFile = path.relative(baseFolder, fullPathToFile).replace(/\\/g, "/");
|
|
14
|
+
// append ./ if necessary
|
|
15
|
+
if (localFile.substr(0, 1) !== ".") {
|
|
16
|
+
localFile = "./" + localFile;
|
|
17
|
+
}
|
|
18
|
+
// remove extension
|
|
19
|
+
localFile = localFile.substr(0, localFile.length - path.extname(localFile).length);
|
|
20
|
+
return localFile;
|
|
21
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { LineFile1 } from "./line_file";
|
|
2
|
-
|
|
3
|
-
export interface WriteFunc {
|
|
4
|
-
(...args: string[]): void;
|
|
5
|
-
indent(): void;
|
|
6
|
-
pop(): void;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const makeWrite = (f: LineFile1) => {
|
|
10
|
-
const _f:
|
|
11
|
-
_f.indent = () => {
|
|
12
|
-
/** */
|
|
13
|
-
};
|
|
14
|
-
_f.pop = () => {
|
|
15
|
-
/** */
|
|
16
|
-
};
|
|
17
|
-
return _f;
|
|
18
|
-
};
|
|
1
|
+
import { LineFile1 } from "./line_file";
|
|
2
|
+
|
|
3
|
+
export interface WriteFunc {
|
|
4
|
+
(...args: string[]): void;
|
|
5
|
+
indent(): void;
|
|
6
|
+
pop(): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const makeWrite = (f: LineFile1): WriteFunc => {
|
|
10
|
+
const _f: WriteFunc = (...args: string[]) => f.write(...args);
|
|
11
|
+
_f.indent = () => {
|
|
12
|
+
/** */
|
|
13
|
+
};
|
|
14
|
+
_f.pop = () => {
|
|
15
|
+
/** */
|
|
16
|
+
};
|
|
17
|
+
return _f;
|
|
18
|
+
};
|