From f4037e9d35d77ea920005b32c2cda448415cd7ea Mon Sep 17 00:00:00 2001 From: Honchar Denys Date: Sun, 27 Oct 2024 18:15:58 +0200 Subject: [PATCH] added CLI generation for selectors --- runner.js | 36 ++++++++++++++++------------ selector/crud/cli.js | 42 +++++++++++++++++++++++++++++++++ selector/crud/component.html | 5 ++++ selector/crud/component.scss | 0 selector/crud/component.ts | 32 +++++++++++++++++++++++++ selector/default/cli.js | 42 +++++++++++++++++++++++++++++++++ selector/default/component.html | 5 ++++ selector/default/component.scss | 0 selector/default/component.ts | 27 +++++++++++++++++++++ 9 files changed, 174 insertions(+), 15 deletions(-) create mode 100644 selector/crud/cli.js create mode 100644 selector/crud/component.html create mode 100644 selector/crud/component.scss create mode 100644 selector/crud/component.ts create mode 100644 selector/default/cli.js create mode 100644 selector/default/component.html create mode 100644 selector/default/component.scss create mode 100644 selector/default/component.ts diff --git a/runner.js b/runner.js index c8fe3ce..4b7c7b5 100644 --- a/runner.js +++ b/runner.js @@ -4,24 +4,32 @@ const fs = require("fs"); /* Angular Generate process */ const defaults = { - icon: { - default: path.join(__dirname, "icon", "default"), - }, - formcomponent: { - default: path.join(__dirname, "formcomponent", "default"), - }, alert: { default: path.join(__dirname, "alert", "default"), }, component: { default: path.join(__dirname, "component", "default"), }, + formcomponent: { + default: path.join(__dirname, "formcomponent", "default"), + }, + icon: { + default: path.join(__dirname, "icon", "default"), + }, + interface: { + default: path.join(__dirname, "interface", "default"), + }, loader: { default: path.join(__dirname, "loader", "default"), }, modal: { default: path.join(__dirname, "modal", "default"), }, + module: { + default: path.join(__dirname, "module", "default"), + crud: path.join(__dirname, "module", "crud"), + "crud server": path.join(__dirname, "module", "crudserver"), + }, page: { default: path.join(__dirname, "page", "default"), crud: path.join(__dirname, "page", "crud"), @@ -30,21 +38,17 @@ const defaults = { pipe: { default: path.join(__dirname, "pipe", "default"), }, - interface: { - default: path.join(__dirname, "interface", "default"), - }, popup: { default: path.join(__dirname, "popup", "default"), }, + selector: { + default: path.join(__dirname, "selector", "default"), + crud: path.join(__dirname, "selector", "crud"), + }, service: { default: path.join(__dirname, "service", "default"), crud: path.join(__dirname, "service", "crud"), - }, - module: { - default: path.join(__dirname, "module", "default"), - crud: path.join(__dirname, "module", "crud"), - "crud server": path.join(__dirname, "module", "crudserver"), - }, + } }; const initialize = (waw) => { waw.argv.shift(); @@ -221,6 +225,8 @@ module.exports.pipe = run("pipe", "core/pipes"); module.exports.popup = run("popup", "popups"); +module.exports.selector = run("selector", "core/selectors"); + module.exports.service = run("service", "core/services"); module.exports.s = run("service", "core/services"); diff --git a/selector/crud/cli.js b/selector/crud/cli.js new file mode 100644 index 0000000..c021686 --- /dev/null +++ b/selector/crud/cli.js @@ -0,0 +1,42 @@ +const fs = require("fs"); +const path = require("path"); + +module.exports = async (waw) => { + if (!fs.existsSync(waw.base)) { + fs.mkdirSync(waw.base, { recursive: true }); + } + + waw.base = path.join(waw.base, waw.name + "-selector"); + + let html = fs.readFileSync(waw.template + "/component.html", "utf8"); + html = html.split("CNAME").join(waw.Name); + html = html.split("NAME").join(waw.name); + fs.writeFileSync(waw.base + ".component.html", html, "utf8"); + + let scss = fs.readFileSync(waw.template + "/component.scss", "utf8"); + scss = scss.split("CNAME").join(waw.Name); + scss = scss.split("NAME").join(waw.name); + fs.writeFileSync(waw.base + ".component.scss", scss, "utf8"); + + let ts = fs.readFileSync(waw.template + "/component.ts", "utf8"); + ts = ts.split("FILENAME").join(waw.fileName); + ts = ts.split("CNAME").join(waw.Name); + ts = ts.split("NAME").join(waw.name); + fs.writeFileSync(waw.base + ".component.ts", ts, "utf8"); + + waw.add_code({ + file: process.cwd() + "/src/app/core/core.module.ts", + search: "/* selectors */", + replace: `/* selectors */\n\t${waw.Name}SelectorComponent,`, + }); + + waw.add_code({ + file: process.cwd() + "/src/app/core/core.module.ts", + search: "/* imports */", + replace: `/* imports */\nimport { ${waw.Name}SelectorComponent } from './selectors/${waw.name}/${waw.name}-selector.component';`, + }); + + console.log("Selector has been created"); + + process.exit(1); +}; diff --git a/selector/crud/component.html b/selector/crud/component.html new file mode 100644 index 0000000..8a058b1 --- /dev/null +++ b/selector/crud/component.html @@ -0,0 +1,5 @@ + diff --git a/selector/crud/component.scss b/selector/crud/component.scss new file mode 100644 index 0000000..e69de29 diff --git a/selector/crud/component.ts b/selector/crud/component.ts new file mode 100644 index 0000000..bc5dc78 --- /dev/null +++ b/selector/crud/component.ts @@ -0,0 +1,32 @@ +import { + Component, + EventEmitter, + Input, + OnChanges, + Output, + SimpleChanges +} from '@angular/core'; +import { CNAMEService, CNAME } from 'src/app/core/services/NAME.service'; + +@Component({ + selector: 'NAME-selector', + templateUrl: './NAME-selector.component.html', + styleUrls: ['./NAME-selector.component.scss'] +}) +export class CNAMESelectorComponent implements OnChanges { + @Input() value: string; + + @Output() onChange = new EventEmitter(); + + get items(): CNAME[] { + return this._NAMEService.NAMEs; + } + + constructor(private _NAMEService: CNAMEService) {} + + ngOnChanges(changes: SimpleChanges): void { + if (changes['value'] && !changes['value'].firstChange) { + this.value = changes['value'].currentValue; + } + } +} diff --git a/selector/default/cli.js b/selector/default/cli.js new file mode 100644 index 0000000..c021686 --- /dev/null +++ b/selector/default/cli.js @@ -0,0 +1,42 @@ +const fs = require("fs"); +const path = require("path"); + +module.exports = async (waw) => { + if (!fs.existsSync(waw.base)) { + fs.mkdirSync(waw.base, { recursive: true }); + } + + waw.base = path.join(waw.base, waw.name + "-selector"); + + let html = fs.readFileSync(waw.template + "/component.html", "utf8"); + html = html.split("CNAME").join(waw.Name); + html = html.split("NAME").join(waw.name); + fs.writeFileSync(waw.base + ".component.html", html, "utf8"); + + let scss = fs.readFileSync(waw.template + "/component.scss", "utf8"); + scss = scss.split("CNAME").join(waw.Name); + scss = scss.split("NAME").join(waw.name); + fs.writeFileSync(waw.base + ".component.scss", scss, "utf8"); + + let ts = fs.readFileSync(waw.template + "/component.ts", "utf8"); + ts = ts.split("FILENAME").join(waw.fileName); + ts = ts.split("CNAME").join(waw.Name); + ts = ts.split("NAME").join(waw.name); + fs.writeFileSync(waw.base + ".component.ts", ts, "utf8"); + + waw.add_code({ + file: process.cwd() + "/src/app/core/core.module.ts", + search: "/* selectors */", + replace: `/* selectors */\n\t${waw.Name}SelectorComponent,`, + }); + + waw.add_code({ + file: process.cwd() + "/src/app/core/core.module.ts", + search: "/* imports */", + replace: `/* imports */\nimport { ${waw.Name}SelectorComponent } from './selectors/${waw.name}/${waw.name}-selector.component';`, + }); + + console.log("Selector has been created"); + + process.exit(1); +}; diff --git a/selector/default/component.html b/selector/default/component.html new file mode 100644 index 0000000..8a058b1 --- /dev/null +++ b/selector/default/component.html @@ -0,0 +1,5 @@ + diff --git a/selector/default/component.scss b/selector/default/component.scss new file mode 100644 index 0000000..e69de29 diff --git a/selector/default/component.ts b/selector/default/component.ts new file mode 100644 index 0000000..b8aba9b --- /dev/null +++ b/selector/default/component.ts @@ -0,0 +1,27 @@ +import { + Component, + EventEmitter, + Input, + OnChanges, + Output, + SimpleChanges +} from '@angular/core'; + +@Component({ + selector: 'NAME-selector', + templateUrl: './NAME-selector.component.html', + styleUrls: ['./NAME-selector.component.scss'] +}) +export class CNAMESelectorComponent implements OnChanges { + @Input() items = ['Yes', 'No']; // put proper items here + + @Input() value: string; + + @Output() onChange = new EventEmitter(); + + ngOnChanges(changes: SimpleChanges): void { + if (changes['value'] && !changes['value'].firstChange) { + this.value = changes['value'].currentValue; + } + } +}