From c0915b550a9d9ed645f6041e8d60cece84f7b147 Mon Sep 17 00:00:00 2001 From: Joao Santos Date: Wed, 6 Jan 2021 17:32:31 +0000 Subject: [PATCH] Fixed issues of this version --- .gitignore | 1 + README.md | 90 +++---------------- generators/app/index.ts | 6 +- generators/driver/index.ts | 11 ++- .../templates/_iot_.connect_iot_package_done | 0 generators/driver/templates/_iot_.gitignore | 1 - generators/driver/templates/_iot_.npmignore | 3 +- generators/driver/templates/_iot_.npmrc | 3 +- .../driver/templates/_iot_.vscode/launch.json | 24 +++++ generators/driver/templates/packConfig.json | 18 ++++ generators/driver/templates/package.json | 7 +- .../templates/src/driverImplementation.ts | 9 +- generators/driver/templates/src/index.ts | 5 +- .../driver/templates/src/inversify.config.ts | 4 +- generators/fontgen/index.ts | 2 +- generators/tasksPackage/index.ts | 9 +- .../templates/_iot_.connect_iot_package_done | 0 .../tasksPackage/templates/_iot_.gitignore | 2 +- .../tasksPackage/templates/_iot_.npmignore | 4 +- .../tasksPackage/templates/font/svg/font.js | 10 +++ .../tasksPackage/templates/packConfig.json | 7 ++ .../tasksPackage/templates/package.json | 5 +- .../templates/test/unit/tsconfig.json | 2 +- package.json | 2 +- 24 files changed, 120 insertions(+), 105 deletions(-) create mode 100644 generators/driver/templates/_iot_.connect_iot_package_done create mode 100644 generators/driver/templates/_iot_.vscode/launch.json create mode 100644 generators/driver/templates/packConfig.json create mode 100644 generators/tasksPackage/templates/_iot_.connect_iot_package_done create mode 100644 generators/tasksPackage/templates/font/svg/font.js create mode 100644 generators/tasksPackage/templates/packConfig.json diff --git a/.gitignore b/.gitignore index 2700d52..7d033e4 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ jspm_packages # Custom Ignore settings *.js !gulpfile.js +!font.js *.map *.d.ts test-results.xml diff --git a/README.md b/README.md index f954785..ac14f9f 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,16 @@ npm i -g yo To start using this generator, it is advisable to have it installed globally (-g setting in NPM). ``` -npm i -g @criticalmanufacturing/generator-iot +npm i -g @criticalmanufacturing/generator-iot@72x ``` +> **Note** Starting from 7.2.0, each combination of Critical Manufacturing MES version (Major + Minor) will have a dedicated generator to make it easier to keep compatibility. +> +> For versions 7.2.0, 7.2.1, 7.2.2, ..., 7.2.\*, use the tag `72x` (`npm i -g @criticalmanufacturing/generator-iot@72x`) +> +> For versions 8.0.0, 8.0.1, 8.0.2, ..., 8.0.\*, use the tag `80x` (`npm i -g @criticalmanufacturing/generator-iot@80x`) + # Apps + To see at any time, the list of available apps, open a terminal window and run: ``` yo @criticalmanufacturing/iot @@ -26,16 +33,6 @@ For both multiple and single choice, use the cursor (Up/Down) to move between th All questions are considered answered when the Enter key is pressed. -## Config -The `Connect IoT` architecture require a configuration file with definitions and instruction mandatory. This App helps creating it. - -On the location where you want to store the configs, open a terminal window and run: - -``` -yo @criticalmanufacturing/iot:config -``` -Answer all questions and the file will be created and can be used immediately. - ## tasksPackage Use this app to create a new custom package structure help you getting started. Of course, you still need to implement the tasks and converters (there are also apps to help you) @@ -126,70 +123,7 @@ If you are extending this package, it is easier to have it linked locally. Run t # Version History -**Next** - - History will be maintained in the Github page for now on - -**1.4.4** -- Removed Chokidar dependency from driver -- Removed Dev dependency from driver package.json -- Added gulpfile.js into driver -- Fixed compiler errors in driver -- Added missing entries in config (monitorApplication, SecurityPortal) - -**1.4.3** -- Added gulp + codelyzer as devDependencies for taskPackage - -**1.4.2** -- Added fonts section in taskPackage metadata - -**1.4.1** -- Updated template driver for ssl implementation - -**1.4.0** -- Updated dependencies versions for driver package -- Updated dependencies versions for tasks packages -- Fix driver source code to support new version of typescript -- Add entityName command parameter in driver -- Add commandParameter extension file in driver -- Add settings in tasksPackage to suppress generated files from VSCode - -**1.3.1** -- Removed invalid entries from .gitignore file -- removed tgz file from previous package -- removed development entry from .npmrc - -**1.3.0** -- Fixed missing entries in task settings code behind -- Fixed typos in task -- Updated gulpfile.js in tasksPackage -- Fixed dependencies in taskPackage -- Added template .less file in tasks -- Added missing comments in task designer file - -**1.2.3** -- Several fixes and cleanup on the driver template - -**1.2.2** -- Added missing gulpfile.js file back into tasksPackage template - -**1.2.1** -- Added componentId to driver app command line - -**1.2.0** -- Updated driver app - -**1.1.0** -- Added tasksPackage app -- Added task app -- Small bug fixes - -**1.0.2** -- Updated driver template - -**1.0.1** -- Fixed template generation of the driver with hidden files included -- Added missing IoT datatype Boolean -- Added test example for converter - -**1.0.0** -- First version +History is maintained in the Github page + +https://github.com/criticalmanufacturing/generator-iot/releases + diff --git a/generators/app/index.ts b/generators/app/index.ts index c8ed9bf..4c816e4 100644 --- a/generators/app/index.ts +++ b/generators/app/index.ts @@ -20,9 +20,9 @@ class GeneratorApp extends ConnectIoTGenerator { this.log(this.usage()); // .help() show all command line parameters this.log(""); - this.log(chalk.cyan("Setup apps:")); - this.log(" " + chalk.yellow("config") + " -> Create a configuration file to use with Automation Manager"); - this.log(""); + // this.log(chalk.cyan("Setup apps:")); + // this.log(" " + chalk.yellow("config") + " -> Create a configuration file to use with Automation Manager"); + // this.log(""); this.log(chalk.cyan("Development apps:")); this.log(" " + chalk.yellow("tasksPackage") + " -> Create a new basic package code for custom Tasks/Converters"); this.log(" " + chalk.yellow("task") + " -> Create the skeleton for a Task"); diff --git a/generators/driver/index.ts b/generators/driver/index.ts index 2b3cf98..1bd903a 100644 --- a/generators/driver/index.ts +++ b/generators/driver/index.ts @@ -37,19 +37,20 @@ class DriverConfig extends ConnectIoTGenerator { ["_iot_.gitattributes", ".gitattributes"], ["_iot_.gitignore", ".gitignore"], ["_iot_.npmignore", ".npmignore"], - ["_iot_.npmrc", ".npmrc"] + ["_iot_.npmrc", ".npmrc"], + ["_iot_.connect_iot_package_done", ".connect_iot_package_done"], ]); filesWithRename.forEach((value, key) => { this.fs.copyTpl(this.templatePath(key), this.destinationPath(this.values.directory, value), this.values); }); - let files: string[] = ["package.json", "README.md", "tsconfig.json", "tslint.json", "gulpfile.js"]; + let files: string[] = ["package.json", "README.md", "tsconfig.json", "tslint.json", "gulpfile.js", "packConfig.json"]; files.forEach((template) => { this.fs.copyTpl(this.templatePath(template), this.destinationPath(this.values.directory, template), this.values); }); // Visual Studio settings - files = ["settings.json"]; + files = ["settings.json", "launch.json"]; files.forEach((template) => { this.fs.copyTpl(this.templatePath("_iot_.vscode", template), this.destinationPath(this.values.directory, ".vscode", template), this.values); }); @@ -77,7 +78,11 @@ class DriverConfig extends ConnectIoTGenerator { } end() { + this.log(""); + this.log(""); + this.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); this.log("For this version, it is recommended to run the command 'npm dedupe' after installing the npm packages."); + this.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } } diff --git a/generators/driver/templates/_iot_.connect_iot_package_done b/generators/driver/templates/_iot_.connect_iot_package_done new file mode 100644 index 0000000..e69de29 diff --git a/generators/driver/templates/_iot_.gitignore b/generators/driver/templates/_iot_.gitignore index a9dff75..cadd56c 100644 --- a/generators/driver/templates/_iot_.gitignore +++ b/generators/driver/templates/_iot_.gitignore @@ -42,4 +42,3 @@ jspm_packages *.d.ts test-results.xml coverage/ -.connect_iot_package_done diff --git a/generators/driver/templates/_iot_.npmignore b/generators/driver/templates/_iot_.npmignore index f4a615f..b71a6a2 100644 --- a/generators/driver/templates/_iot_.npmignore +++ b/generators/driver/templates/_iot_.npmignore @@ -5,4 +5,5 @@ test coverage tsconfig.json tslint.json -.git* \ No newline at end of file +.git* +.connect_iot_package_done diff --git a/generators/driver/templates/_iot_.npmrc b/generators/driver/templates/_iot_.npmrc index 2db2232..83db665 100644 --- a/generators/driver/templates/_iot_.npmrc +++ b/generators/driver/templates/_iot_.npmrc @@ -1,2 +1 @@ -registry = "http://cmf-nuget:4873/" -//cmf-nuget:4873/:_authToken="csNoanwPNA0SGF/V/Q+CRJWzHc/lRymCeBWSRGDZ+kY=" \ No newline at end of file +registry = "http://:4873/" diff --git a/generators/driver/templates/_iot_.vscode/launch.json b/generators/driver/templates/_iot_.vscode/launch.json new file mode 100644 index 0000000..713f463 --- /dev/null +++ b/generators/driver/templates/_iot_.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Start Driver (<%= identifier %>)", + "program": "${workspaceRoot}/src/index.js", + "args": [ + "--dev", + "--id=", + "--mp=", + "--config=/config.json" + ], + // "preLaunchTask": "manager-build", + "cwd": "${workspaceRoot}", + "outFiles": [], + "outputCapture": "std" + } + ] +} \ No newline at end of file diff --git a/generators/driver/templates/packConfig.json b/generators/driver/templates/packConfig.json new file mode 100644 index 0000000..9c88640 --- /dev/null +++ b/generators/driver/templates/packConfig.json @@ -0,0 +1,18 @@ +{ + "type": "Component", + + "postActions": [ + { "type": "DeleteFile", "source": "${Temp}/completion.sh.hbs" }, + { "type": "DeleteDirectory", "source": "${Temp}/src" }, + { "type": "DeleteDirectory", "source": "${Temp}/build" }, + { "type": "DeleteDirectory", "source": "${Temp}/locales" }, + { "type": "DeleteDirectory", "source": "${Temp}/addonsHandler" } + ], + + "information": [ + "Add other instructions in the postActions section", + "according to the result of the pack process of your", + "driver. There is no 'right' recipe. It will always", + "depend on the modules you are using." + ] +} \ No newline at end of file diff --git a/generators/driver/templates/package.json b/generators/driver/templates/package.json index bf81d6f..3023a0d 100644 --- a/generators/driver/templates/package.json +++ b/generators/driver/templates/package.json @@ -13,7 +13,9 @@ "vs:buildAndTest": "npm run build && npm run vs:test", "vs:test": "node node_modules/istanbul/lib/cli cover node_modules/mocha/bin/_mocha --report cobertura --report lcov test/*.js test/**/*.js -- --timeout 30000 --exit --reporter mocha-junit-reporter --reporter-options mochaFile=./test/test-results.xml", "pretest": "npm run build", - "watch": "npm run build -- -w | node node_modules/mocha/bin/mocha --timeout 30000 --exit --reporter min -w test/*.test.js test/**/*.test.js" + "watch": "npm run build -- -w | node node_modules/mocha/bin/mocha --timeout 30000 --exit --reporter min -w test/*.test.js test/**/*.test.js", + + "postinstall": "if exist node_modules\\vinyl-fs\\node_modules\\graceful-fs ren node_modules\\vinyl-fs\\node_modules\\graceful-fs DoNotUse-graceful-fs_incompatible_with_node12" }, "keywords": [ "CMF", @@ -21,6 +23,7 @@ "Agent" ], "devDependencies": { + "@criticalmanufacturing/dev-tasks": "dev-72x", "@types/chai": "^4.1.7", "@types/chai-spies": "^1.0.0", "@types/core-js": "^2.5.0", @@ -31,6 +34,8 @@ "@types/uuid": "^3.4.4", "@types/yargs": "^13.0.0", "chai": "^4.2.0", + "graceful-fs": "4.2.3", + "gulp": "3.9.1", "chai-spies": "^1.0.0", "istanbul": "^0.4.5", "mocha": "^6.1.3", diff --git a/generators/driver/templates/src/driverImplementation.ts b/generators/driver/templates/src/driverImplementation.ts index b7f45c3..ab27b0e 100644 --- a/generators/driver/templates/src/driverImplementation.ts +++ b/generators/driver/templates/src/driverImplementation.ts @@ -3,6 +3,7 @@ import { CommunicationState, PropertyValuePair } from "@criticalmanufacturing/co import { Property, EventOccurrence, PropertyValue, Command, Event as EquipmentEvent, DeviceDriverBase, CommandParameter } from "@criticalmanufacturing/connect-iot-driver"; import { <%= identifier %>CommunicationSettings, <%= identifierCamel %>DefaultCommunicationSettings, validateCommunicationParameters } from "./communicationSettings"; import { validateProperties, validateEvents, validateEventProperties, validateCommands, validateCommandParameters } from "./extendedData/index"; +import { Utils } from "@criticalmanufacturing/connect-iot-common"; import { TYPES } from "./types"; @injectable() @@ -174,8 +175,8 @@ export class <%= identifier %>DeviceDriver extends DeviceDriverBase { // Fill results and check if the trigger properties have been the cause of the event occurrence if (values) { for (let eventProperty of event.properties) { - if (values.hasOwnProperty(eventProperty.deviceId)) { - let value: any = (values)[eventProperty.deviceId]; + if (values.has(eventProperty.deviceId)) { + let value: any = values.get(eventProperty.deviceId); let propertyValue: PropertyValue = { propertyName: eventProperty.name, @@ -214,8 +215,8 @@ export class <%= identifier %>DeviceDriver extends DeviceDriverBase { if (raw == null) return(undefined); - // Convert the value - // ... + // Convert the value (this is an example) + raw = Utils.convertValueToType(raw, toType); // return same thing (could not convert it?) return(raw); diff --git a/generators/driver/templates/src/index.ts b/generators/driver/templates/src/index.ts index af5494c..da8a2fe 100644 --- a/generators/driver/templates/src/index.ts +++ b/generators/driver/templates/src/index.ts @@ -45,6 +45,7 @@ if (yargs.argv) { pid: process.pid, componentId: yargs.argv.componentId || "Driver<%= identifier %>", entityName: yargs.argv.entityName, + managerId: yargs.argv.managerId, }); // Parse and validate configuration @@ -83,10 +84,10 @@ if (yargs.argv) { } }).then(() => { logger.info(`<%= identifier %> Driver process started with success`); - }).catch((error) => { + }).catch((error: Error) => { logger.error(`<%= identifier %> Driver process failed to start!`); logger.error(error.message); - logger.error(error.stack); + logger.error(error.stack || ""); const internalLogger: any = ((logger))._winston; internalLogger.on("finish", () => { diff --git a/generators/driver/templates/src/inversify.config.ts b/generators/driver/templates/src/inversify.config.ts index 21c52a2..7ea71c0 100644 --- a/generators/driver/templates/src/inversify.config.ts +++ b/generators/driver/templates/src/inversify.config.ts @@ -7,9 +7,9 @@ import { <%= identifier %>DeviceDriver } from "./driverImplementation"; const container = new Container(); container.parent = driverContainer; -container.parent.bind(TYPES.Injector).toConstantValue(container); +container.parent?.bind(TYPES.Injector).toConstantValue(container); // Must place in parent otherwise the driver(common) will not find this -container.parent.bind(COMMUNICATION_TYPES.Device.Driver).to(<%= identifier %>DeviceDriver).inSingletonScope(); +container.parent?.bind(COMMUNICATION_TYPES.Device.Driver).to(<%= identifier %>DeviceDriver).inSingletonScope(); export { container }; diff --git a/generators/fontgen/index.ts b/generators/fontgen/index.ts index be3e977..2c1731d 100644 --- a/generators/fontgen/index.ts +++ b/generators/fontgen/index.ts @@ -8,7 +8,7 @@ class GeneratorFontGen extends ConnectIoTGenerator { super(args, opts); if (!this.fs.exists(this.destinationPath("font.js"))) { - this.env.error(new Error(`Unable to find 'font.js' file. Make sure you are running the command from the location where you have the fonts (SVGs + font.js metadata file)`)); + this.env.error(new Error(`Unable to find 'font.js' file in the current directory. Make sure you are running the command from the location where you have the fonts (SVGs + font.js metadata file)`)); } } diff --git a/generators/tasksPackage/index.ts b/generators/tasksPackage/index.ts index 26062b8..f1b29ea 100644 --- a/generators/tasksPackage/index.ts +++ b/generators/tasksPackage/index.ts @@ -6,6 +6,8 @@ class GeneratorTasksPackage extends ConnectIoTGenerator { directory: "controller-engine-custom-tasks", packageName: "@criticalmanufacturing/connect-iot-controller-engine-custom-tasks", packageVersion: "7.2.0", + identifier: "MyTasksPackage", + identifierLower: "" }; constructor(args: any, opts: any) { @@ -17,6 +19,8 @@ class GeneratorTasksPackage extends ConnectIoTGenerator { this.values.directory = await this.askScalar("What is the identifier (directory name)?", ValueType.Text, this.values.directory); this.values.packageName = await this.askScalar("What is the full package name?", ValueType.Text, this.values.packageName); this.values.packageVersion = await this.askScalar("What is the package version?", ValueType.Text, this.values.packageVersion); + this.values.identifier = await this.askScalar("What is the package identifier (Do not enter spaces)?", ValueType.Text, this.values.identifier); + this.values.identifierLower = this.values.identifier.trim().toLocaleLowerCase(); } /** Copy all files to destination directory with the settings defined in the previous step */ @@ -26,13 +30,14 @@ class GeneratorTasksPackage extends ConnectIoTGenerator { ["_iot_.gitattributes", ".gitattributes"], ["_iot_.gitignore", ".gitignore"], ["_iot_.npmignore", ".npmignore"], - ["_iot_.npmrc", ".npmrc"] + ["_iot_.npmrc", ".npmrc"], + ["_iot_.connect_iot_package_done", ".connect_iot_package_done"], ]); filesWithRename.forEach((value, key) => { this.fs.copyTpl(this.templatePath(key), this.destinationPath(this.values.directory, value), this.values); }); - let files: string[] = ["package.json", "README.md", "tsconfig.json", "tslint.json", "gulpfile.js"]; + let files: string[] = ["package.json", "README.md", "tsconfig.json", "tslint.json", "gulpfile.js", "packConfig.json"]; files.forEach((template) => { this.fs.copyTpl(this.templatePath(template), this.destinationPath(this.values.directory, template), this.values); }); diff --git a/generators/tasksPackage/templates/_iot_.connect_iot_package_done b/generators/tasksPackage/templates/_iot_.connect_iot_package_done new file mode 100644 index 0000000..e69de29 diff --git a/generators/tasksPackage/templates/_iot_.gitignore b/generators/tasksPackage/templates/_iot_.gitignore index 730108b..21ef0ac 100644 --- a/generators/tasksPackage/templates/_iot_.gitignore +++ b/generators/tasksPackage/templates/_iot_.gitignore @@ -47,6 +47,6 @@ coverage/ test/e2e/obj/ test/**/bin -.connect_iot_package_done + !font/**/*.css !font/svg/font.js \ No newline at end of file diff --git a/generators/tasksPackage/templates/_iot_.npmignore b/generators/tasksPackage/templates/_iot_.npmignore index d2e7c4c..cff29f4 100644 --- a/generators/tasksPackage/templates/_iot_.npmignore +++ b/generators/tasksPackage/templates/_iot_.npmignore @@ -10,4 +10,6 @@ coverage tsconfig.json tslint.json .git* -font/svg \ No newline at end of file +font/svg +.connect_iot_package_done +packConfig.json diff --git a/generators/tasksPackage/templates/font/svg/font.js b/generators/tasksPackage/templates/font/svg/font.js new file mode 100644 index 0000000..d12d130 --- /dev/null +++ b/generators/tasksPackage/templates/font/svg/font.js @@ -0,0 +1,10 @@ +fontDef = { + "font": { + "fontname": "<%= identifierLower %>tasksiot", + "fullname": "<%= identifier %> Tasks IoT", + "familyname": "<%= identifier %> Tasks IoT", + "version": 0.1, + "prefix": "<%= identifierLower %>-tasks-connect-iot" + } +} +module.exports = fontDef; diff --git a/generators/tasksPackage/templates/packConfig.json b/generators/tasksPackage/templates/packConfig.json new file mode 100644 index 0000000..a3127a7 --- /dev/null +++ b/generators/tasksPackage/templates/packConfig.json @@ -0,0 +1,7 @@ +{ + "type": "TasksPackage", + "postActions": [ + { "type": "CopyDirectory", "source": "font", "destination": "${Temp}/font" }, + { "type": "DeleteDirectory", "source": "${Temp}/font/svg" } + ] +} \ No newline at end of file diff --git a/generators/tasksPackage/templates/package.json b/generators/tasksPackage/templates/package.json index b791d6b..dffaf0b 100644 --- a/generators/tasksPackage/templates/package.json +++ b/generators/tasksPackage/templates/package.json @@ -14,7 +14,9 @@ "vs:buildAndTest": "npm run build && npm run vs:test", "vs:test": "node node_modules/istanbul/lib/cli cover node_modules/mocha/bin/_mocha --report cobertura --report lcov test/*.test.js test/**/*.test.js -- --timeout 5000 --exit --reporter mocha-junit-reporter --reporter-options mochaFile=./test/test-results.xml", "pretest": "npm run build", - "watch": "npm run build -- -w | node node_modules/mocha/bin/mocha --timeout 5000 --exit --reporter min -w test/*.test.js test/**/*.test.js" + "watch": "npm run build -- -w | node node_modules/mocha/bin/mocha --timeout 5000 --exit --reporter min -w test/*.test.js test/**/*.test.js", + + "postinstall": "if exist node_modules\\vinyl-fs\\node_modules\\graceful-fs ren node_modules\\vinyl-fs\\node_modules\\graceful-fs _graceful-fs_incompatible_with_node12" }, "keywords": [ "CMF", @@ -27,6 +29,7 @@ "@types/chai-spies": "^1.0.0", "@types/mocha": "^5.2.6", "@types/node": "^11.13.5", + "graceful-fs": "4.2.3", "chai": "^4.2.0", "chai-spies": "^1.0.0", "cmf.core": "", diff --git a/generators/tasksPackage/templates/test/unit/tsconfig.json b/generators/tasksPackage/templates/test/unit/tsconfig.json index 7b1c3da..08728fe 100644 --- a/generators/tasksPackage/templates/test/unit/tsconfig.json +++ b/generators/tasksPackage/templates/test/unit/tsconfig.json @@ -23,4 +23,4 @@ "strictFunctionTypes": false, "strictPropertyInitialization": false } -} \ No newline at end of file +} diff --git a/package.json b/package.json index a591286..9f11ba5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@criticalmanufacturing/generator-iot", - "version": "7.2.0", + "version": "7.2.2", "description": "Connect IoT Scaffolding", "files": [ "generators/*.js",