@roadmanjs/utils 0.0.3 → 0.0.7

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/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from "./scripts";
2
+ export * from "./morpheus";
package/dist/index.js CHANGED
@@ -11,4 +11,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./scripts"), exports);
14
+ __exportStar(require("./morpheus"), exports);
14
15
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B"}
@@ -0,0 +1,17 @@
1
+ import { InterfaceDefinition } from './interface';
2
+ export interface Consts {
3
+ name: string;
4
+ value: any;
5
+ leadingTrivia?: string;
6
+ }
7
+ export interface MorpheusArgs {
8
+ filename: string;
9
+ consts: Consts[];
10
+ interfaces?: InterfaceDefinition[];
11
+ }
12
+ /**
13
+ * Morpheus in action
14
+ */
15
+ export declare const writeAllFilesToProject: (args: MorpheusArgs[], path: string, pathToFolder?: string) => Promise<boolean>;
16
+ export * from './interface';
17
+ export * from './writter';
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.writeAllFilesToProject = void 0;
14
+ /**
15
+ * Define all models that can should be morphed
16
+ */
17
+ const ts_morph_1 = require("ts-morph");
18
+ const text_utils_1 = require("../utils/text.utils");
19
+ const writter_1 = require("./writter");
20
+ /**
21
+ * Morpheus in action
22
+ */
23
+ const writeAllFilesToProject = async (args, path, pathToFolder) => {
24
+ // write each file
25
+ const writeFilesTasks = args.map((arg) => {
26
+ const { consts: constStatements, filename, interfaces } = arg;
27
+ const nameSNAKE_CASE = (0, text_utils_1.toSnakeUpper)(filename);
28
+ return {
29
+ filename: nameSNAKE_CASE,
30
+ task: (0, writter_1.writeTsFile)({
31
+ pathToFolder,
32
+ pathToTs: path,
33
+ filename: nameSNAKE_CASE,
34
+ variables: constStatements.map((con) => ({
35
+ name: con.name,
36
+ initializer: JSON.stringify(con.value),
37
+ // leadingTrivia: (writer) => {
38
+ // writer.writeLine('\n');
39
+ // if (con?.leadingTrivia) {
40
+ // writer.writeLine(con.leadingTrivia);
41
+ // }
42
+ // },
43
+ // trailingTrivia: (writer) => writer.writeLine('\n'),
44
+ })),
45
+ interfaces,
46
+ }),
47
+ };
48
+ });
49
+ // write all files
50
+ await Promise.all(writeFilesTasks.map((i) => i.task));
51
+ // write all exports
52
+ const allFileExports = writeFilesTasks
53
+ .map((i) => i.filename)
54
+ .map((c) => ({
55
+ kind: ts_morph_1.StructureKind.ExportDeclaration,
56
+ // namespaceExport: "*",
57
+ moduleSpecifier: `./${c}`,
58
+ }));
59
+ // write final index file
60
+ await (0, writter_1.writeTsFile)({
61
+ pathToFolder,
62
+ pathToTs: path,
63
+ filename: 'index',
64
+ exports: allFileExports,
65
+ });
66
+ return true;
67
+ };
68
+ exports.writeAllFilesToProject = writeAllFilesToProject;
69
+ __exportStar(require("./interface"), exports);
70
+ __exportStar(require("./writter"), exports);
71
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/morpheus/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;GAEG;AACH,uCAAmE;AAGnE,oDAAiD;AACjD,uCAAsC;AAatC;;GAEG;AACI,MAAM,sBAAsB,GAAG,KAAK,EACvC,IAAoB,EACpB,IAAY,EACZ,YAAqB,EACvB,EAAE;IACA,kBAAkB;IAClB,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACrC,MAAM,EAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAC,GAAG,GAAG,CAAC;QAC5D,MAAM,cAAc,GAAG,IAAA,yBAAY,EAAC,QAAQ,CAAC,CAAC;QAE9C,OAAO;YACH,QAAQ,EAAE,cAAc;YACxB,IAAI,EAAE,IAAA,qBAAW,EAAC;gBACd,YAAY;gBACZ,QAAQ,EAAE,IAAI;gBACd,QAAQ,EAAE,cAAc;gBACxB,SAAS,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;oBACrC,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;oBACtC,+BAA+B;oBAC/B,8BAA8B;oBAE9B,gCAAgC;oBAChC,+CAA+C;oBAC/C,QAAQ;oBACR,KAAK;oBACL,sDAAsD;iBACzD,CAAC,CAAC;gBACH,UAAU;aACb,CAAC;SACL,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,mBAAmB;IACnB,MAAM,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAEtD,oBAAoB;IACpB,MAAM,cAAc,GAAiC,eAAe;SAC/D,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;SACtB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACT,IAAI,EAAE,wBAAa,CAAC,iBAAiB;QACrC,0BAA0B;QAC1B,eAAe,EAAE,KAAK,CAAC,EAAE;KAC5B,CAAC,CAAC,CAAC;IAER,yBAAyB;IACzB,MAAM,IAAA,qBAAW,EAAC;QACd,YAAY;QACZ,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,OAAO;QACjB,OAAO,EAAE,cAAc;KAC1B,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAtDW,QAAA,sBAAsB,0BAsDjC;AAEF,8CAA4B;AAC5B,4CAA0B"}
@@ -0,0 +1,27 @@
1
+ export declare type IType = 'Date' | 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function';
2
+ export interface KeyType {
3
+ name: string;
4
+ type: IType;
5
+ }
6
+ /**
7
+ * Detect type of a key
8
+ * Only dealing with 4 types for now
9
+ * @param obj
10
+ * @param key
11
+ * @returns
12
+ */
13
+ export declare const getPropertyType: (obj: any, key: any) => IType;
14
+ export interface InterfaceProperty {
15
+ name: string;
16
+ type: IType;
17
+ }
18
+ export interface InterfaceDefinition {
19
+ name: string;
20
+ properties: InterfaceProperty[];
21
+ }
22
+ /**
23
+ * Create an interface from a class
24
+ * @param Cls
25
+ * @returns
26
+ */
27
+ export declare const createInterfaceFromClass: (Cls: any) => InterfaceDefinition;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createInterfaceFromClass = exports.getPropertyType = void 0;
4
+ /**
5
+ * Detect type of a key
6
+ * Only dealing with 4 types for now
7
+ * @param obj
8
+ * @param key
9
+ * @returns
10
+ */
11
+ const getPropertyType = (obj, key) => {
12
+ if (obj[key] instanceof Date) {
13
+ return 'Date';
14
+ }
15
+ if (typeof obj[key] === 'number') {
16
+ return 'number';
17
+ }
18
+ if (typeof obj[key] === 'string') {
19
+ return 'string';
20
+ }
21
+ // just return the default type
22
+ return typeof obj[key];
23
+ };
24
+ exports.getPropertyType = getPropertyType;
25
+ /**
26
+ * Create an interface from a class
27
+ * @param Cls
28
+ * @returns
29
+ */
30
+ const createInterfaceFromClass = (Cls) => {
31
+ // pass in class
32
+ const CLS = new Cls();
33
+ const keys = Object.getOwnPropertyNames(CLS); // got the keys
34
+ const keysWithType = keys.map((key) => {
35
+ const keyType = (0, exports.getPropertyType)(CLS, key);
36
+ return { name: key, type: keyType };
37
+ });
38
+ const name = Cls.name;
39
+ return {
40
+ name,
41
+ properties: keysWithType,
42
+ };
43
+ };
44
+ exports.createInterfaceFromClass = createInterfaceFromClass;
45
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/morpheus/interface.ts"],"names":[],"mappings":";;;AAeA;;;;;;GAMG;AACI,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAS,EAAE;IAC/C,IAAI,GAAG,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE;QAC1B,OAAO,MAAM,CAAC;KACjB;IAED,IAAI,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE;QAC9B,OAAO,QAAQ,CAAC;KACnB;IAED,IAAI,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE;QAC9B,OAAO,QAAQ,CAAC;KACnB;IAED,+BAA+B;IAC/B,OAAO,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC,CAAC;AAfW,QAAA,eAAe,mBAe1B;AAYF;;;;GAIG;AACI,MAAM,wBAAwB,GAAG,CAAC,GAAQ,EAAuB,EAAE;IACtE,gBAAgB;IAChB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;IACtB,MAAM,IAAI,GAAG,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,eAAe;IAE7D,MAAM,YAAY,GAAc,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAC7C,MAAM,OAAO,GAAG,IAAA,uBAAe,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC1C,OAAO,EAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IAEtB,OAAO;QACH,IAAI;QACJ,UAAU,EAAE,YAAY;KAC3B,CAAC;AACN,CAAC,CAAC;AAhBW,QAAA,wBAAwB,4BAgBnC"}
@@ -0,0 +1,12 @@
1
+ import { ExportDeclarationStructure, OptionalKind, StatementedNodeStructure, VariableDeclarationStructure } from 'ts-morph';
2
+ import { InterfaceDefinition } from '../interface';
3
+ interface WriteFileProps extends StatementedNodeStructure {
4
+ pathToFolder?: string;
5
+ pathToTs: string;
6
+ filename: string;
7
+ variables?: OptionalKind<VariableDeclarationStructure>[];
8
+ interfaces?: InterfaceDefinition[];
9
+ exports?: OptionalKind<ExportDeclarationStructure>[];
10
+ }
11
+ export declare const writeTsFile: (props: WriteFileProps) => Promise<any>;
12
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeTsFile = void 0;
4
+ const ts_morph_1 = require("ts-morph");
5
+ const writeTsFile = async (props) => {
6
+ const { filename, statements, variables, interfaces, exports, pathToTs, pathToFolder } = props;
7
+ const project = new ts_morph_1.Project({
8
+ tsConfigFilePath: `${pathToTs}/tsconfig.json`,
9
+ skipAddingFilesFromTsConfig: true,
10
+ });
11
+ const sourceFile = project.createSourceFile(`${pathToFolder || pathToTs}/${filename}.ts`, {}, { overwrite: true });
12
+ if (interfaces) {
13
+ interfaces.map((interfc) => {
14
+ const interfaceDef = sourceFile.addInterface({
15
+ name: interfc.name,
16
+ isExported: true,
17
+ });
18
+ interfc.properties.map((proper) => {
19
+ interfaceDef.addProperty({
20
+ name: proper.name,
21
+ type: proper.type,
22
+ });
23
+ });
24
+ });
25
+ }
26
+ if (variables) {
27
+ sourceFile.addVariableStatement({
28
+ declarationKind: ts_morph_1.VariableDeclarationKind.Const,
29
+ isExported: true,
30
+ declarations: variables,
31
+ });
32
+ }
33
+ if (exports) {
34
+ sourceFile.addExportDeclarations(exports);
35
+ }
36
+ return await sourceFile.save();
37
+ };
38
+ exports.writeTsFile = writeTsFile;
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/morpheus/writter/index.ts"],"names":[],"mappings":";;;AAAA,uCASkB;AAYX,MAAM,WAAW,GAAG,KAAK,EAAE,KAAqB,EAAgB,EAAE;IACrE,MAAM,EAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAC,GAAG,KAAK,CAAC;IAE7F,MAAM,OAAO,GAAG,IAAI,kBAAO,CAAC;QACxB,gBAAgB,EAAE,GAAG,QAAQ,gBAAgB;QAC7C,2BAA2B,EAAE,IAAI;KACpC,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,OAAO,CAAC,gBAAgB,CACvC,GAAG,YAAY,IAAI,QAAQ,IAAI,QAAQ,KAAK,EAC5C,EAAE,EACF,EAAC,SAAS,EAAE,IAAI,EAAC,CACpB,CAAC;IAEF,IAAI,UAAU,EAAE;QACZ,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YACvB,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;gBACzC,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,UAAU,EAAE,IAAI;aACnB,CAAC,CAAC;YAEH,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;gBAC9B,YAAY,CAAC,WAAW,CAAC;oBACrB,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,IAAI,EAAE,MAAM,CAAC,IAAI;iBACpB,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;KACN;IAED,IAAI,SAAS,EAAE;QACX,UAAU,CAAC,oBAAoB,CAAC;YAC5B,eAAe,EAAE,kCAAuB,CAAC,KAAK;YAC9C,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,SAAS;SAC1B,CAAC,CAAC;KACN;IAED,IAAI,OAAO,EAAE;QACT,UAAU,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;KAC7C;IAED,OAAO,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC;AACnC,CAAC,CAAC;AA3CW,QAAA,WAAW,eA2CtB"}
@@ -0,0 +1 @@
1
+ import 'mocha';
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("mocha");
4
+ const interface_1 = require("./morpheus/interface");
5
+ const morpheus_1 = require("./morpheus");
6
+ const chai_1 = require("chai");
7
+ class GClass {
8
+ constructor() {
9
+ this.j = 'j string';
10
+ this.g = 10;
11
+ this.e = new Date();
12
+ this.a = [];
13
+ }
14
+ }
15
+ let demoFiles = [
16
+ {
17
+ filename: 'somefile_name',
18
+ consts: [
19
+ {
20
+ name: 'GoodConst',
21
+ value: 'somevalue',
22
+ },
23
+ ],
24
+ // interfaces: [
25
+ // {
26
+ // name: 'GClass',
27
+ // properties: [
28
+ // {name: 'j', type: 'string'},
29
+ // {name: 'g', type: 'number'},
30
+ // {name: 'e', type: 'Date'},
31
+ // {name: 'a', type: 'object'},
32
+ // ],
33
+ // },
34
+ // ],
35
+ },
36
+ ];
37
+ describe('Morpheus', () => {
38
+ let ginterfaceDefinition = null;
39
+ it('it should write TS files with consts and export them', async () => {
40
+ const project = await (0, morpheus_1.writeAllFilesToProject)(demoFiles, '.', 'src/client');
41
+ (0, chai_1.expect)(project).to.be.true;
42
+ });
43
+ it('it should create a interface definition from a class', async () => {
44
+ ginterfaceDefinition = (0, interface_1.createInterfaceFromClass)(GClass);
45
+ (0, chai_1.expect)(ginterfaceDefinition).to.not.be.null;
46
+ });
47
+ it('it should create TS files with consts and interfaces', async () => {
48
+ // Add the create ginterfaceDefinition
49
+ demoFiles[0].interfaces = [ginterfaceDefinition];
50
+ const project = await (0, morpheus_1.writeAllFilesToProject)(demoFiles, '.', 'src/client');
51
+ (0, chai_1.expect)(project).to.be.true;
52
+ });
53
+ // TODO for interfaces
54
+ });
55
+ //# sourceMappingURL=morpheus.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"morpheus.test.js","sourceRoot":"","sources":["../src/morpheus.test.ts"],"names":[],"mappings":";;AAAA,iBAAe;AAEf,oDAAmF;AACnF,yCAAgE;AAEhE,+BAA4B;AAE5B,MAAM,MAAM;IAAZ;QACI,MAAC,GAAW,UAAU,CAAC;QAEvB,MAAC,GAAW,EAAE,CAAC;QAEf,MAAC,GAAS,IAAI,IAAI,EAAE,CAAC;QAErB,MAAC,GAAQ,EAAE,CAAC;IAChB,CAAC;CAAA;AAED,IAAI,SAAS,GAAmB;IAC5B;QACI,QAAQ,EAAE,eAAe;QACzB,MAAM,EAAE;YACJ;gBACI,IAAI,EAAE,WAAW;gBACjB,KAAK,EAAE,WAAW;aACrB;SACJ;QACD,gBAAgB;QAChB,QAAQ;QACR,0BAA0B;QAC1B,wBAAwB;QACxB,2CAA2C;QAC3C,2CAA2C;QAC3C,yCAAyC;QACzC,2CAA2C;QAC3C,aAAa;QACb,SAAS;QACT,KAAK;KACR;CACJ,CAAC;AAEF,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACtB,IAAI,oBAAoB,GAAwB,IAAI,CAAC;IACrD,EAAE,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;QAClE,MAAM,OAAO,GAAG,MAAM,IAAA,iCAAsB,EAAC,SAAS,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;QAC3E,IAAA,aAAM,EAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;QAClE,oBAAoB,GAAG,IAAA,oCAAwB,EAAC,MAAM,CAAC,CAAC;QACxD,IAAA,aAAM,EAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;QAClE,sCAAsC;QACtC,SAAS,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAEjD,MAAM,OAAO,GAAG,MAAM,IAAA,iCAAsB,EAAC,SAAS,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;QAC3E,IAAA,aAAM,EAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,sBAAsB;AAC1B,CAAC,CAAC,CAAC"}
@@ -7,6 +7,7 @@ export interface CreatePackageJson {
7
7
  name: string;
8
8
  description: string;
9
9
  dependencies?: any;
10
+ extraProps?: any;
10
11
  }
11
12
  /**
12
13
  * Re-usable method for generating client package.json
@@ -10,14 +10,14 @@ const fs_1 = require("fs");
10
10
  * @param clientPackageName
11
11
  */
12
12
  const createClientPackageJson = async (args) => {
13
- const { parentDir = 'package.json', dir = 'dist-client/package.json', name, dependencies, description, } = args;
13
+ const { parentDir = 'package.json', dir = 'dist-client/package.json', name, dependencies, description, extraProps, } = args;
14
14
  try {
15
15
  const packageFile = await (0, fs_1.readFileSync)(parentDir, { encoding: 'utf8' });
16
16
  const packageContentJSON = JSON.parse(packageFile);
17
- const newPackage = Object.assign(Object.assign({}, packageContentJSON), { name,
17
+ const newPackage = Object.assign(Object.assign(Object.assign({}, packageContentJSON), { name,
18
18
  description, dependencies: Object.assign({
19
19
  // make it only one dep for easy client react .e.t.c
20
- 'graphql-tag': '^2.12.5' }, dependencies), devDependencies: {}, peerDependencies: {}, scripts: {} });
20
+ 'graphql-tag': '^2.12.5' }, dependencies), devDependencies: {}, peerDependencies: {}, scripts: {} }), extraProps);
21
21
  // console.log('new packageJson file', newPackage);
22
22
  (0, fs_1.writeFileSync)(dir, JSON.stringify(newPackage), {
23
23
  encoding: 'utf8',
@@ -1 +1 @@
1
- {"version":3,"file":"createPackageJsonForClient.js","sourceRoot":"","sources":["../../src/scripts/createPackageJsonForClient.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2BAA+C;AAS/C;;;GAGG;AACI,MAAM,uBAAuB,GAAG,KAAK,EAAE,IAAuB,EAAmB,EAAE;IACtF,MAAM,EACF,SAAS,GAAG,cAAc,EAC1B,GAAG,GAAG,0BAA0B,EAChC,IAAI,EACJ,YAAY,EACZ,WAAW,GACd,GAAG,IAAI,CAAC;IAET,IAAI;QACA,MAAM,WAAW,GAAQ,MAAM,IAAA,iBAAY,EAAC,SAAS,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;QAC3E,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAEnD,MAAM,UAAU,mCACT,kBAAkB,KACrB,IAAI;YACJ,WAAW,EACX,YAAY;gBACR,oDAAoD;gBACpD,aAAa,EAAE,SAAS,IACrB,YAAY,GAEnB,eAAe,EAAE,EAAE,EACnB,gBAAgB,EAAE,EAAE,EACpB,OAAO,EAAE,EAAE,GACd,CAAC;QAEF,mDAAmD;QAEnD,IAAA,kBAAa,EAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;YAC3C,QAAQ,EAAE,MAAM;SACnB,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC;KACrB;IAAC,OAAO,KAAK,EAAE;QACZ,MAAM,KAAK,CAAC;KACf;AACL,CAAC,CAAC;AArCW,QAAA,uBAAuB,2BAqClC"}
1
+ {"version":3,"file":"createPackageJsonForClient.js","sourceRoot":"","sources":["../../src/scripts/createPackageJsonForClient.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2BAA+C;AAU/C;;;GAGG;AACI,MAAM,uBAAuB,GAAG,KAAK,EAAE,IAAuB,EAAmB,EAAE;IACtF,MAAM,EACF,SAAS,GAAG,cAAc,EAC1B,GAAG,GAAG,0BAA0B,EAChC,IAAI,EACJ,YAAY,EACZ,WAAW,EACX,UAAU,GACb,GAAG,IAAI,CAAC;IAET,IAAI;QACA,MAAM,WAAW,GAAQ,MAAM,IAAA,iBAAY,EAAC,SAAS,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;QAC3E,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAEnD,MAAM,UAAU,iDACT,kBAAkB,KACrB,IAAI;YACJ,WAAW,EACX,YAAY;gBACR,oDAAoD;gBACpD,aAAa,EAAE,SAAS,IACrB,YAAY,GAEnB,eAAe,EAAE,EAAE,EACnB,gBAAgB,EAAE,EAAE,EACpB,OAAO,EAAE,EAAE,KACR,UAAU,CAChB,CAAC;QAEF,mDAAmD;QAEnD,IAAA,kBAAa,EAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;YAC3C,QAAQ,EAAE,MAAM;SACnB,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC;KACrB;IAAC,OAAO,KAAK,EAAE;QACZ,MAAM,KAAK,CAAC;KACf;AACL,CAAC,CAAC;AAvCW,QAAA,uBAAuB,2BAuClC"}
package/dist/ts.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ declare class G {
2
+ j: string;
3
+ g: number;
4
+ e: Date;
5
+ a: any;
6
+ }
7
+ declare const Ginstance: G;
8
+ declare const keys: string[];
package/dist/ts.js ADDED
@@ -0,0 +1,13 @@
1
+ class G {
2
+ constructor() {
3
+ this.j = "j string";
4
+ this.g = 10;
5
+ this.e = new Date();
6
+ this.a = [];
7
+ }
8
+ }
9
+ const Ginstance = new G();
10
+ const keys = Object.getOwnPropertyNames(Ginstance);
11
+ console.log("keys", keys);
12
+ console.log("keys typeof", typeof Ginstance["g"]);
13
+ //# sourceMappingURL=ts.js.map
package/dist/ts.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts.js","sourceRoot":"","sources":["../src/ts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC;IAAP;QACI,MAAC,GAAW,UAAU,CAAA;QAEtB,MAAC,GAAW,EAAE,CAAA;QAEd,MAAC,GAAS,IAAI,IAAI,EAAE,CAAC;QAErB,MAAC,GAAQ,EAAE,CAAA;IACf,CAAC;CAAA;AAED,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,CAAC;AAE1B,MAAM,IAAI,GAAG,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;AAEnD,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAE1B,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ export declare const JSONDATA: (data: any) => Record<string, any> | string | null;
2
+ /**
3
+ * CapitalizeFirstLetter
4
+ * @param txt
5
+ * @returns
6
+ */
7
+ export declare function capText(txt: string): string;
8
+ /**
9
+ * To Snake case and in upper case
10
+ * @param txt
11
+ * @returns
12
+ */
13
+ export declare const toSnakeUpper: (txt: string) => string;
14
+ export default JSONDATA;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.toSnakeUpper = exports.capText = exports.JSONDATA = void 0;
7
+ const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
8
+ const snakeCase_1 = __importDefault(require("lodash/snakeCase"));
9
+ const toUpper_1 = __importDefault(require("lodash/toUpper"));
10
+ const JSONDATA = (data) => {
11
+ if ((0, isEmpty_1.default)(data) || !data) {
12
+ return null;
13
+ }
14
+ try {
15
+ if (typeof data !== "object") {
16
+ return JSON.parse(data);
17
+ }
18
+ return data;
19
+ }
20
+ catch (error) {
21
+ // console.log('error trying to parse response data');
22
+ return data;
23
+ }
24
+ };
25
+ exports.JSONDATA = JSONDATA;
26
+ /**
27
+ * CapitalizeFirstLetter
28
+ * @param txt
29
+ * @returns
30
+ */
31
+ function capText(txt) {
32
+ return txt.charAt(0).toUpperCase() + txt.slice(1); //or if you want lowercase the rest txt.slice(1).toLowerCase();
33
+ }
34
+ exports.capText = capText;
35
+ /**
36
+ * To Snake case and in upper case
37
+ * @param txt
38
+ * @returns
39
+ */
40
+ const toSnakeUpper = (txt) => {
41
+ return (0, toUpper_1.default)((0, snakeCase_1.default)(txt));
42
+ };
43
+ exports.toSnakeUpper = toSnakeUpper;
44
+ exports.default = exports.JSONDATA;
45
+ //# sourceMappingURL=text.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.utils.js","sourceRoot":"","sources":["../../src/utils/text.utils.ts"],"names":[],"mappings":";;;;;;AAAA,6DAAqC;AACrC,iEAAyC;AACzC,6DAAqC;AAE9B,MAAM,QAAQ,GAAG,CAAC,IAAS,EAAuC,EAAE;IACzE,IAAI,IAAA,iBAAO,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;QAC1B,OAAO,IAAI,CAAC;KACb;IAED,IAAI;QACF,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SACzB;QACD,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,KAAK,EAAE;QACd,sDAAsD;QACtD,OAAO,IAAI,CAAC;KACb;AACH,CAAC,CAAC;AAdW,QAAA,QAAQ,YAcnB;AAEF;;;;GAIG;AACH,SAAgB,OAAO,CAAC,GAAW;IACjC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,+DAA+D;AACpH,CAAC;AAFD,0BAEC;AAED;;;;GAIG;AACI,MAAM,YAAY,GAAG,CAAC,GAAW,EAAU,EAAE;IAClD,OAAO,IAAA,iBAAO,EAAC,IAAA,mBAAS,EAAC,GAAG,CAAC,CAAC,CAAC;AACjC,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB;AAEF,kBAAe,gBAAQ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roadmanjs/utils",
3
- "version": "0.0.3",
3
+ "version": "0.0.7",
4
4
  "description": "Shared utilities to use for any other package",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -37,6 +37,7 @@
37
37
  "lint": "tslint \"src/**/*.ts\" --project tsconfig.json",
38
38
  "build": "rm -rf dist && ./node_modules/.bin/tsc --skipLibCheck",
39
39
  "test": "mocha src/*test.ts --exit",
40
+ "morph": "mocha src/morpheus.test.ts --exit",
40
41
  "prepublishOnly": "npm run build",
41
42
  "eslint": "eslint ./src --fix --ext=ts"
42
43
  },
@@ -84,6 +85,7 @@
84
85
  "typescript": ">=2.0"
85
86
  },
86
87
  "dependencies": {
87
- "shelljs": "^0.8.5"
88
+ "shelljs": "^0.8.5",
89
+ "ts-morph": "^13.0.3"
88
90
  }
89
91
  }