From 4498e8e4bd1d4725a57ca7d6478ba331d20a107f Mon Sep 17 00:00:00 2001 From: Chris Cates Date: Mon, 26 Jun 2023 18:16:44 -0400 Subject: [PATCH] v2.1.0 - New Scaffolding Flows --- CHANGELOG.md | 14 ++++ README.md | 2 +- dist/src/generators/error.d.ts | 1 + dist/src/generators/error.js | 81 +++++++++++++++++++ dist/src/generators/error.js.map | 1 + dist/src/generators/layout.d.ts | 1 + dist/src/generators/layout.js | 81 +++++++++++++++++++ dist/src/generators/layout.js.map | 1 + dist/src/generators/loading.d.ts | 1 + dist/src/generators/loading.js | 81 +++++++++++++++++++ dist/src/generators/loading.js.map | 1 + dist/src/printer.js | 53 +++++++++++- dist/src/printer.js.map | 2 +- dist/src/templates/error.template | 23 ++++++ dist/src/templates/layout.template | 18 +++++ dist/src/templates/loading.template | 7 ++ .../src/templates/new/app/layout.tsx.template | 12 ++- package.json | 2 +- src/generators/error.ts | 29 +++++++ src/generators/layout.ts | 29 +++++++ src/generators/loading.ts | 29 +++++++ src/printer.ts | 32 +++++++- src/templates/error.template | 23 ++++++ src/templates/layout.template | 18 +++++ src/templates/loading.template | 7 ++ src/templates/new/app/layout.tsx.template | 12 ++- 26 files changed, 550 insertions(+), 11 deletions(-) create mode 100644 dist/src/generators/error.d.ts create mode 100644 dist/src/generators/error.js create mode 100644 dist/src/generators/error.js.map create mode 100644 dist/src/generators/layout.d.ts create mode 100644 dist/src/generators/layout.js create mode 100644 dist/src/generators/layout.js.map create mode 100644 dist/src/generators/loading.d.ts create mode 100644 dist/src/generators/loading.js create mode 100644 dist/src/generators/loading.js.map create mode 100644 dist/src/templates/error.template create mode 100644 dist/src/templates/layout.template create mode 100644 dist/src/templates/loading.template create mode 100644 src/generators/error.ts create mode 100644 src/generators/layout.ts create mode 100644 src/generators/loading.ts create mode 100644 src/templates/error.template create mode 100644 src/templates/layout.template create mode 100644 src/templates/loading.template diff --git a/CHANGELOG.md b/CHANGELOG.md index b807927..3edcb42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # 🛠️ CHANGELOG +## 2.1.0 + +- Updated how metadata is handled + +- Added 3 new commands + +```bash +printer layout [path] +printer loading [path] +printer error [path] +``` + +These commands behave similar to the `page` command. But instead generate layout, loading and error components for pages. + ## v2.0.2 - Ensure API routes have `application/json` header diff --git a/README.md b/README.md index 320a002..e1af416 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## Automation Tooling for Next, Redux and Prisma ![license](https://img.shields.io/badge/license-AGPLv3-blue.svg) -![version](https://img.shields.io/badge/version-2.0.2-blue.svg) +![version](https://img.shields.io/badge/version-2.1.0-blue.svg) [![CircleCI](https://circleci.com/gh/PrinterFramework/CLI.svg?style=svg)](https://circleci.com/gh/PrinterFramework/CLI) [![codecov](https://codecov.io/gh/PrinterFramework/CLI/branch/master/graph/badge.svg)](https://codecov.io/gh/PrinterFramework/CLI) diff --git a/dist/src/generators/error.d.ts b/dist/src/generators/error.d.ts new file mode 100644 index 0000000..3e11ed1 --- /dev/null +++ b/dist/src/generators/error.d.ts @@ -0,0 +1 @@ +export declare function generateError(path: string): Promise; diff --git a/dist/src/generators/error.js b/dist/src/generators/error.js new file mode 100644 index 0000000..f5a4d52 --- /dev/null +++ b/dist/src/generators/error.js @@ -0,0 +1,81 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.generateError = void 0; +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 generateError(path) { + var _a; + return __awaiter(this, void 0, void 0, function () { + var errorPath, result, pathArray, fileName, name, errorTemplate; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + errorPath = (0, path_1.join)(process.cwd(), 'app', "".concat(path.replace('.tsx', ''), "/error.tsx")); + if (!((0, fs_jetpack_1.exists)(errorPath) !== false)) return [3 /*break*/, 2]; + return [4 /*yield*/, (0, prompts_1.default)({ + type: 'confirm', + name: 'overwrite', + message: 'A error component already exists, overwrite it?' + })]; + case 1: + result = _b.sent(); + if (result.overwrite === false) { + return [2 /*return*/]; + } + _b.label = 2; + case 2: + pathArray = path.replace('.tsx', '').split('/'); + fileName = pathArray[pathArray.length - 1]; + name = (0, nomenclature_1.formatName)(fileName); + errorTemplate = ((_a = (0, fs_jetpack_1.read)((0, path_1.join)(__dirname, '..', 'templates', 'error.template'))) === null || _a === void 0 ? void 0 : _a.replaceAll('{{name}}', name)) || ''; + (0, fs_jetpack_1.write)(errorPath, errorTemplate); + (0, log_1.Log)(" \u2705 Created app/".concat(path, "/error.tsx").green); + return [2 /*return*/]; + } + }); + }); +} +exports.generateError = generateError; +//# sourceMappingURL=error.js.map \ No newline at end of file diff --git a/dist/src/generators/error.js.map b/dist/src/generators/error.js.map new file mode 100644 index 0000000..75ea1e8 --- /dev/null +++ b/dist/src/generators/error.js.map @@ -0,0 +1 @@ +{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/generators/error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA6B;AAC7B,6BAA2B;AAC3B,yCAAgD;AAChD,sCAAoC;AACpC,wDAAoD;AAEpD,SAAsB,aAAa,CAAE,IAAY;;;;;;;oBACzC,SAAS,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,UAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,eAAY,CAAC,CAAA;yBAEjF,CAAA,IAAA,mBAAM,EAAC,SAAS,CAAC,KAAK,KAAK,CAAA,EAA3B,wBAA2B;oBACd,qBAAM,IAAA,iBAAO,EAAC;4BAC3B,IAAI,EAAE,SAAS;4BACf,IAAI,EAAE,WAAW;4BACjB,OAAO,EAAE,iDAAiD;yBAC3D,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,GAAG,CAAC,CAAC,CAAA;oBAC1C,IAAI,GAAG,IAAA,yBAAU,EAAC,QAAQ,CAAC,CAAA;oBAC3B,aAAa,GAAG,CAAA,MAAA,IAAA,iBAAI,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC,0CAAE,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,KAAI,EAAE,CAAA;oBAEpH,IAAA,kBAAK,EAAC,SAAS,EAAE,aAAa,CAAC,CAAA;oBAC/B,IAAA,SAAG,EAAC,kCAAsB,IAAI,eAAY,CAAC,KAAK,CAAC,CAAA;;;;;CAClD;AAtBD,sCAsBC"} \ No newline at end of file diff --git a/dist/src/generators/layout.d.ts b/dist/src/generators/layout.d.ts new file mode 100644 index 0000000..bcdb714 --- /dev/null +++ b/dist/src/generators/layout.d.ts @@ -0,0 +1 @@ +export declare function generateLayout(path: string): Promise; diff --git a/dist/src/generators/layout.js b/dist/src/generators/layout.js new file mode 100644 index 0000000..18922ec --- /dev/null +++ b/dist/src/generators/layout.js @@ -0,0 +1,81 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.generateLayout = void 0; +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 generateLayout(path) { + var _a; + return __awaiter(this, void 0, void 0, function () { + var layoutPath, result, pathArray, fileName, name, layoutTemplate; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + layoutPath = (0, path_1.join)(process.cwd(), 'app', "".concat(path.replace('.tsx', ''), "/layout.tsx")); + if (!((0, fs_jetpack_1.exists)(layoutPath) !== false)) return [3 /*break*/, 2]; + return [4 /*yield*/, (0, prompts_1.default)({ + type: 'confirm', + name: 'overwrite', + message: 'A layout component already exists, overwrite it?' + })]; + case 1: + result = _b.sent(); + if (result.overwrite === false) { + return [2 /*return*/]; + } + _b.label = 2; + case 2: + pathArray = path.replace('.tsx', '').split('/'); + fileName = pathArray[pathArray.length - 1]; + name = (0, nomenclature_1.formatName)(fileName); + layoutTemplate = ((_a = (0, fs_jetpack_1.read)((0, path_1.join)(__dirname, '..', 'templates', 'layout.template'))) === null || _a === void 0 ? void 0 : _a.replaceAll('{{name}}', name)) || ''; + (0, fs_jetpack_1.write)(layoutPath, layoutTemplate); + (0, log_1.Log)(" \u2705 Created app/".concat(path, "/layout.tsx").green); + return [2 /*return*/]; + } + }); + }); +} +exports.generateLayout = generateLayout; +//# sourceMappingURL=layout.js.map \ No newline at end of file diff --git a/dist/src/generators/layout.js.map b/dist/src/generators/layout.js.map new file mode 100644 index 0000000..de30e0d --- /dev/null +++ b/dist/src/generators/layout.js.map @@ -0,0 +1 @@ +{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../../src/generators/layout.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA6B;AAC7B,6BAA2B;AAC3B,yCAAgD;AAChD,sCAAoC;AACpC,wDAAoD;AAEpD,SAAsB,cAAc,CAAE,IAAY;;;;;;;oBAC1C,UAAU,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,UAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAa,CAAC,CAAA;yBAEnF,CAAA,IAAA,mBAAM,EAAC,UAAU,CAAC,KAAK,KAAK,CAAA,EAA5B,wBAA4B;oBACf,qBAAM,IAAA,iBAAO,EAAC;4BAC3B,IAAI,EAAE,SAAS;4BACf,IAAI,EAAE,WAAW;4BACjB,OAAO,EAAE,kDAAkD;yBAC5D,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,GAAG,CAAC,CAAC,CAAA;oBAC1C,IAAI,GAAG,IAAA,yBAAU,EAAC,QAAQ,CAAC,CAAA;oBAC3B,cAAc,GAAG,CAAA,MAAA,IAAA,iBAAI,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC,0CAAE,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,KAAI,EAAE,CAAA;oBAEtH,IAAA,kBAAK,EAAC,UAAU,EAAE,cAAc,CAAC,CAAA;oBACjC,IAAA,SAAG,EAAC,kCAAsB,IAAI,gBAAa,CAAC,KAAK,CAAC,CAAA;;;;;CACnD;AAtBD,wCAsBC"} \ No newline at end of file diff --git a/dist/src/generators/loading.d.ts b/dist/src/generators/loading.d.ts new file mode 100644 index 0000000..a2e000f --- /dev/null +++ b/dist/src/generators/loading.d.ts @@ -0,0 +1 @@ +export declare function generateLoading(path: string): Promise; diff --git a/dist/src/generators/loading.js b/dist/src/generators/loading.js new file mode 100644 index 0000000..50af9e5 --- /dev/null +++ b/dist/src/generators/loading.js @@ -0,0 +1,81 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.generateLoading = void 0; +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 generateLoading(path) { + var _a; + return __awaiter(this, void 0, void 0, function () { + var loadingPath, result, pathArray, fileName, name, loadingTemplate; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + loadingPath = (0, path_1.join)(process.cwd(), 'app', "".concat(path.replace('.tsx', ''), "/loading.tsx")); + if (!((0, fs_jetpack_1.exists)(loadingPath) !== false)) return [3 /*break*/, 2]; + return [4 /*yield*/, (0, prompts_1.default)({ + type: 'confirm', + name: 'overwrite', + message: 'A loading component already exists, overwrite it?' + })]; + case 1: + result = _b.sent(); + if (result.overwrite === false) { + return [2 /*return*/]; + } + _b.label = 2; + case 2: + pathArray = path.replace('.tsx', '').split('/'); + fileName = pathArray[pathArray.length - 1]; + name = (0, nomenclature_1.formatName)(fileName); + loadingTemplate = ((_a = (0, fs_jetpack_1.read)((0, path_1.join)(__dirname, '..', 'templates', 'loading.template'))) === null || _a === void 0 ? void 0 : _a.replaceAll('{{name}}', name)) || ''; + (0, fs_jetpack_1.write)(loadingPath, loadingTemplate); + (0, log_1.Log)(" \u2705 Created app/".concat(path, "/loading.tsx").green); + return [2 /*return*/]; + } + }); + }); +} +exports.generateLoading = generateLoading; +//# sourceMappingURL=loading.js.map \ No newline at end of file diff --git a/dist/src/generators/loading.js.map b/dist/src/generators/loading.js.map new file mode 100644 index 0000000..aa82bca --- /dev/null +++ b/dist/src/generators/loading.js.map @@ -0,0 +1 @@ +{"version":3,"file":"loading.js","sourceRoot":"","sources":["../../../src/generators/loading.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA6B;AAC7B,6BAA2B;AAC3B,yCAAgD;AAChD,sCAAoC;AACpC,wDAAoD;AAEpD,SAAsB,eAAe,CAAE,IAAY;;;;;;;oBAC3C,WAAW,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,UAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAc,CAAC,CAAA;yBAErF,CAAA,IAAA,mBAAM,EAAC,WAAW,CAAC,KAAK,KAAK,CAAA,EAA7B,wBAA6B;oBAChB,qBAAM,IAAA,iBAAO,EAAC;4BAC3B,IAAI,EAAE,SAAS;4BACf,IAAI,EAAE,WAAW;4BACjB,OAAO,EAAE,mDAAmD;yBAC7D,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,GAAG,CAAC,CAAC,CAAA;oBAC1C,IAAI,GAAG,IAAA,yBAAU,EAAC,QAAQ,CAAC,CAAA;oBAC3B,eAAe,GAAG,CAAA,MAAA,IAAA,iBAAI,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,kBAAkB,CAAC,CAAC,0CAAE,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,KAAI,EAAE,CAAA;oBAExH,IAAA,kBAAK,EAAC,WAAW,EAAE,eAAe,CAAC,CAAA;oBACnC,IAAA,SAAG,EAAC,kCAAsB,IAAI,iBAAc,CAAC,KAAK,CAAC,CAAA;;;;;CACpD;AAtBD,0CAsBC"} \ No newline at end of file diff --git a/dist/src/printer.js b/dist/src/printer.js index cc016b7..e6b95e4 100755 --- a/dist/src/printer.js +++ b/dist/src/printer.js @@ -48,6 +48,9 @@ var component_1 = require("./generators/component"); var slice_1 = require("./generators/slice"); var type_1 = require("./generators/type"); var page_1 = require("./generators/page"); +var layout_1 = require("./generators/layout"); +var loading_1 = require("./generators/loading"); +var error_1 = require("./generators/error"); var api_1 = require("./generators/api"); var crud_1 = require("./generators/crud"); var scss_1 = require("./generators/scss"); @@ -56,7 +59,7 @@ var prisma_1 = require("./generators/prisma"); var superagent_1 = require("./generators/superagent"); exports.Printer = new commander_1.Command('🖨️ Printer'); exports.Printer - .version('2.0.2') + .version('2.1.0') .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); @@ -156,6 +159,54 @@ exports.Printer } }); }); }); +exports.Printer + .command('layout ') + .description('Generate a new layout component') + .action(function (path) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + (0, config_1.registerConfig)(); + (0, log_1.Log)('👷 Generating new layout component'.green); + return [4 /*yield*/, (0, layout_1.generateLayout)(path)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); +}); }); +exports.Printer + .command('loading ') + .description('Generate a new loading component') + .action(function (path) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + (0, config_1.registerConfig)(); + (0, log_1.Log)('👷 Generating new loading component'.green); + return [4 /*yield*/, (0, loading_1.generateLoading)(path)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); +}); }); +exports.Printer + .command('error ') + .description('Generate a new error component') + .action(function (path) { return __awaiter(void 0, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + (0, config_1.registerConfig)(); + (0, log_1.Log)('👷 Generating new error component'.green); + return [4 /*yield*/, (0, error_1.generateError)(path)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); +}); }); exports.Printer .command('api ') .description('Generate a new Printer API route') diff --git a/dist/src/printer.js.map b/dist/src/printer.js.map index 25c7b14..08806ae 100755 --- 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;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EJ,eAAO;KACJ,OAAO,CAAC,QAAQ,CAAC;KACjB,WAAW,CAAC,6DAA6D,CAAC;KAC1E,MAAM,CAAC;;;;gBACN,IAAA,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/dist/src/templates/error.template b/dist/src/templates/error.template new file mode 100644 index 0000000..4bfc3b3 --- /dev/null +++ b/dist/src/templates/error.template @@ -0,0 +1,23 @@ +'use client' + +import { useEffect } from 'react' + +export interface ErrorI { + error: Error + reset: () => void +} + +export default function ErrorComponent({ error, reset }: ErrorI) { + useEffect(() => { + console.error(error) + }, [error]) + + return ( +
+

Something Went Wrong!

+ reset()}> + Reload Page + +
+ ) +} diff --git a/dist/src/templates/layout.template b/dist/src/templates/layout.template new file mode 100644 index 0000000..4ec5416 --- /dev/null +++ b/dist/src/templates/layout.template @@ -0,0 +1,18 @@ +import { Metadata } from 'next' +import { ReactNode } from 'react' + +export const metadata: Metadata = { + +} + +export interface LayoutI { + children: ReactNode +} + +export default function LayoutComponent({ children }: LayoutI) { + return ( +
+ {children} +
+ ) +} diff --git a/dist/src/templates/loading.template b/dist/src/templates/loading.template new file mode 100644 index 0000000..97ae45c --- /dev/null +++ b/dist/src/templates/loading.template @@ -0,0 +1,7 @@ +export default function LoadingComponent() { + return ( +
+

Please wait... Loading...

+
+ ) +} diff --git a/dist/src/templates/new/app/layout.tsx.template b/dist/src/templates/new/app/layout.tsx.template index c5b62c7..00caeb7 100755 --- a/dist/src/templates/new/app/layout.tsx.template +++ b/dist/src/templates/new/app/layout.tsx.template @@ -1,7 +1,16 @@ import 'scss/printer.scss' +import { Metadata } from 'next' import { ReactNode } from 'react' import { ReduxProvider } from 'redux/provider' +export const metadata: Metadata = { + title: 'Printer', + description: 'Automation Tooling for Next, Redux and Prisma', + icons: { + icon: '' + } +} + export interface LayoutI { children: ReactNode } @@ -9,9 +18,6 @@ export interface LayoutI { export default function LayoutComponent({ children }: LayoutI) { return ( - - Printer - {children} diff --git a/package.json b/package.json index 991fe46..a1eaae3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@printerframework/cli", "description": "🖨️ Automation Tooling for Next, Redux and Prisma.", - "version": "2.0.1", + "version": "2.1.0", "private": false, "preferGlobal": true, "repository": "https://github.com/PrinterFramework/CLI.git", diff --git a/src/generators/error.ts b/src/generators/error.ts new file mode 100644 index 0000000..5d6ddd7 --- /dev/null +++ b/src/generators/error.ts @@ -0,0 +1,29 @@ +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 generateError (path: string) { + const errorPath = join(process.cwd(), 'app', `${path.replace('.tsx', '')}/error.tsx`) + + if (exists(errorPath) !== false) { + const result = await prompts({ + type: 'confirm', + name: 'overwrite', + message: 'A error component already exists, overwrite it?' + }) + + if (result.overwrite === false) { + return + } + } + + const pathArray = path.replace('.tsx', '').split('/') + const fileName = pathArray[pathArray.length - 1] + const name = formatName(fileName) + const errorTemplate = read(join(__dirname, '..', 'templates', 'error.template'))?.replaceAll('{{name}}', name) || '' + + write(errorPath, errorTemplate) + Log(` ✅ Created app/${path}/error.tsx`.green) +} diff --git a/src/generators/layout.ts b/src/generators/layout.ts new file mode 100644 index 0000000..c8c3c4b --- /dev/null +++ b/src/generators/layout.ts @@ -0,0 +1,29 @@ +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 generateLayout (path: string) { + const layoutPath = join(process.cwd(), 'app', `${path.replace('.tsx', '')}/layout.tsx`) + + if (exists(layoutPath) !== false) { + const result = await prompts({ + type: 'confirm', + name: 'overwrite', + message: 'A layout component already exists, overwrite it?' + }) + + if (result.overwrite === false) { + return + } + } + + const pathArray = path.replace('.tsx', '').split('/') + const fileName = pathArray[pathArray.length - 1] + const name = formatName(fileName) + const layoutTemplate = read(join(__dirname, '..', 'templates', 'layout.template'))?.replaceAll('{{name}}', name) || '' + + write(layoutPath, layoutTemplate) + Log(` ✅ Created app/${path}/layout.tsx`.green) +} diff --git a/src/generators/loading.ts b/src/generators/loading.ts new file mode 100644 index 0000000..fad87be --- /dev/null +++ b/src/generators/loading.ts @@ -0,0 +1,29 @@ +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 generateLoading (path: string) { + const loadingPath = join(process.cwd(), 'app', `${path.replace('.tsx', '')}/loading.tsx`) + + if (exists(loadingPath) !== false) { + const result = await prompts({ + type: 'confirm', + name: 'overwrite', + message: 'A loading component already exists, overwrite it?' + }) + + if (result.overwrite === false) { + return + } + } + + const pathArray = path.replace('.tsx', '').split('/') + const fileName = pathArray[pathArray.length - 1] + const name = formatName(fileName) + const loadingTemplate = read(join(__dirname, '..', 'templates', 'loading.template'))?.replaceAll('{{name}}', name) || '' + + write(loadingPath, loadingTemplate) + Log(` ✅ Created app/${path}/loading.tsx`.green) +} diff --git a/src/printer.ts b/src/printer.ts index 0ee2515..7fe8715 100644 --- a/src/printer.ts +++ b/src/printer.ts @@ -7,6 +7,9 @@ import { generateComponent } from './generators/component' import { generateSlice } from './generators/slice' import { generateType } from './generators/type' import { generatePage } from './generators/page' +import { generateLayout } from './generators/layout' +import { generateLoading } from './generators/loading' +import { generateError } from './generators/error' import { generateApi } from './generators/api' import { generateCrud } from './generators/crud' import { generateScss } from './generators/scss' @@ -17,7 +20,7 @@ import { SuperagentTypes, injectSupergent } from './generators/superagent' export const Printer = new Command('🖨️ Printer') Printer - .version('2.0.2') + .version('2.1.0') .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) @@ -76,6 +79,33 @@ Printer await generatePage(path) }) +Printer + .command('layout ') + .description('Generate a new layout component') + .action(async path => { + registerConfig() + Log('👷 Generating new layout component'.green) + await generateLayout(path) + }) + +Printer + .command('loading ') + .description('Generate a new loading component') + .action(async path => { + registerConfig() + Log('👷 Generating new loading component'.green) + await generateLoading(path) + }) + +Printer + .command('error ') + .description('Generate a new error component') + .action(async path => { + registerConfig() + Log('👷 Generating new error component'.green) + await generateError(path) + }) + Printer .command('api ') .description('Generate a new Printer API route') diff --git a/src/templates/error.template b/src/templates/error.template new file mode 100644 index 0000000..4bfc3b3 --- /dev/null +++ b/src/templates/error.template @@ -0,0 +1,23 @@ +'use client' + +import { useEffect } from 'react' + +export interface ErrorI { + error: Error + reset: () => void +} + +export default function ErrorComponent({ error, reset }: ErrorI) { + useEffect(() => { + console.error(error) + }, [error]) + + return ( +
+

Something Went Wrong!

+ reset()}> + Reload Page + +
+ ) +} diff --git a/src/templates/layout.template b/src/templates/layout.template new file mode 100644 index 0000000..4ec5416 --- /dev/null +++ b/src/templates/layout.template @@ -0,0 +1,18 @@ +import { Metadata } from 'next' +import { ReactNode } from 'react' + +export const metadata: Metadata = { + +} + +export interface LayoutI { + children: ReactNode +} + +export default function LayoutComponent({ children }: LayoutI) { + return ( +
+ {children} +
+ ) +} diff --git a/src/templates/loading.template b/src/templates/loading.template new file mode 100644 index 0000000..97ae45c --- /dev/null +++ b/src/templates/loading.template @@ -0,0 +1,7 @@ +export default function LoadingComponent() { + return ( +
+

Please wait... Loading...

+
+ ) +} diff --git a/src/templates/new/app/layout.tsx.template b/src/templates/new/app/layout.tsx.template index c5b62c7..00caeb7 100644 --- a/src/templates/new/app/layout.tsx.template +++ b/src/templates/new/app/layout.tsx.template @@ -1,7 +1,16 @@ import 'scss/printer.scss' +import { Metadata } from 'next' import { ReactNode } from 'react' import { ReduxProvider } from 'redux/provider' +export const metadata: Metadata = { + title: 'Printer', + description: 'Automation Tooling for Next, Redux and Prisma', + icons: { + icon: '' + } +} + export interface LayoutI { children: ReactNode } @@ -9,9 +18,6 @@ export interface LayoutI { export default function LayoutComponent({ children }: LayoutI) { return ( - - Printer - {children}