UNPKG

@api-platform/client-generator

Version:

Generate apps built with Next, Nuxt, Quasar, React, React Native, Vue or Vuetify for any API documented using Hydra or OpenAPI

95 lines (74 loc) 5.08 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _get from "@babel/runtime/helpers/get"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import chalk from "chalk"; import BaseVueGenerator from "./VueBaseGenerator.js"; var NuxtGenerator = /*#__PURE__*/function (_BaseVueGenerator) { _inherits(NuxtGenerator, _BaseVueGenerator); var _super = _createSuper(NuxtGenerator); function NuxtGenerator(params) { var _this; _classCallCheck(this, NuxtGenerator); _this = _super.call(this, params); _this.registerTemplates("nuxt/", [// components "components/ActionCell.vue", "components/Alert.vue", "components/ConfirmDelete.vue", "components/DataFilter.vue", "components/InputDate.vue", "components/Loading.vue", "components/Toolbar.vue", "components/foo/Filter.vue", "components/foo/Form.vue", // mixins "mixins/create.js", "mixins/list.js", "mixins/notification.js", "mixins/show.js", "mixins/update.js", // pages "pages/foos/create.vue", "pages/foos/index.vue", "pages/foos/_id/edit.vue", "pages/foos/_id/index.vue", // store "store/crud.js", "store/notifications.js", "store/foo.js"]); return _this; } _createClass(NuxtGenerator, [{ key: "help", value: function help(resource) { console.log(chalk.green('Code for the "%s" resource type has been generated!'), resource.title); } }, { key: "generateFiles", value: function generateFiles(api, resource, dir, params) { var _this2 = this; var context = _get(_getPrototypeOf(NuxtGenerator.prototype), "getContextForResource", this).call(this, resource, params); var lc = context.lc; ["".concat(dir, "/config"), "".concat(dir, "/error"), "".concat(dir, "/mixins"), "".concat(dir, "/services"), "".concat(dir, "/store"), "".concat(dir, "/utils"), "".concat(dir, "/validators")].forEach(function (dir) { return _this2.createDir(dir, false); }); // error this.createFile("error/SubmissionError.js", "".concat(dir, "/error/SubmissionError.js"), {}, false); // mixins ["mixins/create.js", "mixins/list.js", "mixins/notification.js", "mixins/show.js", "mixins/update.js"].forEach(function (file) { return _this2.createFile(file, "".concat(dir, "/").concat(file), context, false); }); // stores this.createFile("store/modules/notifications.js", "".concat(dir, "/store/notifications.js"), { hydraPrefix: this.hydraPrefix }, false); this.createFile("store/crud.js", "".concat(dir, "/store/crud.js"), { hydraPrefix: this.hydraPrefix }, false); // validators this.createFile("validators/date.js", "".concat(dir, "/validators/date.js"), { hydraPrefix: this.hydraPrefix }, false); // utils ["dates.js", "fetch.js", "hydra.js"].forEach(function (file) { return _this2.createFile("utils/".concat(file), "".concat(dir, "/utils/").concat(file), {}, false); }); this.createEntrypoint(api.entrypoint, "".concat(dir, "/config/entrypoint.js")); ["".concat(dir, "/components/").concat(lc), "".concat(dir, "/pages/").concat(lc, "s"), "".concat(dir, "/pages/").concat(lc, "s/_id")].forEach(function (dir) { _this2.createDir(dir); }); this.createFile("services/api.js", "".concat(dir, "/services/api.js"), {}, false); [// components "components/%s/Filter.vue", "components/%s/Form.vue", // pages "pages/%ss/create.vue", "pages/%ss/index.vue", "pages/%ss/_id/edit.vue", "pages/%ss/_id/index.vue", // service "services/%s.js", // store "store/%s.js"].forEach(function (pattern) { return _this2.createFileFromPattern(pattern, dir, lc, context); }); // components ["ActionCell.vue", "Alert.vue", "ConfirmDelete.vue", "DataFilter.vue", "InputDate.vue", "Loading.vue", "Toolbar.vue"].forEach(function (file) { return _this2.createFile("components/".concat(file), "".concat(dir, "/components/").concat(file), context, false); }); } }]); return NuxtGenerator; }(BaseVueGenerator); export { NuxtGenerator as default };