diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e9a305..cd5c86e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 🛠️ CHANGELOG +## v1.3.3 + +- Dynamic type inference for prisma type generators + +- `path` refactoring to support all formats (`.ts`, `.tsx` and no suffix). + ## v1.3.2 - Updates prisma type generation nomenclature (hotfix) diff --git a/LICENSE b/LICENSE index 97d3fde..1970ea6 100644 --- a/LICENSE +++ b/LICENSE @@ -16,15 +16,14 @@ when conveying this work. The full and exhaustive list of those sources excepted from the AGPLv3 are: -* The Google Maps API v3 located at: http://maps.google.com/maps/api/js -* The twitter "follow button" widget located at http://platform.twitter.com/widgets.js -* The GitHub Gist API located at http://gist.github.com/{id}.js. This applies only to +* The Google Maps API v3 located at: +* The twitter "follow button" widget located at +* The GitHub Gist API located at . This applies only to the javascript coded issues by GitHub Inc. and explicitly does not apply to the content of any GitHub gist. -* The disqus API located at http://.disqus.com/embed.js where is the +* The disqus API located at .disqus.com/embed.js> where is the userid of the forum. - Additional terms to AGPLv3 ------------------------- @@ -45,4 +44,4 @@ c) Attribution hyperlinks in the footer have to be kept unaltered. d) You may add your name to the list of copyright holder(s) in the footer if you make changes to the work, keeping intact all other copyright holder names -e) Changes to these terms require written permission by the copyright holder(s). \ No newline at end of file +e) Changes to these terms require written permission by the copyright holder(s). diff --git a/dist/src/generators/api.js b/dist/src/generators/api.js index 928079f..ceb7b53 100644 --- a/dist/src/generators/api.js +++ b/dist/src/generators/api.js @@ -44,6 +44,7 @@ var prompts_1 = __importDefault(require("prompts")); var path_1 = require("path"); var fs_jetpack_1 = require("fs-jetpack"); var log_1 = require("../helpers/log"); +var nomenclature_1 = require("../helpers/nomenclature"); function generateApi(path) { var _a; return __awaiter(this, void 0, void 0, function () { @@ -67,16 +68,7 @@ function generateApi(path) { case 2: pathArray = path.split('/'); fileName = pathArray[pathArray.length - 1]; - name = fileName.replace(/[^\w\s]/gi, ''); - if (fileName.indexOf('.') !== -1) { - name = fileName.split('.').map(function (word) { return word[0].toUpperCase() + word.substring(1); }).join(''); - } - else if (fileName.indexOf('-') !== -1) { - name = fileName.split('-').map(function (word) { return word[0].toUpperCase() + word.substring(1); }).join(''); - } - else { - name = name[0].toUpperCase() + name.substring(1); - } + name = (0, nomenclature_1.formatName)(fileName); apiTemplate = (_a = (0, fs_jetpack_1.read)((0, path_1.join)(__dirname, '..', 'templates', 'api.template'))) === null || _a === void 0 ? void 0 : _a.replaceAll('{{name}}', name); (0, fs_jetpack_1.write)(apiPath, apiTemplate || ''); (0, log_1.Log)(" \u2705 Created pages/api/".concat(path, ".tsx").green); diff --git a/dist/src/generators/api.js.map b/dist/src/generators/api.js.map index d6190d6..049ecbb 100644 --- a/dist/src/generators/api.js.map +++ b/dist/src/generators/api.js.map @@ -1 +1 @@ -{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/generators/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA6B;AAC7B,6BAA2B;AAC3B,yCAAgD;AAChD,sCAAoC;AAEpC,SAAsB,WAAW,CAAE,IAAY;;;;;;;oBACvC,OAAO,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,UAAG,IAAI,SAAM,CAAC,CAAA;yBAE9D,CAAA,IAAA,mBAAM,EAAC,OAAO,CAAC,KAAK,KAAK,CAAA,EAAzB,wBAAyB;oBACZ,qBAAM,IAAA,iBAAO,EAAC;4BAC3B,IAAI,EAAE,SAAS;4BACf,IAAI,EAAE,WAAW;4BACjB,OAAO,EAAE,wCAAwC;yBAClD,CAAC,EAAA;;oBAJI,MAAM,GAAG,SAIb;oBAEF,IAAI,MAAM,CAAC,SAAS,KAAK,KAAK,EAAE;wBAC9B,sBAAM;qBACP;;;oBAGG,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;oBAC3B,QAAQ,GA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C"} \ No newline at end of file +{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/generators/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA6B;AAC7B,6BAA2B;AAC3B,yCAAgD;AAChD,sCAAoC;AACpC,wDAAoD;AAEpD,SAAsB,WAAW,CAAE,IAAY;;;;;;;oBACvC,OAAO,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,UAAG,IAAI,SAAM,CAAC,CAAA;yBAE9D,CAAA,IAAA,mBAAM,EAAC,OAAO,CAAC,KAAK,KAAK,CAAA,EAAzB,wBAAyB;oBACZ,qBAAM,IAAA,iBAAO,EAAC;4BAC3B,IAAI,EAAE,SAAS;4BACf,IAAI,EAAE,WAAW;4BACjB,OAAO,EAAE,wCAAwC;yBAClD,CAAC,EAAA;;oBAJI,MAAM,GAAG,SAIb;oBAEF,IAAI,MAAM,CAAC,SAAS,KAAK,KAAK,EAAE;wBAC9B,sBAAM;qBACP;;;oBAGG,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;oBAC3B,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;oBAC5C,IAAI,GAAG,IAAA,yBAAU,EAAC,QAAQ,CAAC,CAAA;oBAEzB,WAAW,GAAG,MAAA,IAAA,iBAAI,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,0CAAE,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;oBAE1G,IAAA,kBAAK,EAAC,OAAO,EAAE,WAAW,IAAI,EAAE,CAAC,CAAA;oBACjC,IAAA,SAAG,EAAC,wCAA4B,IAAI,SAAM,CAAC,KAAK,CAAC,CAAA;;;;;CAClD;AAvBD,kCAuBC"} \ No newline at end of file diff --git a/dist/src/generators/component.js b/dist/src/generators/component.js index 8ddf059..c92e1b9 100644 --- a/dist/src/generators/component.js +++ b/dist/src/generators/component.js @@ -45,6 +45,7 @@ var path_1 = require("path"); var fs_jetpack_1 = require("fs-jetpack"); var log_1 = require("../helpers/log"); var config_1 = require("../config"); +var nomenclature_1 = require("../helpers/nomenclature"); function generateComponent(path) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; return __awaiter(this, void 0, void 0, function () { @@ -67,16 +68,7 @@ function generateComponent(path) { case 2: pathArray = path.replace('.tsx', '').split('/'); fileName = pathArray[pathArray.length - 1]; - name = fileName.replace(/[^\w\s]/gi, ''); - if (fileName.indexOf('.') !== -1) { - name = fileName.split('.').map(function (word) { return word[0].toUpperCase() + word.substring(1); }).join(''); - } - else if (fileName.indexOf('-') !== -1) { - name = fileName.split('-').map(function (word) { return word[0].toUpperCase() + word.substring(1); }).join(''); - } - else { - name = name[0].toUpperCase() + name.substring(1); - } + name = (0, nomenclature_1.formatName)(fileName); if (config_1.Config.componentFolder === true) { component = (_a = (0, fs_jetpack_1.read)((0, path_1.join)(__dirname, '..', 'templates', 'component', 'component.nostyle.template'))) === null || _a === void 0 ? void 0 : _a.replaceAll('{{name}}', name).replaceAll('{{prefix}}', fileName).replaceAll('{{path}}', path); componentPath = (0, path_1.join)(process.cwd(), path, "".concat(fileName, ".component.tsx")); diff --git a/dist/src/generators/component.js.map b/dist/src/generators/component.js.map index 7664208..52b43a9 100644 --- a/dist/src/generators/component.js.map +++ b/dist/src/generators/component.js.map @@ -1 +1 @@ -{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../src/generators/component.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA6B;AAC7B,6BAA2B;AAC3B,yCAAgD;AAChD,sCAAoC;AACpC,oCAAkC;AAElC,SAAsB,iBAAiB,CAAE,IAAY;;;;;;;yBAC/C,CAAA,IAAA,mBAAM,EAAC,IAAA,WAAI,E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,EAAE,UAAU,CAAC,UAAU,EAAE,IAAI,EAAE,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;6BAC3M;4BAED,IAAA,kBAAK,EAAC,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,CAAA;4BAC7B,IAAA,SAAG,EAAC,0BAA0B,CAAC,KAAK,CAAC,CAAA;yBACtC;qBACF;yBAAM;wBACC,SAAS,GAAG,MAAA,IAAA,iBAAI,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,4BAA4B,CAAC,CAAC,0CAAE,UAAU,CAAC,UAAU,EAAE,IAAI,EAAE,UAAU,CAAC,YAAY,EAAE,QAAQ,EAAE,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;wBAC7L,aAAa,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,SAAM,CAAC,CAAA;wBAE5E,IAAA,kBAAK,EAAC,aAAa,EAAE,SAAS,IAAI,EAAE,CAAC,CAAA;wBACrC,IAAA,SAAG,EAAC,8BAAkB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,SAAM,CAAC,KAAK,CAAC,CAAA;qBAC5D;;;;;CACF;AA3DD,8CA2DC"} \ No newline at end of file diff --git a/dist/src/generators/inject.js b/dist/src/generators/inject.js index ee530a3..eef5f70 100644 --- a/dist/src/generators/inject.js +++ b/dist/src/generators/inject.js @@ -45,21 +45,17 @@ function inject(slice, component, opts) { return __awaiter(this, void 0, void 0, function () { var filePath, pathArray, fileName, fileContents, fileComponentPath, slicePath, sliceContents, matches, splitFile, sliceMatch, newContents, stateInjections, actionInjections, i, index, match, decorator, typeMap, varKey, addDots, varKey, hasExistingImport, i, stateInjection, typeName, i, stateInjection, injectionLine, tempContents, typeMap, value, spreadLeft, spreadRight, typeName, injectionLine, tempContents, tempContents, fileComponentPath; return __generator(this, function (_a) { + component = component.replaceAll('.tsx', ''); filePath = (0, path_1.join)(process.cwd(), component); pathArray = component.split('/'); fileName = pathArray[pathArray.length - 1]; fileContents = ''; - if (filePath.indexOf('.tsx') === -1) { - if ((0, fs_jetpack_1.exists)(filePath) === 'dir') { - fileComponentPath = (0, path_1.join)(process.cwd(), component, "".concat(fileName, ".component.tsx")); - fileContents = (0, fs_jetpack_1.read)(fileComponentPath) || ''; - } - else { - fileContents = (0, fs_jetpack_1.read)("".concat(filePath, ".tsx")) || ''; - } + if ((0, fs_jetpack_1.exists)(filePath) === 'dir') { + fileComponentPath = (0, path_1.join)(process.cwd(), component, "".concat(fileName, ".component.tsx")); + fileContents = (0, fs_jetpack_1.read)(fileComponentPath) || ''; } else { - fileContents = (0, fs_jetpack_1.read)("".concat(filePath)) || ''; + fileContents = (0, fs_jetpack_1.read)("".concat(filePath, ".tsx")) || ''; } slicePath = (0, path_1.join)(process.cwd(), 'redux', 'slice', "".concat(slice, ".tsx")); sliceContents = (0, fs_jetpack_1.read)(slicePath) || ''; diff --git a/dist/src/generators/inject.js.map b/dist/src/generators/inject.js.map index ed29013..2b7ef08 100644 --- a/dist/src/generators/inject.js.map +++ b/dist/src/generators/inject.js.map @@ -1 +1 @@ -{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/generators/inject.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAA2B;AAC3B,yCAAgD;AAChD,sCAAoC;AACpC,0CAA8L;AAO9L,SAAsB,MAAM,CAAE,KAAa,EAAE,SAAiB,EAAE,IAAc;;;;YACtE,QAAQ,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,CAAA;YACzC,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAChC,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAA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AC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,iCAA8B,CAAC,KAAK,CAAC,CAAA;iBACpI;aACF;YAED,IAAI,IAAA,mBAAM,EAAC,QAAQ,CAAC,KAAK,KAAK,EAAE;gBACxB,iBAAiB,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,UAAG,QAAQ,mBAAgB,CAAC,CAAA;gBACrF,IAAA,kBAAK,EAAC,iBAAiB,EAAE,WAAW,CAAC,CAAA;aACtC;iBAAM;gBACL,IAAA,kBAAK,EAAC,UAAG,QAAQ,SAAM,EAAE,WAAW,CAAC,CAAA;aACtC;;;;CACF;AAzID,wBAyIC"} \ No newline at end of file diff --git a/dist/src/generators/page.js b/dist/src/generators/page.js index bd0b230..4b7c0a1 100644 --- a/dist/src/generators/page.js +++ b/dist/src/generators/page.js @@ -44,6 +44,7 @@ var prompts_1 = __importDefault(require("prompts")); var path_1 = require("path"); var fs_jetpack_1 = require("fs-jetpack"); var log_1 = require("../helpers/log"); +var nomenclature_1 = require("../helpers/nomenclature"); function generatePage(path) { var _a, _b; return __awaiter(this, void 0, void 0, function () { @@ -68,24 +69,15 @@ function generatePage(path) { pathArray = path.replace('.tsx', '').split('/'); fileName = pathArray[pathArray.length - 1]; urls = []; - name = fileName.replace(/[^\w\s]/gi, ''); + name = (0, nomenclature_1.formatName)(fileName); pageTemplate = ''; + console.log(name, path); if (path.match(/\[(.*?)\]/g)) { urls = path.match(/\[(.*?)\]/g); urls = urls.map(function (url) { return url.replace(/\[/g, '').replace(/\]/g, ''); }); - name = name[0].toUpperCase() + name.substring(1); pageTemplate = ((_a = (0, fs_jetpack_1.read)((0, path_1.join)(__dirname, '..', 'templates', 'page.url.template'))) === null || _a === void 0 ? void 0 : _a.replaceAll('{{name}}', name).replaceAll('{{url}}', urls.join(', '))) || ''; } else { - if (fileName.indexOf('.') !== -1) { - name = fileName.split('.').map(function (word) { return word[0].toUpperCase() + word.substring(1); }).join(''); - } - else if (fileName.indexOf('-') !== -1) { - name = fileName.split('-').map(function (word) { return word[0].toUpperCase() + word.substring(1); }).join(''); - } - else { - name = name[0].toUpperCase() + name.substring(1); - } pageTemplate = ((_b = (0, fs_jetpack_1.read)((0, path_1.join)(__dirname, '..', 'templates', 'page.template'))) === null || _b === void 0 ? void 0 : _b.replaceAll('{{name}}', name)) || ''; } (0, fs_jetpack_1.write)(pagePath, pageTemplate); diff --git a/dist/src/generators/page.js.map b/dist/src/generators/page.js.map index 1f2481c..3ad30dc 100644 --- a/dist/src/generators/page.js.map +++ b/dist/src/generators/page.js.map @@ -1 +1 @@ -{"version":3,"file":"page.js","sourceRoot":"","sources":["../../../src/generators/page.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA6B;AAC7B,6BAA2B;AAC3B,yCAAgD;AAChD,sCAAoC;AAEpC,SAAsB,YAAY,CAAE,IAAY;;;;;;;oBACxC,QAAQ,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,UAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,SAAM,CAAC,CAAA;yBAE5E,CAAA,IAAA,mBAAM,EAAC,QAAQ,CAAC,KAAK,KAAK,CAAA,EAA1B,wBAA0B;oBACb,qBAAM,IAAA,iBAAO,EAAC;4BAC3B,IAAI,EAAE,SAAS;4BACf,IAAI,EAAE,WAAW;4BACjB,OAAO,EAAE,yCAAyC;yBACnD,CAAC,EAAA;;oBAJI,MAAM,GAAG,SAIb;oBAEF,IAAI,MAAM,CAAC,SAAS,KAAK,KAAK,EAAE;wBAC9B,sBAAM;qBACP;;;oBAGG,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;oBAC/C,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,G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eAAe,CAAC,CAAC,0CAAE,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,KAAI,EAAE,CAAA;qBAC7G;oBAED,IAAA,kBAAK,EAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;oBAC7B,IAAA,SAAG,EAAC,oCAAwB,IAAI,SAAM,CAAC,KAAK,CAAC,CAAA;;;;;CAC9C;AAjCD,oCAiCC"} \ No newline at end of file diff --git a/dist/src/generators/prisma.d.ts b/dist/src/generators/prisma.d.ts index 9509d28..854f145 100644 --- a/dist/src/generators/prisma.d.ts +++ b/dist/src/generators/prisma.d.ts @@ -1 +1,8 @@ +interface ModelType { + name: string; + type: string; + imported: boolean; +} +export declare function generateImports(models: ModelType[]): string; export declare function generatePrismaTypes(): Promise; +export {}; diff --git a/dist/src/generators/prisma.js b/dist/src/generators/prisma.js index 25d2847..51640ba 100644 --- a/dist/src/generators/prisma.js +++ b/dist/src/generators/prisma.js @@ -72,7 +72,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.generatePrismaTypes = void 0; +exports.generatePrismaTypes = exports.generateImports = void 0; var path_1 = require("path"); var fs_jetpack_1 = require("fs-jetpack"); var log_1 = require("../helpers/log"); @@ -91,13 +91,15 @@ var typeMatches = [ } ]; function formatModel(models) { - var e_1, _a, e_2, _b; + var e_1, _a, e_2, _b, e_3, _c; var formattedModels = []; + var names = models.map(function (item) { return item.name.toUpperCase(); }); try { for (var models_1 = __values(models), models_1_1 = models_1.next(); !models_1_1.done; models_1_1 = models_1.next()) { var model = models_1_1.value; var type = model.type.toUpperCase().trim(); var tm = type.replaceAll('[]', ''); + var imported = false; var newType = 'any'; try { for (var typeMatches_1 = (e_2 = void 0, __values(typeMatches)), typeMatches_1_1 = typeMatches_1.next(); !typeMatches_1_1.done; typeMatches_1_1 = typeMatches_1.next()) { @@ -114,13 +116,32 @@ function formatModel(models) { } finally { if (e_2) throw e_2.error; } } + if (newType === 'any' && names.includes(model.name.toUpperCase())) { + try { + for (var models_2 = (e_3 = void 0, __values(models)), models_2_1 = models_2.next(); !models_2_1.done; models_2_1 = models_2.next()) { + var model_1 = models_2_1.value; + if (type === model_1.type.toUpperCase().trim()) { + newType = model_1.name[0].toUpperCase() + model_1.name.substring(1) + 'Type'; + imported = true; + } + } + } + catch (e_3_1) { e_3 = { error: e_3_1 }; } + finally { + try { + if (models_2_1 && !models_2_1.done && (_c = models_2.return)) _c.call(models_2); + } + finally { if (e_3) throw e_3.error; } + } + } var inputType = newType; if (type.indexOf('[]') !== -1) { inputType += '[]'; } formattedModels.push({ name: model.name, - type: inputType + type: inputType, + imported: imported }); } } @@ -133,10 +154,37 @@ function formatModel(models) { } return formattedModels; } +function generateImports(models) { + var e_4, _a; + var output = ''; + var hasImports = false; + try { + for (var models_3 = __values(models), models_3_1 = models_3.next(); !models_3_1.done; models_3_1 = models_3.next()) { + var model = models_3_1.value; + if (model.imported) { + var name = model.name[0].toUpperCase() + model.name.substring(1); + output += "import ".concat(name, "Type from 'types/prisma/").concat(name, "'\n"); + hasImports = true; + } + } + } + catch (e_4_1) { e_4 = { error: e_4_1 }; } + finally { + try { + if (models_3_1 && !models_3_1.done && (_a = models_3.return)) _a.call(models_3); + } + finally { if (e_4) throw e_4.error; } + } + if (hasImports) { + output += '\n'; + } + return output; +} +exports.generateImports = generateImports; function generatePrismaTypes() { return __awaiter(this, void 0, void 0, function () { - var prismaPath, prismaFile, matches, matches_1, matches_1_1, match, models, index, data, name, match2, indexEnd, modelContent, lines, lines_1, lines_1_1, line, lineFmt, tokens, tokenFmt, name_1, type, dataMap, typeFile, typeInject, dataMap_1, dataMap_1_1, item, typePath; - var e_3, _a, e_4, _b, e_5, _c; + var prismaPath, prismaFile, matches, matches_1, matches_1_1, match, models, index, data, name, match2, indexEnd, modelContent, lines, lines_1, lines_1_1, line, lineFmt, tokens, tokenFmt, name_1, type, dataMap, importMap, typeFile, typeInject, dataMap_1, dataMap_1_1, item, typePath; + var e_5, _a, e_6, _b, e_7, _c; return __generator(this, function (_d) { prismaPath = (0, path_1.join)(process.cwd(), 'prisma', 'schema.prisma'); prismaFile = (0, fs_jetpack_1.read)(prismaPath) || ''; @@ -156,7 +204,7 @@ function generatePrismaTypes() { name = data.slice(0, indexEnd).split('{')[0].replace('model', '').trim(); lines = modelContent.split('\n').filter(function (line) { return line.indexOf('@@') === -1; }); try { - for (lines_1 = (e_4 = void 0, __values(lines)), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) { + for (lines_1 = (e_6 = void 0, __values(lines)), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) { line = lines_1_1.value; lineFmt = line.trim(); tokens = lineFmt.split(' '); @@ -164,47 +212,49 @@ function generatePrismaTypes() { name_1 = (tokenFmt[0] || ''); type = (tokenFmt[1] || '').toLowerCase(); if (name_1 && type) { - models.push({ name: name_1, type: type }); + models.push({ name: name_1, type: type, imported: false }); } } } - catch (e_4_1) { e_4 = { error: e_4_1 }; } + catch (e_6_1) { e_6 = { error: e_6_1 }; } finally { try { if (lines_1_1 && !lines_1_1.done && (_b = lines_1.return)) _b.call(lines_1); } - finally { if (e_4) throw e_4.error; } + finally { if (e_6) throw e_6.error; } } } dataMap = formatModel(models); - typeFile = "export interface ".concat(name, "Type {{{injection}}}") + '\n\n' + "export default ".concat(name, "Type") + '\n'; + importMap = generateImports(dataMap); + typeFile = "{{imports}}" + "export interface ".concat(name, "Type {{{injection}}}") + '\n\n' + "export default ".concat(name, "Type") + '\n'; typeInject = ''; try { - for (dataMap_1 = (e_5 = void 0, __values(dataMap)), dataMap_1_1 = dataMap_1.next(); !dataMap_1_1.done; dataMap_1_1 = dataMap_1.next()) { + for (dataMap_1 = (e_7 = void 0, __values(dataMap)), dataMap_1_1 = dataMap_1.next(); !dataMap_1_1.done; dataMap_1_1 = dataMap_1.next()) { item = dataMap_1_1.value; typeInject += '\t' + item.name + '?: ' + item.type + '\n'; } } - catch (e_5_1) { e_5 = { error: e_5_1 }; } + catch (e_7_1) { e_7 = { error: e_7_1 }; } finally { try { if (dataMap_1_1 && !dataMap_1_1.done && (_c = dataMap_1.return)) _c.call(dataMap_1); } - finally { if (e_5) throw e_5.error; } + finally { if (e_7) throw e_7.error; } } typeFile = typeFile.replace('{{injection}}', '\n' + typeInject); + typeFile = typeFile.replace('{{imports}}', importMap); typePath = (0, path_1.join)(process.cwd(), 'types', 'prisma', "".concat(name, ".tsx")); (0, log_1.Log)(" \u2705 Generated types/prisma/".concat(name, ".tsx").green); (0, fs_jetpack_1.write)(typePath, typeFile || ''); } } } - catch (e_3_1) { e_3 = { error: e_3_1 }; } + catch (e_5_1) { e_5 = { error: e_5_1 }; } finally { try { if (matches_1_1 && !matches_1_1.done && (_a = matches_1.return)) _a.call(matches_1); } - finally { if (e_3) throw e_3.error; } + finally { if (e_5) throw e_5.error; } } return [2 /*return*/]; }); diff --git a/dist/src/generators/prisma.js.map b/dist/src/generators/prisma.js.map index 87fc80e..c0bc276 100644 --- a/dist/src/generators/prisma.js.map +++ b/dist/src/generators/prisma.js.map @@ -1 +1 @@ -{"version":3,"file":"prisma.js","sourceRoot":"","sources":["../../../src/generators/prisma.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAA2B;AAC3B,yCAAwC;AACxC,sCAAoC;AAYpC,IAAM,WAAW,GAAG;IAClB;QACE,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC;KAChF;IACD;QACE,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC;KAC/C;IACD;QACE,IAAI,EAAE,MAAM;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gCACb,UAAU,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;6BAC1D;;;;;;;;;wBAED,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,GAAG,UAAU,CAAC,CAAA;wBAC/D,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,aAAa,EAAE,SAAS,CAAC,CAAA;wBAC/C,QAAQ,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAG,IAAI,SAAM,CAAC,CAAA;wBAEtE,IAAA,SAAG,EAAC,6CAAiC,IAAI,SAAM,CAAC,KAAK,CAAC,CAAA;wBACtD,IAAA,kBAAK,EAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;qBAChC;iBACF;;;;;;;;;;;;CACF;AArDD,kDAqDC"} \ No newline at end of file diff --git a/dist/src/helpers/nomenclature.d.ts b/dist/src/helpers/nomenclature.d.ts new file mode 100644 index 0000000..5ef71ed --- /dev/null +++ b/dist/src/helpers/nomenclature.d.ts @@ -0,0 +1 @@ +export declare function formatName(_fileName: string): string; diff --git a/dist/src/helpers/nomenclature.js b/dist/src/helpers/nomenclature.js new file mode 100644 index 0000000..5def5c5 --- /dev/null +++ b/dist/src/helpers/nomenclature.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.formatName = void 0; +function formatName(_fileName) { + var fileName = _fileName.replaceAll('.ts', '').replaceAll('.tsx', '').replaceAll('[', '').replaceAll(']', ''); + var name = fileName; + if (fileName.indexOf('.') !== -1) { + name = fileName.split('.').map(function (word) { return word[0].toUpperCase() + word.substring(1); }).join(''); + } + else if (fileName.indexOf('-') !== -1) { + name = fileName.split('-').map(function (word) { return word[0].toUpperCase() + word.substring(1); }).join(''); + } + else { + name = name[0].toUpperCase() + name.substring(1); + } + return name; +} +exports.formatName = formatName; +//# sourceMappingURL=nomenclature.js.map \ No newline at end of file diff --git a/dist/src/helpers/nomenclature.js.map b/dist/src/helpers/nomenclature.js.map new file mode 100644 index 0000000..e63dd8f --- /dev/null +++ b/dist/src/helpers/nomenclature.js.map @@ -0,0 +1 @@ +{"version":3,"file":"nomenclature.js","sourceRoot":"","sources":["../../../src/helpers/nomenclature.ts"],"names":[],"mappings":";;;AAAA,SAAgB,UAAU,CAAC,SAAiB;IAC1C,IAAI,QAAQ,GAAG,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IAC7G,IAAI,IAAI,GAAG,QAAQ,CAAA;IAEnB,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;QAChC,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAzC,CAAyC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;KAC3F;SAAM,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;QACvC,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAzC,CAAyC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;KAC3F;SAAM;QACL,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;KACjD;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAbD,gCAaC"} \ No newline at end of file diff --git a/dist/src/printer.js b/dist/src/printer.js index 6bce3c6..ea3c063 100755 --- a/dist/src/printer.js +++ b/dist/src/printer.js @@ -56,7 +56,7 @@ var prisma_1 = require("./generators/prisma"); var superagent_1 = require("./generators/superagent"); exports.Printer = new commander_1.Command('🖨️ Printer'); exports.Printer - .version('1.3.2') + .version('1.3.3') .description('🖨️ Printer: Automation Tooling for Next, Redux and Prisma.') .option('-a, --no-action', 'do not inject actions', false) .option('-s, --no-state', 'do not inject state', false); @@ -116,7 +116,7 @@ exports.Printer switch (_a.label) { case 0: (0, config_1.registerConfig)(); - (0, log_1.Log)("\uD83D\uDC89 Injecting ".concat(slice, " into ").concat(component).green); + (0, log_1.Log)("\uD83D\uDC89 Injecting ".concat(slice, " into ").concat(component.replaceAll('.tsx', '')).green); return [4 /*yield*/, (0, inject_1.inject)(slice, component, exports.Printer.opts())]; case 1: _a.sent(); diff --git a/dist/src/printer.js.map b/dist/src/printer.js.map index 3a235f8..25c7b14 100644 --- a/dist/src/printer.js.map +++ b/dist/src/printer.js.map @@ -1 +1 @@ -{"version":3,"file":"printer.js","sourceRoot":"","sources":["../../src/printer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kBAAe;AACf,uCAAmC;AACnC,qCAAmC;AACnC,mCAAyC;AACzC,wCAAqD;AACrD,oDAA0D;AAC1D,4CAAkD;AAClD,0CAAgD;AAChD,0CAAgD;AAChD,wCAA8C;AAC9C,0CAAgD;AAChD,0CAAgD;AAChD,8CAA4C;AAC5C,8CAAyD;AACzD,sDAA0E;AAE7D,QAAA,OAAO,GAAG,IAAI,mBAAO,CAAC,aAAa,CAAC,CAAA;AAEjD,eAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC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,uBAAc,GAAE,CAAA;gBAChB,IAAA,SAAG,EAAC,6BAA6B,CAAC,KAAK,CAAC,CAAA;gBACxC,qBAAM,IAAA,4BAAmB,GAAE,EAAA;;gBAA3B,SAA2B,CAAA;;;;KAC5B,CAAC,CAAA;AAEJ,eAAO;KACJ,OAAO,CAAC,cAAc,CAAC;KACvB,WAAW,CAAC,gDAAgD,CAAC;KAC7D,MAAM,CAAC,UAAM,KAAK;;;;gBACjB,IAAA,uBAAc,GAAE,CAAA;gBAChB,IAAA,SAAG,EAAC,4DAA2C,KAAK,CAAE,CAAC,KAAK,CAAC,CAAA;gBAC7D,qBAAM,IAAA,mBAAY,EAAC,KAAK,CAAC,EAAA;;gBAAzB,SAAyB,CAAA;;;;KAC1B,CAAC,CAAA;AAEJ,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,EAAE;IACnC,eAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5B"} \ No newline at end of file diff --git a/package.json b/package.json index 26f3e1a..42f9024 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@printerframework/cli", "description": "🖨️ Automation Tooling for Next, Redux and Prisma.", - "version": "1.3.2", + "version": "1.3.3", "private": false, "preferGlobal": true, "repository": "https://github.com/PrinterFramework/CLI.git", diff --git a/src/generators/api.ts b/src/generators/api.ts index b847541..6d3c6eb 100644 --- a/src/generators/api.ts +++ b/src/generators/api.ts @@ -2,6 +2,7 @@ import prompts from 'prompts' import { join } from 'path' import { exists, read, write } from 'fs-jetpack' import { Log } from '../helpers/log' +import { formatName } from '../helpers/nomenclature' export async function generateApi (path: string) { const apiPath = join(process.cwd(), 'pages', 'api', `${path}.tsx`) @@ -20,15 +21,7 @@ export async function generateApi (path: string) { const pathArray = path.split('/') const fileName = pathArray[pathArray.length - 1] - let name = fileName.replace(/[^\w\s]/gi, '') - - if (fileName.indexOf('.') !== -1) { - name = fileName.split('.').map(word => word[0].toUpperCase() + word.substring(1)).join('') - } else if (fileName.indexOf('-') !== -1) { - name = fileName.split('-').map(word => word[0].toUpperCase() + word.substring(1)).join('') - } else { - name = name[0].toUpperCase() + name.substring(1) - } + const name = formatName(fileName) const apiTemplate = read(join(__dirname, '..', 'templates', 'api.template'))?.replaceAll('{{name}}', name) diff --git a/src/generators/component.ts b/src/generators/component.ts index 8f877e4..75b12de 100644 --- a/src/generators/component.ts +++ b/src/generators/component.ts @@ -3,6 +3,7 @@ import { join } from 'path' import { exists, read, write } from 'fs-jetpack' import { Log } from '../helpers/log' import { Config } from '../config' +import { formatName } from '../helpers/nomenclature' export async function generateComponent (path: string) { if (exists(join(process.cwd(), path)) || exists(join(process.cwd(), `${path.replace('.tsx', '')}.tsx`))) { @@ -19,15 +20,7 @@ export async function generateComponent (path: string) { const pathArray = path.replace('.tsx', '').split('/') const fileName = pathArray[pathArray.length - 1] - let name = fileName.replace(/[^\w\s]/gi, '') - - if (fileName.indexOf('.') !== -1) { - name = fileName.split('.').map(word => word[0].toUpperCase() + word.substring(1)).join('') - } else if (fileName.indexOf('-') !== -1) { - name = fileName.split('-').map(word => word[0].toUpperCase() + word.substring(1)).join('') - } else { - name = name[0].toUpperCase() + name.substring(1) - } + const name = formatName(fileName) if (Config.componentFolder === true) { let component = read(join(__dirname, '..', 'templates', 'component', 'component.nostyle.template'))?.replaceAll('{{name}}', name).replaceAll('{{prefix}}', fileName).replaceAll('{{path}}', path) diff --git a/src/generators/inject.ts b/src/generators/inject.ts index 5fb32c9..6c9de5d 100644 --- a/src/generators/inject.ts +++ b/src/generators/inject.ts @@ -9,20 +9,17 @@ export interface OptsType { } export async function inject (slice: string, component: string, opts: OptsType) { + component = component.replaceAll('.tsx', '') const filePath = join(process.cwd(), component) const pathArray = component.split('/') const fileName = pathArray[pathArray.length - 1] let fileContents = '' - if (filePath.indexOf('.tsx') === -1) { - if (exists(filePath) === 'dir') { - const fileComponentPath = join(process.cwd(), component, `${fileName}.component.tsx`) - fileContents = read(fileComponentPath) || '' - } else { - fileContents = read(`${filePath}.tsx`) || '' - } + if (exists(filePath) === 'dir') { + const fileComponentPath = join(process.cwd(), component, `${fileName}.component.tsx`) + fileContents = read(fileComponentPath) || '' } else { - fileContents = read(`${filePath}`) || '' + fileContents = read(`${filePath}.tsx`) || '' } const slicePath = join(process.cwd(), 'redux', 'slice', `${slice}.tsx`) diff --git a/src/generators/page.ts b/src/generators/page.ts index 0853367..fed29a8 100644 --- a/src/generators/page.ts +++ b/src/generators/page.ts @@ -2,6 +2,7 @@ import prompts from 'prompts' import { join } from 'path' import { exists, read, write } from 'fs-jetpack' import { Log } from '../helpers/log' +import { formatName } from '../helpers/nomenclature' export async function generatePage (path: string) { const pagePath = join(process.cwd(), 'pages', `${path.replace('.tsx', '')}.tsx`) @@ -21,24 +22,16 @@ export async function generatePage (path: string) { const pathArray = path.replace('.tsx', '').split('/') const fileName = pathArray[pathArray.length - 1] let urls = [] - let name = fileName.replace(/[^\w\s]/gi, '') + const name = formatName(fileName) let pageTemplate = '' + console.log(name, path) + if (path.match(/\[(.*?)\]/g)) { urls = path.match(/\[(.*?)\]/g) as string[] urls = urls.map(url => url.replace(/\[/g, '').replace(/\]/g, '')) - name = name[0].toUpperCase() + name.substring(1) - pageTemplate = read(join(__dirname, '..', 'templates', 'page.url.template'))?.replaceAll('{{name}}', name).replaceAll('{{url}}', urls.join(', ')) || '' } else { - if (fileName.indexOf('.') !== -1) { - name = fileName.split('.').map(word => word[0].toUpperCase() + word.substring(1)).join('') - } else if (fileName.indexOf('-') !== -1) { - name = fileName.split('-').map(word => word[0].toUpperCase() + word.substring(1)).join('') - } else { - name = name[0].toUpperCase() + name.substring(1) - } - pageTemplate = read(join(__dirname, '..', 'templates', 'page.template'))?.replaceAll('{{name}}', name) || '' } diff --git a/src/generators/prisma.ts b/src/generators/prisma.ts index 9e61e01..8a6530f 100644 --- a/src/generators/prisma.ts +++ b/src/generators/prisma.ts @@ -5,6 +5,7 @@ import { Log } from '../helpers/log' interface ModelType { name: string type: string + imported: boolean } interface TypeMatches { @@ -29,10 +30,12 @@ const typeMatches = [ function formatModel (models: ModelType[]): ModelType[] { const formattedModels = [] as ModelType[] + const names = models.map((item) => item.name.toUpperCase()) for (const model of models) { const type = model.type.toUpperCase().trim() const tm = type.replaceAll('[]', '') + let imported = false let newType = 'any' for (const typeMatch of typeMatches) { @@ -41,19 +44,45 @@ function formatModel (models: ModelType[]): ModelType[] { } } + if (newType === 'any' && names.includes(model.name.toUpperCase())) { + for (const model of models) { + if (type === model.type.toUpperCase().trim()) { + newType = model.name[0].toUpperCase() + model.name.substring(1) + 'Type' + imported = true + } + } + } + let inputType = newType if (type.indexOf('[]') !== -1) { inputType += '[]' } formattedModels.push({ name: model.name, - type: inputType + type: inputType, + imported }) } return formattedModels } +export function generateImports (models: ModelType[]): string { + let output = '' + let hasImports = false + for (const model of models) { + if (model.imported) { + const name = model.name[0].toUpperCase() + model.name.substring(1) + output += `import ${name}Type from 'types/prisma/${name}'\n` + hasImports = true + } + } + if (hasImports) { + output += '\n' + } + return output +} + export async function generatePrismaTypes () { const prismaPath = join(process.cwd(), 'prisma', 'schema.prisma') const prismaFile = read(prismaPath) || '' @@ -84,13 +113,15 @@ export async function generatePrismaTypes () { const type = (tokenFmt[1] || '').toLowerCase() if (name && type) { - models.push({ name, type }) + models.push({ name, type, imported: false }) } } } const dataMap = formatModel(models) - let typeFile = `export interface ${name}Type {{{injection}}}` + '\n\n' + `export default ${name}Type` + '\n' + const importMap = generateImports(dataMap) + + let typeFile = '{{imports}}' + `export interface ${name}Type {{{injection}}}` + '\n\n' + `export default ${name}Type` + '\n' let typeInject = '' for (const item of dataMap) { @@ -98,6 +129,7 @@ export async function generatePrismaTypes () { } typeFile = typeFile.replace('{{injection}}', '\n' + typeInject) + typeFile = typeFile.replace('{{imports}}', importMap) const typePath = join(process.cwd(), 'types', 'prisma', `${name}.tsx`) Log(` ✅ Generated types/prisma/${name}.tsx`.green) diff --git a/src/helpers/nomenclature.ts b/src/helpers/nomenclature.ts new file mode 100644 index 0000000..7224831 --- /dev/null +++ b/src/helpers/nomenclature.ts @@ -0,0 +1,14 @@ +export function formatName (_fileName: string) { + const fileName = _fileName.replaceAll('.ts', '').replaceAll('.tsx', '').replaceAll('[', '').replaceAll(']', '') + let name = fileName + + if (fileName.indexOf('.') !== -1) { + name = fileName.split('.').map(word => word[0].toUpperCase() + word.substring(1)).join('') + } else if (fileName.indexOf('-') !== -1) { + name = fileName.split('-').map(word => word[0].toUpperCase() + word.substring(1)).join('') + } else { + name = name[0].toUpperCase() + name.substring(1) + } + + return name +} diff --git a/src/printer.ts b/src/printer.ts index c4ff7f7..8d52f78 100644 --- a/src/printer.ts +++ b/src/printer.ts @@ -17,7 +17,7 @@ import { SuperagentTypes, injectSupergent } from './generators/superagent' export const Printer = new Command('🖨️ Printer') Printer - .version('1.3.2') + .version('1.3.3') .description('🖨️ Printer: Automation Tooling for Next, Redux and Prisma.') .option('-a, --no-action', 'do not inject actions', false) .option('-s, --no-state', 'do not inject state', false) @@ -54,7 +54,7 @@ Printer .description('Inject a slice into a component or page') .action(async (slice, component) => { registerConfig() - Log(`💉 Injecting ${slice} into ${component}`.green) + Log(`💉 Injecting ${slice} into ${component.replaceAll('.tsx', '')}`.green) await inject(slice, component, Printer.opts()) })