@ronas-it/nx-generators 0.1.3 → 0.2.0

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/generators.json CHANGED
@@ -14,6 +14,16 @@
14
14
  "factory": "./src/generators/repo-config/generator",
15
15
  "schema": "./src/generators/repo-config/schema.json",
16
16
  "description": "repo-config generator"
17
+ },
18
+ "react-lib": {
19
+ "factory": "./src/generators/react-lib/generator",
20
+ "schema": "./src/generators/react-lib/schema.json",
21
+ "description": "react-lib generator"
22
+ },
23
+ "react-component": {
24
+ "factory": "./src/generators/react-component/generator",
25
+ "schema": "./src/generators/react-component/schema.json",
26
+ "description": "react-component generator"
17
27
  }
18
28
  }
19
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronas-it/nx-generators",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "NX generators for Ronas IT projects",
5
5
  "license": "MIT",
6
6
  "author": "Ronas IT",
@@ -1,6 +1,5 @@
1
1
  declare const _default: {
2
2
  lint: string;
3
3
  format: string;
4
- verify: string;
5
4
  };
6
5
  export default _default;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = {
4
- 'lint': 'eslint ./',
4
+ 'lint': 'npx tsc && npx eslint ./',
5
5
  'format': 'npx prettier --write . && npm run lint -- --fix',
6
- 'verify': 'npx tsc',
7
6
  };
8
7
  //# sourceMappingURL=scripts.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../../../plugin/src/generators/code-checks/scripts.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACb,MAAM,EAAE,WAAW;IACnB,QAAQ,EAAE,iDAAiD;IAC3D,QAAQ,EAAE,SAAS;CACpB,CAAA"}
1
+ {"version":3,"file":"scripts.js","sourceRoot":"","sources":["../../../../../plugin/src/generators/code-checks/scripts.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACb,MAAM,EAAE,0BAA0B;IAClC,QAAQ,EAAE,iDAAiD;CAC5D,CAAA"}
@@ -1,5 +1,5 @@
1
1
  export interface ExpoAppGeneratorSchema {
2
2
  name: string;
3
3
  directory: string;
4
- formatName?: (value: string) => string;
4
+ formatName?: (value: string, withoutSpaces?: boolean) => string;
5
5
  }
@@ -0,0 +1,10 @@
1
+ import React, { Fragment, ReactElement } from 'react';
2
+
3
+ interface <%= formatName(name, true) %>Props {
4
+ // TODO: Describe props
5
+ }
6
+
7
+ export function <%= formatName(name, true) %>(props: <%= formatName(name, true) %>Props): ReactElement {
8
+ // TODO: Implement component
9
+ return <Fragment />;
10
+ }
@@ -0,0 +1 @@
1
+ export * from './component';
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { ReactComponentGeneratorSchema } from './schema';
3
+ export declare function reactComponentGenerator(tree: Tree, options: ReactComponentGeneratorSchema): Promise<void>;
4
+ export default reactComponentGenerator;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reactComponentGenerator = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const path = require("path");
7
+ const utils_1 = require("../../shared/utils");
8
+ const fs = require("fs");
9
+ function reactComponentGenerator(tree, options) {
10
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
11
+ options.directory = options.directory || (yield (0, utils_1.askQuestion)('Enter the directory of the library: '));
12
+ const libPath = `libs/${options.directory}`;
13
+ if (!fs.existsSync(libPath)) {
14
+ console.error(`Directory ${libPath} does not exist!`);
15
+ process.exit(1);
16
+ }
17
+ options.name = options.name || (yield (0, utils_1.askQuestion)('Enter the name of the component (e.g: AppButton): '));
18
+ const libRootPath = `${libPath}/src/lib`;
19
+ const componentPath = options.subcomponent
20
+ ? `${libRootPath}/components/${(0, utils_1.convertToKebabCase)(options.name)}`
21
+ : libRootPath;
22
+ (0, devkit_1.generateFiles)(tree, path.join(__dirname, `files`), componentPath, Object.assign(Object.assign({}, options), { formatName: utils_1.formatName }));
23
+ yield (0, devkit_1.formatFiles)(tree);
24
+ });
25
+ }
26
+ exports.reactComponentGenerator = reactComponentGenerator;
27
+ exports.default = reactComponentGenerator;
28
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../plugin/src/generators/react-component/generator.ts"],"names":[],"mappings":";;;;AAAA,uCAA8D;AAC9D,6BAA6B;AAE7B,8CAAiF;AACjF,yBAAyB;AAEzB,SAAsB,uBAAuB,CAC3C,IAAU,EACV,OAAsC;;QAEtC,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,KAAI,MAAM,IAAA,mBAAW,EAAC,sCAAsC,CAAC,CAAA,CAAC;QACnG,MAAM,OAAO,GAAG,QAAQ,OAAO,CAAC,SAAS,EAAE,CAAA;QAE3C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,aAAa,OAAO,kBAAkB,CAAC,CAAC;YACtD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,KAAI,MAAM,IAAA,mBAAW,EAAC,oDAAoD,CAAC,CAAA,CAAC;QAEvG,MAAM,WAAW,GAAG,GAAG,OAAO,UAAU,CAAC;QACzC,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY;YACxC,CAAC,CAAC,GAAG,WAAW,eAAe,IAAA,0BAAkB,EAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACjE,CAAC,CAAC,WAAW,CAAC;QAEhB,IAAA,sBAAa,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,aAAa,kCAAO,OAAO,KAAE,UAAU,EAAV,kBAAU,IAAG,CAAC;QAE9F,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CAAA;AAtBD,0DAsBC;AAED,kBAAe,uBAAuB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export interface ReactComponentGeneratorSchema {
2
+ directory?: string;
3
+ name?: string;
4
+ subcomponent?: boolean;
5
+ formatName?: (value: string, withoutSpaces?: boolean) => string;
6
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "ReactComponent",
4
+ "title": "",
5
+ "type": "object",
6
+ "properties": {
7
+ "directory": {
8
+ "type": "string",
9
+ "description": "Directory of the library",
10
+ "default": "",
11
+ "$default": {
12
+ "$source": "argv",
13
+ "index": 0
14
+ }
15
+ },
16
+ "name": {
17
+ "type": "string",
18
+ "description": "Name of the component",
19
+ "default": "",
20
+ "$default": {
21
+ "$source": "argv",
22
+ "index": 1
23
+ }
24
+ },
25
+ "subcomponent": {
26
+ "type": "boolean",
27
+ "description": "Generate a folder for components",
28
+ "default": false
29
+ }
30
+ },
31
+ "required": []
32
+ }
@@ -0,0 +1,10 @@
1
+ import React, { Fragment, ReactElement } from 'react';
2
+
3
+ interface <%= formatName(name, true) %>Props {
4
+ // TODO: Describe props
5
+ }
6
+
7
+ export function <%= formatName(name, true) %>(props: <%= formatName(name, true) %>Props): ReactElement {
8
+ // TODO: Implement component
9
+ return <Fragment />;
10
+ }
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { ReactLibGeneratorSchema } from './schema';
3
+ export declare function reactLibGenerator(tree: Tree, options: ReactLibGeneratorSchema): Promise<void>;
4
+ export default reactLibGenerator;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reactLibGenerator = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const path = require("path");
7
+ const child_process_1 = require("child_process");
8
+ const utils_1 = require("../../shared/utils");
9
+ function reactLibGenerator(tree, options) {
10
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
11
+ if (!options.directory) {
12
+ options.app = options.app || (yield (0, utils_1.askQuestion)("Enter the name of the app (e.g: mobile) or 'shared': "));
13
+ options.scope = options.scope || (yield (0, utils_1.askQuestion)("Enter the scope (e.g: profile) or 'shared': "));
14
+ options.type = options.type || (yield (0, utils_1.askQuestion)("Enter the type (utils, ui, data-access or features): "));
15
+ options.name = options.name || (yield (0, utils_1.askQuestion)("Enter the name of the library (e.g: profile-settings): "));
16
+ }
17
+ const libPath = options.directory
18
+ ? `libs/${options.directory}`
19
+ : `libs/${options.app}/${options.scope}/${options.type}/${options.name}`;
20
+ const command = `npx nx g @nx/expo:lib --skipPackageJson --unitTestRunner=none --projectNameAndRootFormat=derived ${libPath}`;
21
+ const commandWithOptions = options.dryRun ? command + ' --dry-run' : command;
22
+ (0, child_process_1.execSync)(commandWithOptions, { stdio: 'inherit' });
23
+ if (options.withComponent) {
24
+ const srcPath = `${libPath}/src`;
25
+ (0, devkit_1.generateFiles)(tree, path.join(__dirname, 'files'), srcPath, Object.assign(Object.assign({}, options), { name: (0, utils_1.getLibName)(libPath), formatName: utils_1.formatName }));
26
+ tree.write(`${srcPath}/index.ts`, "export * from './lib/component';");
27
+ }
28
+ yield (0, devkit_1.formatFiles)(tree);
29
+ });
30
+ }
31
+ exports.reactLibGenerator = reactLibGenerator;
32
+ exports.default = reactLibGenerator;
33
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../plugin/src/generators/react-lib/generator.ts"],"names":[],"mappings":";;;;AAAA,uCAA8D;AAC9D,6BAA6B;AAE7B,iDAAyC;AACzC,8CAAyE;AAEzE,SAAsB,iBAAiB,CACrC,IAAU,EACV,OAAgC;;QAEhC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,GAAG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C,CAAC;QACxE,CAAC;QAED,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CAAA;AA1BD,8CA0BC;AAED,kBAAe,iBAAiB,CAAC"}
@@ -0,0 +1,10 @@
1
+ export interface ReactLibGeneratorSchema {
2
+ directory?: string;
3
+ app?: string;
4
+ scope?: string;
5
+ type?: string;
6
+ name?: string;
7
+ withComponent?: boolean;
8
+ dryRun?: boolean;
9
+ formatName?: (value: string, withoutSpaces?: boolean) => string;
10
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "ReactLib",
4
+ "title": "",
5
+ "type": "object",
6
+ "properties": {
7
+ "directory": {
8
+ "type": "string",
9
+ "description": "Directory for the library",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ }
14
+ },
15
+ "app": {
16
+ "type": "string",
17
+ "description": "Name of the app",
18
+ "default": ""
19
+ },
20
+ "scope": {
21
+ "type": "string",
22
+ "description": "Name of the scope",
23
+ "default": ""
24
+ },
25
+ "type": {
26
+ "type": "string",
27
+ "description": "Type of the library",
28
+ "default": ""
29
+ },
30
+ "name": {
31
+ "type": "string",
32
+ "description": "Name of the library",
33
+ "default": ""
34
+ },
35
+ "withComponent": {
36
+ "type": "boolean",
37
+ "description": "Generate the library with 'lib/component.tsx' file",
38
+ "default": false
39
+ },
40
+ "dryRun": {
41
+ "type": "boolean",
42
+ "description": "Generate the library without creating files",
43
+ "default": false
44
+ }
45
+ },
46
+ "required": []
47
+ }
@@ -1,2 +1,5 @@
1
- export declare const formatName: (value: string) => string;
1
+ export declare const formatName: (value: string, withoutSpaces?: boolean) => string;
2
2
  export declare const getProjectName: (str: string) => string;
3
+ export declare const getLibName: (path: string) => string;
4
+ export declare const askQuestion: (question: string) => Promise<string>;
5
+ export declare const convertToKebabCase: (value: string) => string;
@@ -1,14 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProjectName = exports.formatName = void 0;
4
- const formatName = (value) => value
3
+ exports.convertToKebabCase = exports.askQuestion = exports.getLibName = exports.getProjectName = exports.formatName = void 0;
4
+ const readline = require("readline");
5
+ const formatName = (value, withoutSpaces = false) => value
5
6
  .split('-')
6
7
  .map((word) => `${word.charAt(0).toUpperCase()}${word.substring(1)}`)
7
- .join(' ');
8
+ .join(withoutSpaces ? '' : ' ');
8
9
  exports.formatName = formatName;
9
10
  const getProjectName = (str) => {
10
11
  const parts = str.split('@');
11
12
  return parts.length > 1 ? parts[1].split('/')[0] : parts[0];
12
13
  };
13
14
  exports.getProjectName = getProjectName;
15
+ const getLibName = (path) => path.split('/').pop();
16
+ exports.getLibName = getLibName;
17
+ const askQuestion = (question) => {
18
+ const rl = readline.createInterface({
19
+ input: process.stdin,
20
+ output: process.stdout,
21
+ });
22
+ return new Promise((resolve) => rl.question(question, (answer) => {
23
+ rl.close();
24
+ resolve(answer);
25
+ }));
26
+ };
27
+ exports.askQuestion = askQuestion;
28
+ const convertToKebabCase = (value) => value
29
+ .trim()
30
+ .replace(/(.)([A-Z])/g, (_, p1, p2) => p1 + '-' + p2)
31
+ .toLowerCase();
32
+ exports.convertToKebabCase = convertToKebabCase;
14
33
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../plugin/src/shared/utils.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAE,CAC1C,KAAK;KACF,KAAK,CAAC,GAAG,CAAC;KACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;KACpE,IAAI,CAAC,GAAG,CAAC,CAAC;AAJF,QAAA,UAAU,cAIR;AAER,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,E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