Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
);
} else {
write(
`import { ${field.fieldType} } from "../source/imports";`
);
}
}
// -------------------------------------------------------------------------
// - insert definition of base class
// -------------------------------------------------------------------------
if (baseClass !== "BaseUAObject") {
const filename = get_class_tscript_filename_local(baseClass);
const localFilename = normalize_require_file(folderForSourceFile, filename);
// xx console.log(" ===> filename", filename, localFilename, fs.existsSync(filename));
if (fs.existsSync(filename)) {
assert(!localFilename.match(/\\/));
write("import { " + baseClass + " } from \"" + localFilename + "\";");
} else {
write("const " + baseClass + " = getStructureTypeConstructor(\"" + baseClass + "\");");
}
}
write_expose_encoder_decoder(write, schema);
writeStructuredType(write, schema);
f.saveFormat(generatedTypescriptFilename, (code) => {
const options: prettier.Options = {
// if binaryEncodingNodeId is in the standard factory => no need to overwrite
if (!bForce && (hasConstructor(dataType.binaryEncodingNodeId) || dataType.binaryEncodingNodeId.namespace === 0)) {
//xx console.log(chalk.bgYellow("Skipping standard constructor") ," for dataType" ,dataType.browseName.toString());
return getConstructor(dataType.binaryEncodingNodeId);
}
const schema = constructSchema(addressSpace, dataType);
generateFileCode(namespaceUri, schema, schema_folder);
generateStructureCode(namespaceUri, schema);
const filename = getSchemaSourceFile(namespaceUri, schema.name, "");
const relative_filename = normalize_require_file(__dirname, filename);
const constructor = require(relative_filename)[schema.name];
assert(_.isFunction(constructor), "expecting a constructor here");
return constructor;
}
`import { ${schemaObjName} } from "${localSchemaFile}";`
);
write("const schema = " + schemaObjName + ";");
// -------------------------------------------------------------------------
// - insert definition of complex type used by this class
// -------------------------------------------------------------------------
const tmpMap: any = {};
for (const field of complexTypes) {
if (tmpMap.hasOwnProperty(field.fieldType)) {
continue;
}
tmpMap[field.fieldType] = 1;
const filename = get_class_tscript_filename_local(field.fieldType);
const localFilename = normalize_require_file(folderForSourceFile, filename);
if (fs.existsSync(filename)) {
// xx write("const " + field.fieldType + ' = require("' + local_filename + '").' + field.fieldType + ";");
write(
`import { ${field.fieldType} } from "${localFilename}";`
);
} else {
write(
`import { ${field.fieldType} } from "../source/imports";`
);
}
}
// -------------------------------------------------------------------------
// - insert definition of base class
// -------------------------------------------------------------------------
//const Enumeration_Schema = {
// id: dataType.nodeId,
// name: dataType.browseName.toString(),
// enumValues: {}
//};
//
//dataType.definition.forEach(function (pair) {
// Enumeration_Schema.enumValues[pair.name] = parseInt(pair.value, 10);
//});
const namespace = dataType.namespaceUri;
const filename = getSchemaSourceFile(namespace, dataType.browseName.toString(), "enum");
generateEnumerationCode(dataType, filename);
const relative_filename = normalize_require_file(__dirname, filename);
return require(relative_filename)[dataType.browseName.toString()];
}
assert(fs.existsSync(code_generator_script), "cannot get code generator");
const code_generator_script_mtime = new Date(fs.statSync(code_generator_script).mtime).getTime();
code_generator_is_newer = (generated_source_mtime <= code_generator_script_mtime );
}
const generated_source_is_outdated = (!generated_source_exists || code_generator_is_newer || schema_file_is_newer);
if (generated_source_is_outdated) {
debugLog(" generated_source_is_outdated ", schema.name, " to ", generated_source);
if (exports.verbose) {
console.log(" generating ", schema.name, " in ", generated_source);
}
code = produce_code(schema_file, schema_name, generated_source);
}
schema.generate_source = generated_source;
const local_generated_source = normalize_require_file(__dirname, generated_source);
return require(local_generated_source)[schema.name];
}