@mckit/schematics 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mckit/schematics",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "A blank schematics",
5
5
  "scripts": {
6
6
  "build": "tsc -p tsconfig.json",
@@ -0,0 +1,5 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ module.exports = {
3
+ // ...
4
+ plugins: [require('tailwindcss-primeui')]
5
+ };
package/src/init/index.js CHANGED
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.init = init;
4
4
  const child_process_1 = require("child_process");
5
+ const fs = require("fs");
6
+ const path = require("path");
5
7
  function runCommand(command, _context) {
6
8
  (0, child_process_1.exec)(command, (error, stdout, stderr) => {
7
9
  if (error) {
@@ -14,14 +16,78 @@ function runCommand(command, _context) {
14
16
  _context.logger.info(`✅ Result: ${stdout}`);
15
17
  });
16
18
  }
17
- function createFileWithTemplate(tree, path, template) {
18
- var _a;
19
- const templatePath = './files/' + template;
20
- if (tree.exists(templatePath)) {
21
- const content = ((_a = tree.read(templatePath)) === null || _a === void 0 ? void 0 : _a.toString()) || '';
22
- tree.create(path, content);
19
+ function createFileWithTemplate(tree, fileName, template) {
20
+ const filePath = path.join(__dirname, 'files/' + template);
21
+ if (fs.existsSync(filePath)) {
22
+ let content = fs.readFileSync(filePath, 'utf8');
23
+ tree.create(fileName, content);
23
24
  }
24
25
  }
26
+ function insertStringAt(originalString, stringToInsert, position) {
27
+ if (position > originalString.length) {
28
+ // Si la posición está fuera del rango, simplemente agrega el string al final
29
+ return originalString + stringToInsert;
30
+ }
31
+ // Dividir el original en dos partes: antes y después de la posición
32
+ const before = originalString.slice(0, position);
33
+ const after = originalString.slice(position);
34
+ // Insertar el string en la posición deseada
35
+ return before + stringToInsert + after;
36
+ }
37
+ function processStyles(tree, _context) {
38
+ const filePath = 'src/styles.scss';
39
+ if (!tree.exists(filePath)) {
40
+ return;
41
+ }
42
+ const fileBuffer = tree.read(filePath);
43
+ const content = fileBuffer ? fileBuffer.toString() : '';
44
+ if (content.includes('@use "tailwindcss";')) {
45
+ return;
46
+ }
47
+ // Create string variable with the new content
48
+ const newContent = `@use "tailwindcss";
49
+ @use "primeicons/primeicons.css";
50
+
51
+ body, html {
52
+ height: 100%;
53
+ margin: 0;
54
+ min-height: 100%;
55
+ }
56
+ `;
57
+ const updatedContent = newContent + content;
58
+ tree.overwrite(filePath, updatedContent);
59
+ }
60
+ function processAppConfig(tree, _context) {
61
+ const filePath = 'src/app/app.config.ts';
62
+ if (!tree.exists(filePath)) {
63
+ return;
64
+ }
65
+ const fileBuffer = tree.read(filePath);
66
+ let content = fileBuffer ? fileBuffer.toString() : '';
67
+ // Search position of the last import
68
+ const importPosition = content.lastIndexOf('import');
69
+ // Search position of the last ; after import position
70
+ const importEndPosition = content.indexOf(';', importPosition);
71
+ // Add the new import after the last import
72
+ content = insertStringAt(content, `
73
+ import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
74
+ import { providePrimeNG } from 'primeng/config';
75
+ import Aura from '@primeng/themes/aura';`, importEndPosition + 1);
76
+ // Search position of the last ]
77
+ const providerPosition = content.lastIndexOf(']');
78
+ // Add the new provider after the last provider
79
+ content = insertStringAt(content, ` provideAnimationsAsync(),
80
+ providePrimeNG({
81
+ theme: {
82
+ preset: Aura,
83
+ options: {
84
+ prefix: 'p',
85
+ darkModeSelector: '.dark',
86
+ cssLayer: false
87
+ }
88
+ }
89
+ })`, providerPosition - 1);
90
+ }
25
91
  // You don't have to export the function as default. You can also have more than one rule factory
26
92
  // per file.
27
93
  function init(_options) {
@@ -32,6 +98,12 @@ function init(_options) {
32
98
  runCommand('npm i tailwindcss-primeui --save', _context);
33
99
  // Create .postcssrc.json file from template
34
100
  createFileWithTemplate(tree, '.postcssrc.json', '.postcssrc.json.template');
101
+ // Config SCSS
102
+ processStyles(tree, _context);
103
+ // Create .postcssrc.json file from template
104
+ createFileWithTemplate(tree, 'tailwind.config.js', 'tailwind.config.js.template');
105
+ // Config app.config.ts
106
+ processAppConfig(tree, _context);
35
107
  return tree;
36
108
  };
37
109
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AA0BA,oBAaC;AAtCD,iDAAqC;AAErC,SAAS,UAAU,CAAC,OAAe,EAAE,QAA0B;IAC7D,IAAA,oBAAI,EAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;QACtC,IAAI,KAAK,EAAE,CAAC;YACV,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACnD,OAAO;QACT,CAAC;QACD,IAAI,MAAM,EAAE,CAAC;YACX,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,MAAM,EAAE,CAAC,CAAC;QAChD,CAAC;QACD,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,MAAM,EAAE,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAU,EAAE,IAAY,EAAE,QAAgB;;IACxE,MAAM,YAAY,GAAG,UAAU,GAAG,QAAQ,CAAC;IAC3C,IAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,CAAA,MAAA,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,0CAAE,QAAQ,EAAE,KAAI,EAAE,CAAC;QAC1D,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,iGAAiG;AACjG,YAAY;AACZ,SAAgB,IAAI,CAAC,QAAa;IAChC,OAAO,CAAC,IAAU,EAAE,QAA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ElF,uBAAuB;QACvB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAEjC,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const schematics_1 = require("@angular-devkit/schematics");
13
+ const testing_1 = require("@angular-devkit/schematics/testing");
14
+ const path = require("path");
15
+ const collectionPath = path.join(__dirname, '../collection.json');
16
+ describe('init', () => {
17
+ it('works', () => __awaiter(void 0, void 0, void 0, function* () {
18
+ const runner = new testing_1.SchematicTestRunner('schematics', collectionPath);
19
+ const tree = yield runner.runSchematic('init', {}, schematics_1.Tree.empty());
20
+ expect(tree.files[0]).toEqual('/.postcssrc.json');
21
+ expect(tree.files.length).toEqual(1);
22
+ }));
23
+ });
24
+ //# sourceMappingURL=index_spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index_spec.js","sourceRoot":"","sources":["index_spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2DAAkD;AAClD,gEAAyE;AACzE,6BAA6B;AAE7B,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;AAElE,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,EAAE,CAAC,OAAO,EAAE,GAAS,EAAE;QACrB,MAAM,MAAM,GAAG,IAAI,6BAAmB,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;QACrE,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,EAAE,iBAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAEjE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAClD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -6,7 +6,7 @@ exports.mcSchematic = mcSchematic;
6
6
  function mcSchematic(_options) {
7
7
  return (tree, _context) => {
8
8
  // Aquí puedes definir la lógica para generar archivos o modificar el proyecto
9
- tree.create('hello.txt', 'Hello, World!');
9
+ //tree.create('hello.txt', 'Hello, World!');
10
10
  return tree;
11
11
  };
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAKA,kCAMC;AARD,iGAAiG;AACjG,YAAY;AACZ,SAAgB,WAAW,CAAC,QAAa;IACvC,OAAO,CAAC,IAAU,EAAE,QAA0B,EAAE,EAAE;QAChD,8EAA8E;QAC9E,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAKA,kCAMC;AARD,iGAAiG;AACjG,YAAY;AACZ,SAAgB,WAAW,CAAC,QAAa;IACvC,OAAO,CAAC,IAAU,EAAE,QAA0B,EAAE,EAAE;QAChD,8EAA8E;QAC9E,4CAA4C;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC"}
@@ -1,14 +0,0 @@
1
- import { NgModule } from '@angular/core';
2
- import { CommonModule } from '@angular/common';
3
- import { FormsModule } from '@angular/forms';
4
- import { <%= classify(name) %>RoutingModule } from './<%= dasherize(name) %>-routing.module';
5
-
6
- @NgModule({
7
- declarations: [],
8
- imports: [
9
- CommonModule,
10
- <%= classify(name) %>RoutingModule,
11
- FormsModule,
12
- ]
13
- })
14
- export class <%= classify(name) %>Module { }