Skip to content

Commit

Permalink
added CLI generation for selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
CrackerakiUA committed Oct 27, 2024
1 parent 8f54a60 commit f4037e9
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 15 deletions.
36 changes: 21 additions & 15 deletions runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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();
Expand Down Expand Up @@ -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");

Expand Down
42 changes: 42 additions & 0 deletions selector/crud/cli.js
Original file line number Diff line number Diff line change
@@ -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);
};
5 changes: 5 additions & 0 deletions selector/crud/component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<wselect
(modelChange)="onChange.emit($event)"
[items]="items"
[select]="value"
></wselect>
Empty file added selector/crud/component.scss
Empty file.
32 changes: 32 additions & 0 deletions selector/crud/component.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
42 changes: 42 additions & 0 deletions selector/default/cli.js
Original file line number Diff line number Diff line change
@@ -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);
};
5 changes: 5 additions & 0 deletions selector/default/component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<wselect
(modelChange)="onChange.emit($event)"
[items]="items"
[select]="value"
></wselect>
Empty file added selector/default/component.scss
Empty file.
27 changes: 27 additions & 0 deletions selector/default/component.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit f4037e9

Please sign in to comment.