How to use the node-opcua-utils.LineFile function in node-opcua-utils

To help you get started, we’ve selected a few node-opcua-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-generator / source / generate_extension_object_code.ts View on Github external
import {
    EnumerationDefinitionSchema,
    FieldCategory,
    getStandartDataTypeFactory,
    StructuredTypeSchema,
} from "node-opcua-factory";
import { EnumeratedType, parseBinaryXSD, TypeDictionary } from "node-opcua-schemas";
import { LineFile } from "node-opcua-utils";
import { promisify } from "util";
import { writeStructuredType } from "./factory_code_generator";
// Xx import * as  prettier from "prettier";

const readFile = promisify(fs.readFile);
const parseBinaryXSD2 = promisify(parseBinaryXSD);

const f = new LineFile();

function write(...args: string[]) {
    f.write.apply(f, args);
}

function writeEnumeratedType(enumerationSchema: EnumerationDefinitionSchema) {

    // make sure there is a Invalid key in the enum => else insert one
    const hasInvalid = enumerationSchema.enumValues.hasOwnProperty("Invalid");
    if (!hasInvalid) {
        // xx console.log("Adding Invalid Enum entry on ", enumeratedType.name);
        enumerationSchema.enumValues[enumerationSchema.enumValues.Invalid = 0xFFFFFFFF] = "Invalid";
    }

    const arrayValues = Object.keys(enumerationSchema.enumValues)
        .filter((a: string) => a.match("[0-9]+"))
github node-opcua / node-opcua / packages / node-opcua-generator / src / factory_code_generator.js View on Github external
}
    if (typeof encoding_BinaryId === "string") {
        encoding_BinaryId = coerceNodeId(encoding_BinaryId);
    }

    const encodingBinaryNodeId =
        encoding_BinaryId === RUNTIME_GENERATED_ID ? encoding_BinaryId : makeExpandedNodeId(encoding_BinaryId);
    const encodingXmlNodeId = encoding_XmlId ? makeExpandedNodeId(encoding_XmlId) : null;

    schema.baseType = schema.baseType || "BaseUAObject";

    const baseclass = schema.baseType;

    const classname = schema.name;

    const f = new LineFile();

    function write() {
        f.write.apply(f, arguments);
    }

    resolve_schema_field_types(schema);
    const complexTypes = schema.fields.filter(function(field) {
        return field.category === "complex" && field.fieldType !== schema.name;
    });

    const folder_for_source_file = path.dirname(source_file);

    // -------------------------------------------------------------------------
    // - insert common require's
    // -------------------------------------------------------------------------
    write('"use strict";');
github node-opcua / node-opcua / packages / node-opcua-convert-nodeset-to-javascript / src / convert_nodeset_to_types.js View on Github external
function generateEnumerationCode(dataType, filename) {
    assert(typeof filename === "string");

    const dataTypeName = dataType.browseName.name.toString();
    assert(!hasEnumeration(dataTypeName));

    // create the enumeration file
    const f = new LineFile();
    f.write("// namespace " + dataType.namespaceUri.toString());
    f.write('const factories  = require("node-opcua-factory");');
    f.write('const makeNodeId = require("node-opcua-nodeid").makeNodeId;');

    f.write("const " + dataTypeName + "_Schema = {");
    f.write("  id:  makeNodeId(" + dataType.nodeId.value + "," + dataType.nodeId.namespace + "),");
    f.write("  name: '" + dataTypeName + "',");
    f.write("  namespace: '" + dataType.nodeId.namespace + "',");

    f.write("  enumValues: {");
    dataType.definition.forEach(function(pair) {
        f.write("     " + pair.name + ": " + pair.value + ",");
    });
    f.write("  }");
    f.write("};");
    f.write("exports." + dataTypeName + "_Schema = " + dataTypeName + "_Schema;");
github node-opcua / node-opcua / packages / node-opcua-generator / source / factory_code_generator.ts View on Github external
schema: StructuredTypeSchema,
  localSchemaFile: string,
  generatedTypescriptFilename: string
) {

    const className = schema.name;

    generatedObjectSchema[className] = generatedTypescriptFilename;

    schema.baseType = schema.baseType || "BaseUAObject";

    const baseClass = schema.baseType;

    check_schema_correctness(schema);

    const f = new LineFile();

    function write(...args: string[]) {
        f.write.apply(f, args);
    }

    // Xx resolve_schema_field_types(schema, generatedObjectSchema);

    const complexTypes = schema.fields.filter(
      (field: FieldType) => field.category === FieldCategory.complex && field.fieldType !== schema.name);

    const folderForSourceFile = path.dirname(generatedTypescriptFilename);

    // -------------------------------------------------------------------------
    // - insert common require's
    // -------------------------------------------------------------------------
    write("/**");
github node-opcua / node-opcua / packages / node-opcua-convert-nodeset-to-javascript / src / convert_nodeset_to_types.js View on Github external
function generateFileCode(namespace, schema, schema_folder) {
    assert(fs.existsSync(schema_folder, "schema folder must exist"));
    assert(typeof namespace === "string");

    const f = new LineFile();

    const name = schema.name;
    const hint = "$node-opcua/schemas/" + hashNamespace(namespace);

    f.write("// namespace " + namespace.toString());
    f.write('const  registerObject = require("node-opcua-factory").registerObject;');
    // f.write("registerObject('_generated_schemas|"+ name + "','_generated_schemas');");
    f.write("registerObject('" + hint + "|" + name + "');");

    //
    f.write('require("' + hint + "/" + name + '_schema");');

    // const filename = "../_generated_schemas/_auto_generated_"+ name;
    let filename = "$node-opcua/generated/_auto_generated_" + name;
    f.write("const " + name + ' = require("' + filename + '").' + name + ";");
    f.write("exports." + name + " = " + name + ";");
github node-opcua / node-opcua / packages / node-opcua-convert-nodeset-to-javascript / src / convert_nodeset_to_types.js View on Github external
function generateStructureCode(namespace, schema, schema_folder) {
    assert(fs.existsSync(schema_folder, "schema folder must exist"));
    const name = schema.name;

    const f = new LineFile();

    f.write('const factories  = require("node-opcua-factory");');
    f.write('const coerceNodeId = require("node-opcua-nodeid").coerceNodeId;');
    f.write("const " + schema.name + "_Schema = {");
    f.write("    id:  coerceNodeId('" + schema.id.toString() + "'),");
    f.write('    name: "' + name + '",');
    f.write("    fields: [");
    schema.fields.forEach(function(field) {
        f.write("       {");
        f.write('           name: "' + field.name + '",');
        f.write('           fieldType: "' + field.fieldType + '"');
        if (field.isArray) {
            f.write("         ,   isArray:" + (field.isArray ? "true" : false));
        }
        if (field.description) {
            f.write("          , documentation:" + ' "' + field.description + '" ');