From 54834909b933fb7af0c741b5f1adc3569beeaf57 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Wed, 14 Jul 2021 21:03:34 +0300 Subject: [PATCH] major refactor --- .editorconfig | 5 + .gitignore | 2 +- .prettierrc | 6 +- dist/cmd.js | 38 +++- dist/cmd.js.map | 2 +- dist/index.d.ts | 33 +-- dist/index.js | 29 ++- dist/index.js.map | 2 +- dist/scaffold.d.ts | 32 +-- dist/test.d.ts | 1 - dist/test.js | 2 - dist/test.js.map | 1 - examples/test-input/Component/Scaffold.tsx | 19 -- examples/test-input/Component/{{Name}}.tsx | 12 +- package.json | 19 +- src/cmd.ts | 22 ++ .../test-output/.gitkeep => src/filters.ts | 0 src/index.ts | 3 + src/scaffold.ts | 165 ++++++++++++++ tsconfig.json | 13 +- webpack.config.js | 46 ---- yarn.lock | 212 +++++++++++++++++- 22 files changed, 514 insertions(+), 150 deletions(-) create mode 100644 .editorconfig delete mode 100755 dist/test.d.ts delete mode 100755 dist/test.js delete mode 100755 dist/test.js.map delete mode 100644 examples/test-input/Component/Scaffold.tsx create mode 100644 src/cmd.ts rename examples/test-output/.gitkeep => src/filters.ts (100%) create mode 100644 src/index.ts create mode 100644 src/scaffold.ts delete mode 100644 webpack.config.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..973f82f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +[*] +tab_width = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.gitignore b/.gitignore index ac68c14..c44c668 100644 --- a/.gitignore +++ b/.gitignore @@ -58,4 +58,4 @@ typings/ .env examples/test-output/**/* -!examples/test-output/.gitkeep +dist/ diff --git a/.prettierrc b/.prettierrc index dceda2d..6c1772b 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,3 +1,5 @@ { - "semi": false -} \ No newline at end of file + "semi": false, + "printWidth": 120, + "tabWidth": 2 +} diff --git a/dist/cmd.js b/dist/cmd.js index e8f1012..fe30b87 100755 --- a/dist/cmd.js +++ b/dist/cmd.js @@ -1,3 +1,37 @@ -#!/usr/bin/env node -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.library=t():e.library=t()}(global,(function(){return(()=>{"use strict";var e={784:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=o(493),i=o(127),n=o(67),a=o(622);function s(e){return e.startsWith("/")?e:[process.cwd(),e].join(a.sep)}function l(e){return!e||!e.trim().length||["true","1","on"].includes(e.trim())}var u=[{name:"name",alias:"n",type:String,description:"Component output name",defaultOption:!0},{name:"templates",alias:"t",type:s,typeLabel:"{underline File}[]",description:"A glob pattern of template files to load.\nA template file may be of any type and extension, and supports Handlebars as a parsing engine for the file names and contents, so you may customize both with variables from your configuration.",multiple:!0},{name:"output",alias:"o",type:s,typeLabel:"{underline File}",description:"The output directory to put the new files in. They will attempt to maintain their regular structure as they are found, if possible."},{name:"locals",alias:"l",description:"A JSON string for the template to use in parsing.",typeLabel:"{underline JSON string}",type:function(e){return JSON.parse(e)}},{name:"overwrite",alias:"w",description:"Whether to overwrite files when they are found to already exist. {bold Default=true}",type:l,typeLabel:"{underline Boolean}",defaultValue:!0},{name:"quiet",alias:"q",description:"When set to {bold true}, logs will not output (including warnings and errors). {bold Default=false}",type:l,typeLabel:"{underline Boolean}",defaultValue:!1},{name:"create-sub-folder",alias:"S",typeLabel:"{underline Boolean}",description:"Whether to create a subdirectory with \\{\\{Name\\}\\} in the {underline output} directory. {bold Default=true}",type:l,defaultValue:!0},{name:"help",alias:"h",type:Boolean,description:"Display this help message"}],p=i(u,{camelCase:!0}),c=[{header:"Scaffold Generator",content:"Generate scaffolds for your project based on file templates.\nUsage: {bold simple-scaffold} {underline scaffold-name} {underline [options]}"},{header:"Options",optionList:u}];null===p.createSubFolder&&(p.createSubFolder=!0),null===p.quiet&&(p.quiet=!0),!p.help&&p.name||(console.log(n(c)),process.exit(0)),p.quiet||console.info("Config:",p),new r.default({name:p.name,templates:p.templates,output:p.output,locals:p.locals,createSubfolder:p.createSubFolder,overwrite:p.overwrite,quiet:p.quiet}).run()},493:function(e,t,o){var r=this&&this.__assign||function(){return(r=Object.assign||function(e){for(var t,o=1,r=arguments.length;o=0&&(u=i.slice(0,l-1));for(var p=0,c=n;p=0&&(n=e!==t?e.slice(i+t.length+1):a.basename(e)),o=r+n}return this.parseLocals(o)},e.prototype.writeFile=function(e,t){var o=a.dirname(e);this.writeDirectory(o,e),n.writeFile(e,t,{encoding:"utf-8"},(function(e){if(e)throw e}))},e.prototype.shouldWriteFile=function(e){var t,o,r="boolean"==typeof this.config.overwrite?this.config.overwrite:null===(o=(t=this.config).overwrite)||void 0===o?void 0:o.call(t,e);return!n.existsSync(e)||!1!==r},e.prototype.run=function(){this.log("Generating scaffold: "+this.config.name+"...");var e,t=this.fileList(this.config.templates),o=0;this.log("Template files:",t);for(var r=0,i=t;r{e.exports=require("command-line-args")},67:e=>{e.exports=require("command-line-usage")},747:e=>{e.exports=require("fs")},878:e=>{e.exports=require("glob")},778:e=>{e.exports=require("handlebars")},622:e=>{e.exports=require("path")}},t={};return function o(r){if(t[r])return t[r].exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,o),i.exports}(784)})()})); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./scaffold"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + var scaffold_1 = __importDefault(require("./scaffold")); + scaffold_1.default({ + name: "sample_app", + outputPath: "examples/test-output", + templates: ["examples/test-input/Component"], + overwrite: true, + data: { + property: "myProp", + value: "10", + }, + }); + scaffold_1.default({ + name: "sample_app_with_subdir", + outputPath: "examples/test-output", + templates: ["examples/test-input/Component"], + createSubfolder: true, + data: { + property: "myProp", + value: "10", + }, + }); +}); //# sourceMappingURL=cmd.js.map \ No newline at end of file diff --git a/dist/cmd.js.map b/dist/cmd.js.map index 05abaed..7813d18 100755 --- a/dist/cmd.js.map +++ b/dist/cmd.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack/universalModuleDefinition","/Users/chen/Dev/simple-scaffold/cmd.ts","/Users/chen/Dev/simple-scaffold/scaffold.ts","external \"command-line-args\"","external \"command-line-usage\"","external \"fs\"","external \"glob\"","external \"handlebars\"","external \"path\"","webpack/bootstrap","webpack/startup"],"names":["root","factory","exports","module","define","amd","global","filePathParser","content","startsWith","process","cwd","join","path","sep","booleanParser","text","trim","length","includes","defs","name","alias","type","String","description","defaultOption","typeLabel","multiple","JSON","parse","defaultValue","Boolean","args","cliArgs","camelCase","help","header","optionList","createSubFolder","quiet","console","log","cliUsage","exit","info","templates","output","locals","createSubfolder","overwrite","run","config","DefaultConfig","this","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","handlebars","compile","noEscape","template","e","warn","fileList","input","checkPath","files","glob","sync","dot","map","g","idx","indexOf","cleanCheckPath","file","push","base","getFileContents","filePath","fs","readFileSync","toString","getOutputPath","basePath","out","basename","outputDir","relativeFilePath","writeFile","fileContents","baseDir","dirname","writeDirectory","encoding","err","shouldWriteFile","existsSync","fileConf","count","outputPath","contents","outputContents","lstatSync","isDirectory","replace","error","Error","parent","mkdirSync","_log","method","fn","SimpleScaffold","require","__webpack_module_cache__","__webpack_require__","moduleId","__webpack_modules__","call"],"mappings":";CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAiB,QAAID,IAErBD,EAAc,QAAIC,IARpB,CASGK,QAAQ,WACX,M,yFCVA,aAGA,SACA,QACA,SAWA,SAASC,EAAeC,GACtB,OAAIA,EAAQC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AAWrB,KAEvB,YAAA6E,MAAA,W,IAAM,sDACJxD,KAAK4D,KAAI,MAAT5D,KAAI,GAAM,SAAYrB,KAE1B,EA7LA,GA+LA,UAAeoF,G,QCrMflH,EAAOD,QAAUoH,QAAQ,sB,OCAzBnH,EAAOD,QAAUoH,QAAQ,uB,QCAzBnH,EAAOD,QAAUoH,QAAQ,O,QCAzBnH,EAAOD,QAAUoH,QAAQ,S,QCAzBnH,EAAOD,QAAUoH,QAAQ,e,QCAzBnH,EAAOD,QAAUoH,QAAQ,UCCrBC,EAA2B,GCE/B,ODCA,SAASC,EAAoBC,GAE5B,GAAGF,EAAyBE,GAC3B,OAAOF,EAAyBE,GAAUvH,QAG3C,IAAIC,EAASoH,EAAyBE,GAAY,CAGjDvH,QAAS,IAOV,OAHAwH,EAAoBD,GAAUE,KAAKxH,EAAOD,QAASC,EAAQA,EAAOD,QAASsH,GAGpErH,EAAOD,QCjBRsH,CAAoB,M","file":"cmd.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"library\"] = factory();\n\telse\n\t\troot[\"library\"] = factory();\n})(global, function() {\nreturn ","import SimpleScaffold from \"./scaffold\"\nimport * as fs from \"fs\"\nimport { IScaffold } from \"./index\"\nimport * as cliArgs from \"command-line-args\"\nimport * as cliUsage from \"command-line-usage\"\nimport * as path from \"path\"\n\ntype Def = cliArgs.OptionDefinition & {\n description?: string\n typeLabel?: string\n}\n\nfunction localsParser(content: string) {\n return JSON.parse(content)\n}\n\nfunction filePathParser(content: string) {\n if (content.startsWith(\"/\")) {\n return content\n }\n return [process.cwd(), content].join(path.sep)\n}\n\nfunction booleanParser(text: string) {\n return text && text.trim().length\n ? [\"true\", \"1\", \"on\"].includes(text.trim())\n : true\n}\n\nconst defs: Def[] = [\n {\n name: \"name\",\n alias: \"n\",\n type: String,\n description: \"Component output name\",\n defaultOption: true,\n },\n {\n name: \"templates\",\n alias: \"t\",\n type: filePathParser,\n typeLabel: \"{underline File}[]\",\n description: `A glob pattern of template files to load.\\nA template file may be of any type and extension, and supports Handlebars as a parsing engine for the file names and contents, so you may customize both with variables from your configuration.`,\n multiple: true,\n },\n {\n name: \"output\",\n alias: \"o\",\n type: filePathParser,\n typeLabel: \"{underline File}\",\n description: `The output directory to put the new files in. They will attempt to maintain their regular structure as they are found, if possible.`,\n },\n {\n name: \"locals\",\n alias: \"l\",\n description: `A JSON string for the template to use in parsing.`,\n typeLabel: \"{underline JSON string}\",\n type: localsParser,\n },\n {\n name: \"overwrite\",\n alias: \"w\",\n description: `Whether to overwrite files when they are found to already exist. {bold Default=true}`,\n type: booleanParser,\n typeLabel: \"{underline Boolean}\",\n defaultValue: true,\n },\n {\n name: \"quiet\",\n alias: \"q\",\n description:\n \"When set to {bold true}, logs will not output (including warnings and errors). {bold Default=false}\",\n type: booleanParser,\n typeLabel: \"{underline Boolean}\",\n defaultValue: false,\n },\n {\n name: \"create-sub-folder\",\n alias: \"S\",\n typeLabel: \"{underline Boolean}\",\n description:\n \"Whether to create a subdirectory with \\\\{\\\\{Name\\\\}\\\\} in the {underline output} directory. {bold Default=true}\",\n type: booleanParser,\n defaultValue: true,\n },\n {\n name: \"help\",\n alias: \"h\",\n type: Boolean,\n description: \"Display this help message\",\n },\n]\n\nconst args = cliArgs(defs, { camelCase: true }) as Omit<\n IScaffold.Config,\n \"createSubFolder\"\n> & {\n help: boolean\n createSubFolder: boolean\n}\n\nconst help = [\n {\n header: \"Scaffold Generator\",\n content: `Generate scaffolds for your project based on file templates.\\nUsage: {bold simple-scaffold} {underline scaffold-name} {underline [options]}`,\n },\n { header: \"Options\", optionList: defs },\n]\n\nif (args.createSubFolder === null) {\n args.createSubFolder = true\n}\n\nif (args.quiet === null) {\n args.quiet = true\n}\n\nif (args.help || !args.name) {\n console.log(cliUsage(help))\n process.exit(0)\n}\n\nif (!args.quiet) {\n console.info(\"Config:\", args)\n}\n\nnew SimpleScaffold({\n name: args.name,\n templates: args.templates,\n output: args.output,\n locals: args.locals,\n createSubfolder: args.createSubFolder,\n overwrite: args.overwrite,\n quiet: args.quiet,\n}).run()\n","import * as fs from \"fs\"\nimport * as path from \"path\"\nimport { IScaffold } from \"./index.d\"\nimport * as glob from \"glob\"\nimport * as handlebars from \"handlebars\"\n\nclass SimpleScaffold {\n public config: IScaffold.Config\n public locals: IScaffold.Config[\"locals\"] = {} as any\n\n constructor(config: IScaffold.Config) {\n const DefaultConfig: IScaffold.Config = {\n name: \"scaffold\",\n templates: [],\n output: process.cwd(),\n createSubfolder: true,\n overwrite: true,\n quiet: false,\n }\n\n this.config = { ...DefaultConfig, ...config }\n\n const DefaultLocals = {\n // TODO improve\n Name: this.config.name![0].toUpperCase() + this.config.name!.slice(1),\n name: this.config.name![0].toLowerCase() + this.config.name!.slice(1),\n }\n\n this.locals = { ...DefaultLocals, ...config.locals }\n }\n\n private parseLocals(text: string): string {\n try {\n const template = handlebars.compile(text, {\n noEscape: true,\n })\n return template(this.locals)\n } catch (e) {\n this.warn(\"Problem using Handlebars, returning unmodified content\")\n return text\n }\n }\n\n private fileList(input: string[]): IScaffold.FileRepr[] {\n const output: IScaffold.FileRepr[] = []\n for (const checkPath of input) {\n const files = glob\n .sync(checkPath, { dot: true })\n .map((g) => (g[0] == \"/\" ? g : path.join(process.cwd(), g)))\n const idx = checkPath.indexOf(\"*\")\n let cleanCheckPath = checkPath\n if (idx >= 0) {\n cleanCheckPath = checkPath.slice(0, idx - 1)\n }\n for (const file of files) {\n output.push({ base: cleanCheckPath, file })\n }\n }\n return output\n }\n\n private getFileContents(filePath: string): string {\n this.log(fs.readFileSync(filePath))\n return fs.readFileSync(filePath).toString()\n }\n\n private getOutputPath(file: string, basePath: string): string {\n let out: string\n\n if (typeof this.config.output === \"function\") {\n out = this.config.output(file, basePath, path.basename(file))\n } else {\n const outputDir =\n this.config.output +\n (this.config.createSubfolder ? `/${this.config.name}/` : \"/\")\n const idx = file.indexOf(basePath)\n let relativeFilePath = file\n if (idx >= 0) {\n if (file !== basePath) {\n relativeFilePath = file.slice(idx + basePath.length + 1)\n } else {\n relativeFilePath = path.basename(file)\n }\n }\n out = outputDir + relativeFilePath\n }\n\n return this.parseLocals(out)\n }\n\n private writeFile(filePath: string, fileContents: string): void {\n const baseDir = path.dirname(filePath)\n this.writeDirectory(baseDir, filePath)\n fs.writeFile(filePath, fileContents, { encoding: \"utf-8\" }, (err) => {\n if (err) {\n throw err\n }\n })\n }\n\n private shouldWriteFile(filePath: string) {\n const overwrite =\n typeof this.config.overwrite === \"boolean\"\n ? this.config.overwrite\n : this.config.overwrite?.(filePath)\n const exists = fs.existsSync(filePath)\n\n return !exists || overwrite !== false\n }\n\n public run(): void {\n this.log(`Generating scaffold: ${this.config.name}...`)\n const templates = this.fileList(this.config.templates)\n\n let fileConf,\n count = 0\n\n this.log(\"Template files:\", templates)\n for (fileConf of templates) {\n let outputPath, contents, outputContents, file, base\n try {\n count++\n file = fileConf.file\n base = fileConf.base\n outputPath = this.getOutputPath(file, base)\n if (fs.lstatSync(file).isDirectory()) {\n this.writeDirectory(outputPath, file)\n continue\n }\n contents = this.getFileContents(file)\n outputContents = this.parseLocals(contents)\n if (this.shouldWriteFile(outputPath)) {\n this.info(\"Writing:\", {\n file,\n base,\n outputPath,\n outputContents: outputContents.replace(\"\\n\", \"\\\\n\"),\n })\n this.writeFile(outputPath, outputContents)\n } else {\n this.log(`Skipping file ${outputPath}`)\n }\n } catch (e) {\n this.error(\"Error while processing file:\", {\n file,\n base,\n contents,\n outputPath,\n outputContents,\n })\n throw e\n }\n }\n\n if (!count) {\n throw new Error(\"No files to scaffold!\")\n }\n\n this.log(\"Done\")\n }\n\n private writeDirectory(outputPath: string, file: any): void {\n const parent = path.dirname(outputPath)\n if (!fs.existsSync(parent)) {\n this.writeDirectory(parent, outputPath)\n }\n if (!fs.existsSync(outputPath)) {\n this.info(\"Creating directory:\", {\n file,\n outputPath,\n })\n fs.mkdirSync(outputPath)\n }\n }\n\n _log(method: keyof typeof console, ...args: any[]): void {\n if (this.config.quiet) {\n return\n }\n const fn = console[method] as (...a: any[]) => void\n fn(...args)\n }\n\n log(...args: any[]): void {\n this._log(\"log\", ...args)\n }\n info(...args: any[]): void {\n this._log(\"info\", ...args)\n }\n warn(...args: any[]): void {\n this._log(\"warn\", ...args)\n }\n error(...args: any[]): void {\n this._log(\"error\", ...args)\n }\n}\n\nexport default SimpleScaffold\n","module.exports = require(\"command-line-args\");;","module.exports = require(\"command-line-usage\");;","module.exports = require(\"fs\");;","module.exports = require(\"glob\");;","module.exports = require(\"handlebars\");;","module.exports = require(\"path\");;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tif(__webpack_module_cache__[moduleId]) {\n\t\treturn __webpack_module_cache__[moduleId].exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// module exports must be returned from runtime so entry inlining is disabled\n// startup\n// Load entry module and return exports\nreturn __webpack_require__(784);\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"cmd.js","sourceRoot":"","sources":["../src/cmd.ts"],"names":[],"mappings":";;;;;;;;;;;;;;IAAA,wDAAiC;IAEjC,kBAAQ,CAAC;QACP,IAAI,EAAE,YAAY;QAClB,UAAU,EAAE,sBAAsB;QAClC,SAAS,EAAE,CAAC,+BAA+B,CAAC;QAC5C,SAAS,EAAE,IAAI;QACf,IAAI,EAAE;YACJ,QAAQ,EAAE,QAAQ;YAClB,KAAK,EAAE,IAAI;SACZ;KACF,CAAC,CAAA;IACF,kBAAQ,CAAC;QACP,IAAI,EAAE,wBAAwB;QAC9B,UAAU,EAAE,sBAAsB;QAClC,SAAS,EAAE,CAAC,+BAA+B,CAAC;QAC5C,eAAe,EAAE,IAAI;QACrB,IAAI,EAAE;YACJ,QAAQ,EAAE,QAAQ;YAClB,KAAK,EAAE,IAAI;SACZ;KACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts index 6b9a750..3eb6371 100755 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,30 +1,3 @@ -declare namespace IScaffold { - class SimpleScaffold { - constructor(config: Config) - run(): void - } - - export interface Config { - name?: string - templates: string[] - output: - | string - | ((fullPath: string, basedir: string, basename: string) => string) - locals?: Locals - createSubfolder?: boolean - overwrite?: boolean | ((path: string) => boolean) - quiet?: boolean - } - - export interface Locals { - [k: string]: string - } - - export interface FileRepr { - base: string - file: string - } -} - -export default IScaffold.SimpleScaffold -export { IScaffold } +export * from "./scaffold"; +import Scaffold from "./scaffold"; +export default Scaffold; diff --git a/dist/index.js b/dist/index.js index 49aec0e..02c6a59 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,29 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.library=e():t.library=e()}(global,(function(){return(()=>{"use strict";var t={493:function(t,e,o){var r=this&&this.__assign||function(){return(r=Object.assign||function(t){for(var e,o=1,r=arguments.length;o=0&&(f=i.slice(0,l-1));for(var c=0,p=n;c=0&&(n=t!==e?t.slice(i+e.length+1):s.basename(t)),o=r+n}return this.parseLocals(o)},t.prototype.writeFile=function(t,e){var o=s.dirname(t);this.writeDirectory(o,t),n.writeFile(t,e,{encoding:"utf-8"},(function(t){if(t)throw t}))},t.prototype.shouldWriteFile=function(t){var e,o,r="boolean"==typeof this.config.overwrite?this.config.overwrite:null===(o=(e=this.config).overwrite)||void 0===o?void 0:o.call(e,t);return!n.existsSync(t)||!1!==r},t.prototype.run=function(){this.log("Generating scaffold: "+this.config.name+"...");var t,e=this.fileList(this.config.templates),o=0;this.log("Template files:",e);for(var r=0,i=e;r{t.exports=require("fs")},878:t=>{t.exports=require("glob")},778:t=>{t.exports=require("handlebars")},622:t=>{t.exports=require("path")}},e={};return function o(r){if(e[r])return e[r].exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,o),i.exports}(493)})()})); +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./scaffold", "./scaffold"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + __exportStar(require("./scaffold"), exports); + var scaffold_1 = __importDefault(require("./scaffold")); + exports.default = scaffold_1.default; +}); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map index e7b56da..2a85872 100755 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack/universalModuleDefinition","/Users/chen/Dev/simple-scaffold/scaffold.ts","external \"fs\"","external \"glob\"","external \"handlebars\"","external \"path\"","webpack/bootstrap","webpack/startup"],"names":["root","factory","exports","module","define","amd","global","config","locals","DefaultConfig","name","templates","output","process","cwd","createSubfolder","overwrite","quiet","this","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","text","handlebars","compile","noEscape","template","e","warn","fileList","input","checkPath","files","glob","sync","dot","map","g","path","join","idx","indexOf","cleanCheckPath","file","push","base","getFileContents","filePath","log","fs","readFileSync","toString","getOutputPath","basePath","out","basename","outputDir","relativeFilePath","length","writeFile","fileContents","baseDir","dirname","writeDirectory","encoding","err","shouldWriteFile","existsSync","run","fileConf","count","outputPath","contents","outputContents","lstatSync","isDirectory","info","replace","error","Error","parent","mkdirSync","_log","method","fn","console","args","SimpleScaffold","require","__webpack_module_cache__","__webpack_require__","moduleId","__webpack_modules__","call"],"mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAiB,QAAID,IAErBD,EAAc,QAAIC,IARpB,CASGK,QAAQ,WACX,M,0hBCVA,aACA,SAEA,SACA,SAEA,aAIE,WAAYC,GAFL,KAAAC,OAAqC,GAG1C,IAAMC,EAAkC,CACtCC,KAAM,WACNC,UAAW,GACXC,OAAQC,QAAQC,MAChBC,iBAAiB,EACjBC,WAAW,EACXC,OAAO,GAGTC,KAAKX,OAAS,EAAH,KAAQE,GAAkBF,GAErC,IAAMY,EAAgB,CAEpBC,KAAMF,KAAKX,OAAOG,KAAM,GAAGW,cAAgBH,KAAKX,OAAOG,KAAMY,MAAM,GACnEZ,KAAMQ,KAAKX,OAAOG,KAAM,GAAGa,cAAgBL,KAAKX,OAAOG,KAAMY,MAAM,IAGrEJ,KAAKV,OAAS,EAAH,KAAQW,GAAkBZ,EAAOC,QAuKhD,OApKU,YAAAgB,YAAR,SAAoBC,GAClB,IAIE,OAHiBC,EAAWC,QAAQF,EAAM,CACxCG,UAAU,GAELC,CAASX,KAAKV,QACrB,MAAOsB,GAEP,OADAZ,KAAKa,KAAK,0DACHN,IAIH,YAAAO,SAAR,SAAiBC,GAEf,IADA,IAAMrB,EAA+B,GACb,MAAAqB,EAA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,KAAK,sBAAuB,CAC/BjC,KAAI,EACJ4B,WAAU,IAEZtB,EAAGgC,UAAUV,KAIjB,YAAAW,KAAA,SAAKC,G,IAA8B,wDACjC,IAAIpE,KAAKX,OAAOU,MAAhB,CAGA,IAAMsE,EAAKC,QAAQF,GACnBC,EAAE,aAAIE,KAGR,YAAAtC,IAAA,W,IAAI,sDACFjC,KAAKmE,KAAI,MAATnE,KAAI,GAAM,OAAUuE,KAEtB,YAAAV,KAAA,W,IAAK,sDACH7D,KAAKmE,KAAI,MAATnE,KAAI,GAAM,QAAWuE,KAEvB,YAAA1D,KAAA,W,IAAK,sDACHb,KAAKmE,KAAI,MAATnE,KAAI,GAAM,QAAWuE,KAEvB,YAAAR,MAAA,W,IAAM,sDACJ/D,KAAKmE,KAAI,MAATnE,KAAI,GAAM,SAAYuE,KAE1B,EA7LA,GA+LA,UAAeC,G,QCrMfvF,EAAOD,QAAUyF,QAAQ,O,QCAzBxF,EAAOD,QAAUyF,QAAQ,S,QCAzBxF,EAAOD,QAAUyF,QAAQ,e,QCAzBxF,EAAOD,QAAUyF,QAAQ,UCCrBC,EAA2B,GCE/B,ODCA,SAASC,EAAoBC,GAE5B,GAAGF,EAAyBE,GAC3B,OAAOF,EAAyBE,GAAU5F,QAG3C,IAAIC,EAASyF,EAAyBE,GAAY,CAGjD5F,QAAS,IAOV,OAHA6F,EAAoBD,GAAUE,KAAK7F,EAAOD,QAASC,EAAQA,EAAOD,QAAS2F,GAGpE1F,EAAOD,QCjBR2F,CAAoB,M","file":"index.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"library\"] = factory();\n\telse\n\t\troot[\"library\"] = factory();\n})(global, function() {\nreturn ","import * as fs from \"fs\"\nimport * as path from \"path\"\nimport { IScaffold } from \"./index.d\"\nimport * as glob from \"glob\"\nimport * as handlebars from \"handlebars\"\n\nclass SimpleScaffold {\n public config: IScaffold.Config\n public locals: IScaffold.Config[\"locals\"] = {} as any\n\n constructor(config: IScaffold.Config) {\n const DefaultConfig: IScaffold.Config = {\n name: \"scaffold\",\n templates: [],\n output: process.cwd(),\n createSubfolder: true,\n overwrite: true,\n quiet: false,\n }\n\n this.config = { ...DefaultConfig, ...config }\n\n const DefaultLocals = {\n // TODO improve\n Name: this.config.name![0].toUpperCase() + this.config.name!.slice(1),\n name: this.config.name![0].toLowerCase() + this.config.name!.slice(1),\n }\n\n this.locals = { ...DefaultLocals, ...config.locals }\n }\n\n private parseLocals(text: string): string {\n try {\n const template = handlebars.compile(text, {\n noEscape: true,\n })\n return template(this.locals)\n } catch (e) {\n this.warn(\"Problem using Handlebars, returning unmodified content\")\n return text\n }\n }\n\n private fileList(input: string[]): IScaffold.FileRepr[] {\n const output: IScaffold.FileRepr[] = []\n for (const checkPath of input) {\n const files = glob\n .sync(checkPath, { dot: true })\n .map((g) => (g[0] == \"/\" ? g : path.join(process.cwd(), g)))\n const idx = checkPath.indexOf(\"*\")\n let cleanCheckPath = checkPath\n if (idx >= 0) {\n cleanCheckPath = checkPath.slice(0, idx - 1)\n }\n for (const file of files) {\n output.push({ base: cleanCheckPath, file })\n }\n }\n return output\n }\n\n private getFileContents(filePath: string): string {\n this.log(fs.readFileSync(filePath))\n return fs.readFileSync(filePath).toString()\n }\n\n private getOutputPath(file: string, basePath: string): string {\n let out: string\n\n if (typeof this.config.output === \"function\") {\n out = this.config.output(file, basePath, path.basename(file))\n } else {\n const outputDir =\n this.config.output +\n (this.config.createSubfolder ? `/${this.config.name}/` : \"/\")\n const idx = file.indexOf(basePath)\n let relativeFilePath = file\n if (idx >= 0) {\n if (file !== basePath) {\n relativeFilePath = file.slice(idx + basePath.length + 1)\n } else {\n relativeFilePath = path.basename(file)\n }\n }\n out = outputDir + relativeFilePath\n }\n\n return this.parseLocals(out)\n }\n\n private writeFile(filePath: string, fileContents: string): void {\n const baseDir = path.dirname(filePath)\n this.writeDirectory(baseDir, filePath)\n fs.writeFile(filePath, fileContents, { encoding: \"utf-8\" }, (err) => {\n if (err) {\n throw err\n }\n })\n }\n\n private shouldWriteFile(filePath: string) {\n const overwrite =\n typeof this.config.overwrite === \"boolean\"\n ? this.config.overwrite\n : this.config.overwrite?.(filePath)\n const exists = fs.existsSync(filePath)\n\n return !exists || overwrite !== false\n }\n\n public run(): void {\n this.log(`Generating scaffold: ${this.config.name}...`)\n const templates = this.fileList(this.config.templates)\n\n let fileConf,\n count = 0\n\n this.log(\"Template files:\", templates)\n for (fileConf of templates) {\n let outputPath, contents, outputContents, file, base\n try {\n count++\n file = fileConf.file\n base = fileConf.base\n outputPath = this.getOutputPath(file, base)\n if (fs.lstatSync(file).isDirectory()) {\n this.writeDirectory(outputPath, file)\n continue\n }\n contents = this.getFileContents(file)\n outputContents = this.parseLocals(contents)\n if (this.shouldWriteFile(outputPath)) {\n this.info(\"Writing:\", {\n file,\n base,\n outputPath,\n outputContents: outputContents.replace(\"\\n\", \"\\\\n\"),\n })\n this.writeFile(outputPath, outputContents)\n } else {\n this.log(`Skipping file ${outputPath}`)\n }\n } catch (e) {\n this.error(\"Error while processing file:\", {\n file,\n base,\n contents,\n outputPath,\n outputContents,\n })\n throw e\n }\n }\n\n if (!count) {\n throw new Error(\"No files to scaffold!\")\n }\n\n this.log(\"Done\")\n }\n\n private writeDirectory(outputPath: string, file: any): void {\n const parent = path.dirname(outputPath)\n if (!fs.existsSync(parent)) {\n this.writeDirectory(parent, outputPath)\n }\n if (!fs.existsSync(outputPath)) {\n this.info(\"Creating directory:\", {\n file,\n outputPath,\n })\n fs.mkdirSync(outputPath)\n }\n }\n\n _log(method: keyof typeof console, ...args: any[]): void {\n if (this.config.quiet) {\n return\n }\n const fn = console[method] as (...a: any[]) => void\n fn(...args)\n }\n\n log(...args: any[]): void {\n this._log(\"log\", ...args)\n }\n info(...args: any[]): void {\n this._log(\"info\", ...args)\n }\n warn(...args: any[]): void {\n this._log(\"warn\", ...args)\n }\n error(...args: any[]): void {\n this._log(\"error\", ...args)\n }\n}\n\nexport default SimpleScaffold\n","module.exports = require(\"fs\");;","module.exports = require(\"glob\");;","module.exports = require(\"handlebars\");;","module.exports = require(\"path\");;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tif(__webpack_module_cache__[moduleId]) {\n\t\treturn __webpack_module_cache__[moduleId].exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// module exports must be returned from runtime so entry inlining is disabled\n// startup\n// Load entry module and return exports\nreturn __webpack_require__(493);\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;IAAA,6CAA0B;IAC1B,wDAAiC;IACjC,kBAAe,kBAAQ,CAAA"} \ No newline at end of file diff --git a/dist/scaffold.d.ts b/dist/scaffold.d.ts index b8712fd..7f93989 100755 --- a/dist/scaffold.d.ts +++ b/dist/scaffold.d.ts @@ -1,21 +1,13 @@ -/// -import { IScaffold } from "./index.d"; -declare class SimpleScaffold { - config: IScaffold.Config; - locals: IScaffold.Config["locals"]; - constructor(config: IScaffold.Config); - private parseLocals; - private fileList; - private getFileContents; - private getOutputPath; - private writeFile; - private shouldWriteFile; - run(): void; - private writeDirectory; - _log(method: keyof typeof console, ...args: any[]): void; - log(...args: any[]): void; - info(...args: any[]): void; - warn(...args: any[]): void; - error(...args: any[]): void; +declare type FileResponseFn = (fullPath: string, basedir: string, basename: string) => T; +export declare type FileResponse = T | FileResponseFn; +export interface ScaffoldConfig { + name: string; + templates: string[]; + outputPath: FileResponse; + createSubfolder?: boolean; + data?: Record; + overwrite?: FileResponse; + silent?: boolean; } -export default SimpleScaffold; +export declare function Scaffold(config: ScaffoldConfig): Promise; +export default Scaffold; diff --git a/dist/test.d.ts b/dist/test.d.ts deleted file mode 100755 index cb0ff5c..0000000 --- a/dist/test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/dist/test.js b/dist/test.js deleted file mode 100755 index 3e545ef..0000000 --- a/dist/test.js +++ /dev/null @@ -1,2 +0,0 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.library=e():t.library=e()}(global,(function(){return(()=>{"use strict";var t={493:function(t,e,o){var r=this&&this.__assign||function(){return(r=Object.assign||function(t){for(var e,o=1,r=arguments.length;o=0&&(p=i.slice(0,l-1));for(var u=0,c=n;u=0&&(n=t!==e?t.slice(i+e.length+1):s.basename(t)),o=r+n}return this.parseLocals(o)},t.prototype.writeFile=function(t,e){var o=s.dirname(t);this.writeDirectory(o,t),n.writeFile(t,e,{encoding:"utf-8"},(function(t){if(t)throw t}))},t.prototype.shouldWriteFile=function(t){var e,o,r="boolean"==typeof this.config.overwrite?this.config.overwrite:null===(o=(e=this.config).overwrite)||void 0===o?void 0:o.call(e,t);return!n.existsSync(t)||!1!==r},t.prototype.run=function(){this.log("Generating scaffold: "+this.config.name+"...");var t,e=this.fileList(this.config.templates),o=0;this.log("Template files:",e);for(var r=0,i=e;r{Object.defineProperty(e,"__esModule",{value:!0});var r=o(493),i=o(622).join(process.cwd(),"examples");new r.default({templates:[i+"/test-input/Component/**/*"],output:i+"/test-output/no-create-subpath",createSubfolder:!1,locals:{property:"myProp",value:'"value"'}}).run(),new r.default({templates:[i+"/test-input/Component/**/*"],output:i+"/test-output",locals:{property:"myProp",value:'"value"'}}).run(),new r.default({templates:[i+"/test-input/Component/**/*"],output:function(t,e,o){return console.log({file:t,basedir:e,basename:o}),t},locals:{property:"myProp",value:'"value"'}}).run()},747:t=>{t.exports=require("fs")},878:t=>{t.exports=require("glob")},778:t=>{t.exports=require("handlebars")},622:t=>{t.exports=require("path")}},e={};return function o(r){if(e[r])return e[r].exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,o),i.exports}(743)})()})); -//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/dist/test.js.map b/dist/test.js.map deleted file mode 100755 index 4c5d1b7..0000000 --- a/dist/test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["webpack/universalModuleDefinition","/Users/chen/Dev/simple-scaffold/scaffold.ts","/Users/chen/Dev/simple-scaffold/test.ts","external \"fs\"","external \"glob\"","external \"handlebars\"","external \"path\"","webpack/bootstrap","webpack/startup"],"names":["root","factory","exports","module","define","amd","global","config","locals","DefaultConfig","name","templates","output","process","cwd","createSubfolder","overwrite","quiet","this","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","text","handlebars","compile","noEscape","template","e","warn","fileList","input","checkPath","files","glob","sync","dot","map","g","path","join","idx","indexOf","cleanCheckPath","file","push","base","getFileContents","filePath","log","fs","readFileSync","toString","getOutputPath","basePath","out","basename","outputDir","relativeFilePath","length","writeFile","fileContents","baseDir","dirname","writeDirectory","encoding","err","shouldWriteFile","existsSync","run","fileConf","count","outputPath","contents","outputContents","lstatSync","isDirectory","info","replace","error","Error","parent","mkdirSync","_log","method","fn","console","args","SimpleScaffold","templateDir","property","value","basedir","require","__webpack_module_cache__","__webpack_require__","moduleId","__webpack_modules__","call"],"mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAiB,QAAID,IAErBD,EAAc,QAAIC,IARpB,CASGK,QAAQ,WACX,M,0hBCVA,aACA,SAEA,SACA,SAEA,aAIE,WAAYC,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AE7C,IAAI,UAAe,CACjBH,UAAW,CAACgF,EAAc,8BAC1B/E,OAAQ+E,EAAc,iCACtB5E,iBAAiB,EACjBP,OAAQ,CACNoF,SAAU,SACVC,MAAO,aAERtB,MAEH,IAAI,UAAe,CACjB5D,UAAW,CAACgF,EAAc,8BAC1B/E,OAAQ+E,EAAc,eACtBnF,OAAQ,CACNoF,SAAU,SACVC,MAAO,aAERtB,MAEH,IAAI,UAAe,CACjB5D,UAAW,CAACgF,EAAc,8BAC1B/E,OAAQ,SAACkC,EAAMgD,EAASpC,GAEtB,OADA8B,QAAQrC,IAAI,CAAEL,KAAI,EAAEgD,QAAO,EAAEpC,SAAQ,IAC9BZ,GAETtC,OAAQ,CACNoF,SAAU,SACVC,MAAO,aAERtB,O,QClCHpE,EAAOD,QAAU6F,QAAQ,O,QCAzB5F,EAAOD,QAAU6F,QAAQ,S,QCAzB5F,EAAOD,QAAU6F,QAAQ,e,QCAzB5F,EAAOD,QAAU6F,QAAQ,UCCrBC,EAA2B,GCE/B,ODCA,SAASC,EAAoBC,GAE5B,GAAGF,EAAyBE,GAC3B,OAAOF,EAAyBE,GAAUhG,QAG3C,IAAIC,EAAS6F,EAAyBE,GAAY,CAGjDhG,QAAS,IAOV,OAHAiG,EAAoBD,GAAUE,KAAKjG,EAAOD,QAASC,EAAQA,EAAOD,QAAS+F,GAGpE9F,EAAOD,QCjBR+F,CAAoB,M","file":"test.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"library\"] = factory();\n\telse\n\t\troot[\"library\"] = factory();\n})(global, function() {\nreturn ","import * as fs from \"fs\"\nimport * as path from \"path\"\nimport { IScaffold } from \"./index.d\"\nimport * as glob from \"glob\"\nimport * as handlebars from \"handlebars\"\n\nclass SimpleScaffold {\n public config: IScaffold.Config\n public locals: IScaffold.Config[\"locals\"] = {} as any\n\n constructor(config: IScaffold.Config) {\n const DefaultConfig: IScaffold.Config = {\n name: \"scaffold\",\n templates: [],\n output: process.cwd(),\n createSubfolder: true,\n overwrite: true,\n quiet: false,\n }\n\n this.config = { ...DefaultConfig, ...config }\n\n const DefaultLocals = {\n // TODO improve\n Name: this.config.name![0].toUpperCase() + this.config.name!.slice(1),\n name: this.config.name![0].toLowerCase() + this.config.name!.slice(1),\n }\n\n this.locals = { ...DefaultLocals, ...config.locals }\n }\n\n private parseLocals(text: string): string {\n try {\n const template = handlebars.compile(text, {\n noEscape: true,\n })\n return template(this.locals)\n } catch (e) {\n this.warn(\"Problem using Handlebars, returning unmodified content\")\n return text\n }\n }\n\n private fileList(input: string[]): IScaffold.FileRepr[] {\n const output: IScaffold.FileRepr[] = []\n for (const checkPath of input) {\n const files = glob\n .sync(checkPath, { dot: true })\n .map((g) => (g[0] == \"/\" ? g : path.join(process.cwd(), g)))\n const idx = checkPath.indexOf(\"*\")\n let cleanCheckPath = checkPath\n if (idx >= 0) {\n cleanCheckPath = checkPath.slice(0, idx - 1)\n }\n for (const file of files) {\n output.push({ base: cleanCheckPath, file })\n }\n }\n return output\n }\n\n private getFileContents(filePath: string): string {\n this.log(fs.readFileSync(filePath))\n return fs.readFileSync(filePath).toString()\n }\n\n private getOutputPath(file: string, basePath: string): string {\n let out: string\n\n if (typeof this.config.output === \"function\") {\n out = this.config.output(file, basePath, path.basename(file))\n } else {\n const outputDir =\n this.config.output +\n (this.config.createSubfolder ? `/${this.config.name}/` : \"/\")\n const idx = file.indexOf(basePath)\n let relativeFilePath = file\n if (idx >= 0) {\n if (file !== basePath) {\n relativeFilePath = file.slice(idx + basePath.length + 1)\n } else {\n relativeFilePath = path.basename(file)\n }\n }\n out = outputDir + relativeFilePath\n }\n\n return this.parseLocals(out)\n }\n\n private writeFile(filePath: string, fileContents: string): void {\n const baseDir = path.dirname(filePath)\n this.writeDirectory(baseDir, filePath)\n fs.writeFile(filePath, fileContents, { encoding: \"utf-8\" }, (err) => {\n if (err) {\n throw err\n }\n })\n }\n\n private shouldWriteFile(filePath: string) {\n const overwrite =\n typeof this.config.overwrite === \"boolean\"\n ? this.config.overwrite\n : this.config.overwrite?.(filePath)\n const exists = fs.existsSync(filePath)\n\n return !exists || overwrite !== false\n }\n\n public run(): void {\n this.log(`Generating scaffold: ${this.config.name}...`)\n const templates = this.fileList(this.config.templates)\n\n let fileConf,\n count = 0\n\n this.log(\"Template files:\", templates)\n for (fileConf of templates) {\n let outputPath, contents, outputContents, file, base\n try {\n count++\n file = fileConf.file\n base = fileConf.base\n outputPath = this.getOutputPath(file, base)\n if (fs.lstatSync(file).isDirectory()) {\n this.writeDirectory(outputPath, file)\n continue\n }\n contents = this.getFileContents(file)\n outputContents = this.parseLocals(contents)\n if (this.shouldWriteFile(outputPath)) {\n this.info(\"Writing:\", {\n file,\n base,\n outputPath,\n outputContents: outputContents.replace(\"\\n\", \"\\\\n\"),\n })\n this.writeFile(outputPath, outputContents)\n } else {\n this.log(`Skipping file ${outputPath}`)\n }\n } catch (e) {\n this.error(\"Error while processing file:\", {\n file,\n base,\n contents,\n outputPath,\n outputContents,\n })\n throw e\n }\n }\n\n if (!count) {\n throw new Error(\"No files to scaffold!\")\n }\n\n this.log(\"Done\")\n }\n\n private writeDirectory(outputPath: string, file: any): void {\n const parent = path.dirname(outputPath)\n if (!fs.existsSync(parent)) {\n this.writeDirectory(parent, outputPath)\n }\n if (!fs.existsSync(outputPath)) {\n this.info(\"Creating directory:\", {\n file,\n outputPath,\n })\n fs.mkdirSync(outputPath)\n }\n }\n\n _log(method: keyof typeof console, ...args: any[]): void {\n if (this.config.quiet) {\n return\n }\n const fn = console[method] as (...a: any[]) => void\n fn(...args)\n }\n\n log(...args: any[]): void {\n this._log(\"log\", ...args)\n }\n info(...args: any[]): void {\n this._log(\"info\", ...args)\n }\n warn(...args: any[]): void {\n this._log(\"warn\", ...args)\n }\n error(...args: any[]): void {\n this._log(\"error\", ...args)\n }\n}\n\nexport default SimpleScaffold\n","import SimpleScaffold from \"./scaffold\"\nimport * as path from \"path\"\n\nconst templateDir = path.join(process.cwd(), \"examples\")\n\nnew SimpleScaffold({\n templates: [templateDir + \"/test-input/Component/**/*\"],\n output: templateDir + \"/test-output/no-create-subpath\",\n createSubfolder: false,\n locals: {\n property: \"myProp\",\n value: '\"value\"',\n },\n}).run()\n\nnew SimpleScaffold({\n templates: [templateDir + \"/test-input/Component/**/*\"],\n output: templateDir + \"/test-output\",\n locals: {\n property: \"myProp\",\n value: '\"value\"',\n },\n}).run()\n\nnew SimpleScaffold({\n templates: [templateDir + \"/test-input/Component/**/*\"],\n output: (file, basedir, basename) => {\n console.log({ file, basedir, basename })\n return file\n },\n locals: {\n property: \"myProp\",\n value: '\"value\"',\n },\n}).run()\n","module.exports = require(\"fs\");;","module.exports = require(\"glob\");;","module.exports = require(\"handlebars\");;","module.exports = require(\"path\");;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tif(__webpack_module_cache__[moduleId]) {\n\t\treturn __webpack_module_cache__[moduleId].exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// module exports must be returned from runtime so entry inlining is disabled\n// startup\n// Load entry module and return exports\nreturn __webpack_require__(743);\n"],"sourceRoot":""} \ No newline at end of file diff --git a/examples/test-input/Component/Scaffold.tsx b/examples/test-input/Component/Scaffold.tsx deleted file mode 100644 index f67e3bd..0000000 --- a/examples/test-input/Component/Scaffold.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import * as React from 'react' -import * as css from './Scaffold.css' - -class Scaffold extends React.Component { - private myProp - - constructor(props: any) { - super(props) - this.myProp = "value" - } - - public render() { - return ( -
- ) - } -} - -export default Scaffold diff --git a/examples/test-input/Component/{{Name}}.tsx b/examples/test-input/Component/{{Name}}.tsx index e0e05d5..6ab755b 100644 --- a/examples/test-input/Component/{{Name}}.tsx +++ b/examples/test-input/Component/{{Name}}.tsx @@ -1,18 +1,16 @@ -import * as React from 'react' -import * as css from './{{Name}}.css' +import * as React from "react" +import * as css from "./{{Name}}.css" class {{Name}} extends React.Component { - private {{property}} + private {{ snakeCase property }} constructor(props: any) { super(props) - this.{{property}} = {{value}} + this.{{ snakeCase property }} = {{ value }} } public render() { - return ( -
- ) + return
} } diff --git a/package.json b/package.json index 12f006c..28c2ecd 100644 --- a/package.json +++ b/package.json @@ -9,25 +9,30 @@ "bin": "dist/cmd.js", "types": "index.d.ts", "scripts": { - "build": "NODE_ENV=${NODE_ENV:-production} webpack && chmod -R +x ./dist", + "clean": "rm -rf dist/", + "build": "yarn clean && tsc && chmod -R +x ./dist", "prepublishOnly": "yarn build", - "dev": "webpack --watch", - "start": "node dist/scaffold.js", - "test": "node dist/test.js", - "cmd": "dist/cmd.js", + "dev": "tsc --watch", + "start": "node --trace-warnings dist/scaffold.js", + "test": "node --trace-warnings dist/test.js", + "cmd": "node --trace-warnings dist/cmd.js", "build-test": "yarn build && yarn test", "build-cmd": "yarn build && yarn cmd" }, "dependencies": { + "args": "^5.0.1", "command-line-args": "^5.0.2", "command-line-usage": "^6.1.1", "glob": "^7.1.3", - "handlebars": "^4.1.0" + "handlebars": "^4.7.7", + "lodash": "^4.17.21", + "util.promisify": "^1.1.1" }, "devDependencies": { "@types/command-line-args": "^5.0.0", "@types/command-line-usage": "^5.0.1", "@types/glob": "^7.1.1", + "@types/lodash": "^4.14.171", "@types/node": "^14.14.22", "copy-webpack-plugin": "^7.0.0", "jest": "^26.6.3", @@ -44,4 +49,4 @@ "dist" ] } -} \ No newline at end of file +} diff --git a/src/cmd.ts b/src/cmd.ts new file mode 100644 index 0000000..f5e1f95 --- /dev/null +++ b/src/cmd.ts @@ -0,0 +1,22 @@ +import Scaffold from "./scaffold" + +Scaffold({ + name: "sample_app", + outputPath: "examples/test-output", + templates: ["examples/test-input/Component"], + overwrite: true, + data: { + property: "myProp", + value: "10", + }, +}) +Scaffold({ + name: "sample_app_with_subdir", + outputPath: "examples/test-output", + templates: ["examples/test-input/Component"], + createSubfolder: true, + data: { + property: "myProp", + value: "10", + }, +}) diff --git a/examples/test-output/.gitkeep b/src/filters.ts similarity index 100% rename from examples/test-output/.gitkeep rename to src/filters.ts diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..a6158d9 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,3 @@ +export * from "./scaffold" +import Scaffold from "./scaffold" +export default Scaffold diff --git a/src/scaffold.ts b/src/scaffold.ts new file mode 100644 index 0000000..6ffa451 --- /dev/null +++ b/src/scaffold.ts @@ -0,0 +1,165 @@ +import { access, stat, mkdir, open, readFile, writeFile } from "fs/promises" +import { glob } from "glob" +import Handlebars = require("handlebars") +import camelCase from "lodash/camelCase" +import snakeCase from "lodash/snakeCase" +import kebabCase from "lodash/kebabCase" +import startCase from "lodash/startCase" +import path = require("path") +import { F_OK } from "constants" +import { promisify } from "util" + +type FileResponseFn = (fullPath: string, basedir: string, basename: string) => T + +export type FileResponse = T | FileResponseFn + +export interface ScaffoldConfig { + name: string + templates: string[] + outputPath: FileResponse + createSubfolder?: boolean + data?: Record + overwrite?: FileResponse + silent?: boolean +} + +const helpers = { + camelCase, + snakeCase, + startCase, + kebabCase, + hyphenCase: kebabCase, + pascalCase, +} + +for (const helperName in helpers) { + Handlebars.registerHelper(helperName, helpers[helperName as keyof typeof helpers]) +} + +export async function Scaffold(config: ScaffoldConfig) { + try { + const options = { ...config } + const data = { name: options.name, Name: pascalCase(options.name), ...options.data } + l(options, "Config:", options) + l(options, "Data:", data) + for (let template of config.templates) { + try { + const tplStat = await stat(template) + if (tplStat.isDirectory()) { + template = template + "/**/*" + } + const files = await promisify(glob)(template, { dot: true }) + for (const templatePath of files) { + await handleTemplateFile(templatePath, options, data) + } + } catch (e) { + handleErr(e) + } + } + } catch (e) { + console.error(e) + process.exit(e.code ?? 1) + } +} + +async function handleTemplateFile( + templatePath: string, + options: ScaffoldConfig, + data: Record +): Promise { + return new Promise(async (resolve, reject) => { + try { + l(options, `Parsing ${templatePath}`) + const inputPath = path.join(process.cwd(), templatePath) + const outputPathOpt = getOptionValueForFile(inputPath, options.outputPath) + const outputDir = path.join( + process.cwd(), + ...([outputPathOpt, options.createSubfolder ? options.name : undefined].filter(Boolean) as string[]) + ) + const outputPath = path.join(outputDir, handlebarsParse(path.basename(inputPath), data)) + const overwrite = getOptionValueForFile(inputPath, options.overwrite ?? false) + const exists = await pathExists(outputPath) + + await createDirIfNotExists(outputDir, options) + + l(options, `Writing to ${outputPath}`) + if (!exists || overwrite) { + if (exists && overwrite) { + l(options, `File ${outputPath} exists, overwriting`) + } + const templateBuffer = await readFile(inputPath) + const outputContents = handlebarsParse(templateBuffer, data) + + await writeFile(outputPath, outputContents) + resolve() + } else if (exists) { + l(options, `File ${outputPath} already exists, skipping`) + } + } catch (e) { + handleErr(e) + reject(e) + } + }) +} + +function handlebarsParse(templateBuffer: Buffer | string, data: Record) { + const parser = Handlebars.compile(templateBuffer.toString(), { noEscape: true }) + const outputContents = parser(data) + return outputContents +} + +async function pathExists(filePath: string): Promise { + try { + await access(filePath, F_OK) + return true + } catch (e) { + if (e.code === "ENOENT") { + return false + } + throw e + } +} + +function handleErr(err: NodeJS.ErrnoException | null) { + if (err) throw err +} + +function l(options: ScaffoldConfig, ...obj: any[]) { + if (options.silent) { + return + } + console.log(...obj) +} + +async function createDirIfNotExists(dir: string, options: ScaffoldConfig): Promise { + const parentDir = path.dirname(dir) + + if (!(await pathExists(parentDir))) { + await createDirIfNotExists(parentDir, options) + } + + if (!(await pathExists(dir))) { + try { + await mkdir(dir) + return + } catch (e) { + if (e.code !== "EEXIST") { + throw e + } + return + } + } +} + +function pascalCase(s: string): string { + return startCase(s).replace(/\s+/g, "") +} + +function getOptionValueForFile(filePath: string, fn: FileResponse, defaultValue?: T): T { + if (typeof fn !== "function") { + return defaultValue ?? (fn as T) + } + return (fn as FileResponseFn)(filePath, path.dirname(filePath), path.basename(filePath)) +} + +export default Scaffold diff --git a/tsconfig.json b/tsconfig.json index ae9666f..e08fe23 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,9 @@ { "compilerOptions": { "target": "es5", - "module": "commonjs", + "module": "umd", + "moduleResolution": "node", + "esModuleInterop": true, "lib": [ "es2017", "es6" @@ -11,9 +13,8 @@ "strict": true, "sourceMap": true }, - "exclude": [ - "examples/**/*", - "test.ts", - "dist/**/*" + "include": [ + "src/index.ts", + "src/cmd.ts" ] -} \ No newline at end of file +} diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 832a696..0000000 --- a/webpack.config.js +++ /dev/null @@ -1,46 +0,0 @@ -const path = require("path") -const webpack = require("webpack") -const nodeExternals = require("webpack-node-externals") -const CopyPlugin = require("copy-webpack-plugin") - -module.exports = { - devtool: - process.env.NODE_ENV === "develop" ? "inline-source-map" : "source-map", - target: "node", - entry: { - index: "./scaffold.ts", - test: "./test.ts", - cmd: "./cmd.ts", - }, - output: { - filename: "[name].js", - path: path.resolve(__dirname, "dist"), - devtoolModuleFilenameTemplate: "[absolute-resource-path]", - library: "library", - libraryTarget: "umd", - }, - resolve: { - extensions: [".ts"], - }, - externals: [nodeExternals()], - module: { - rules: [ - { - test: [/\.tsx?$/], - loader: "ts-loader", - exclude: [/\/examples\//, /\/node_modules\//], - }, - ], - }, - plugins: [ - new webpack.DefinePlugin({ - __dirname: "__dirname", - }), - new webpack.BannerPlugin({ - banner: "#!/usr/bin/env node", - raw: true, - include: [/cmd\.js/], - }), - new CopyPlugin({ patterns: ["index.d.ts"] }), - ], -} diff --git a/yarn.lock b/yarn.lock index 610fd2a..cf07b61 100644 --- a/yarn.lock +++ b/yarn.lock @@ -608,6 +608,11 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad" integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA== +"@types/lodash@^4.14.171": + version "4.14.171" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.171.tgz#f01b3a5fe3499e34b622c362a46a609fdb23573b" + integrity sha512-7eQ2xYLLI/LsicL2nejW9Wyko3lcpN6O/z0ZLHrEQsg280zIdCv1t/0m6UtBjUHokCGBQ3gYTbHzDkZ1xOBwwg== + "@types/minimatch@*": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" @@ -923,6 +928,16 @@ argparse@^1.0.7: dependencies: sprintf-js "~1.0.2" +args@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/args/-/args-5.0.1.tgz#4bf298df90a4799a09521362c579278cc2fdd761" + integrity sha512-1kqmFCFsPffavQFGt8OxJdIcETti99kySRUPMpOhaGjL6mRJn8HFU1OxKY5bMqfZKUwTQc1mZkAjmGYaVOHFtQ== + dependencies: + camelcase "5.0.0" + chalk "2.4.2" + leven "2.1.0" + mri "1.1.4" + arr-diff@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520" @@ -1272,6 +1287,11 @@ callsites@^3.0.0: resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ== +camelcase@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.0.0.tgz#03295527d58bd3cd4aa75363f35b2e8d97be2f42" + integrity sha512-faqwZqnWxbxn+F1d399ygeamQNy3lPp/H9H6rNrqYh4FSVCtcY+3cub1MxA8o9mDd55mM8Aghuu/kuyYA6VTsA== + camelcase@^5.0.0, camelcase@^5.3.1: version "5.3.1" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320" @@ -1299,7 +1319,7 @@ caseless@~0.12.0: resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= -chalk@^2.0.0, chalk@^2.4.2: +chalk@2.4.2, chalk@^2.0.0, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -1889,11 +1909,42 @@ error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" +es-abstract@^1.18.0-next.2: + version "1.18.3" + resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.18.3.tgz#25c4c3380a27aa203c44b2b685bba94da31b63e0" + integrity sha512-nQIr12dxV7SSxE6r6f1l3DtAeEYdsGpps13dR0TwJg1S8gyp4ZPgy3FZcHBgbiQqnoqSTb+oC+kO4UQ0C/J8vw== + dependencies: + call-bind "^1.0.2" + es-to-primitive "^1.2.1" + function-bind "^1.1.1" + get-intrinsic "^1.1.1" + has "^1.0.3" + has-symbols "^1.0.2" + is-callable "^1.2.3" + is-negative-zero "^2.0.1" + is-regex "^1.1.3" + is-string "^1.0.6" + object-inspect "^1.10.3" + object-keys "^1.1.1" + object.assign "^4.1.2" + string.prototype.trimend "^1.0.4" + string.prototype.trimstart "^1.0.4" + unbox-primitive "^1.0.1" + es-module-lexer@^0.3.26: version "0.3.26" resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-0.3.26.tgz#7b507044e97d5b03b01d4392c74ffeb9c177a83b" integrity sha512-Va0Q/xqtrss45hWzP8CZJwzGSZJjDM5/MJRE3IXXnUCcVLElR9BRaE9F62BopysASyc4nM3uwhSW7FFB9nlWAA== +es-to-primitive@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.2.1.tgz#e55cd4c9cdc188bcefb03b366c736323fc5c898a" + integrity sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA== + dependencies: + is-callable "^1.1.4" + is-date-object "^1.0.1" + is-symbol "^1.0.2" + escalade@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" @@ -2264,6 +2315,13 @@ follow-redirects@^1.0.0: resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.2.tgz#dd73c8effc12728ba5cf4259d760ea5fb83e3147" integrity sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA== +for-each@^0.3.3: + version "0.3.3" + resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e" + integrity sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw== + dependencies: + is-callable "^1.1.3" + for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" @@ -2342,6 +2400,15 @@ get-intrinsic@^1.0.2: has "^1.0.3" has-symbols "^1.0.1" +get-intrinsic@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.1.1.tgz#15f59f376f855c446963948f0d24cd3637b4abc6" + integrity sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q== + dependencies: + function-bind "^1.1.1" + has "^1.0.3" + has-symbols "^1.0.1" + get-package-type@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/get-package-type/-/get-package-type-0.1.0.tgz#8de2d803cff44df3bc6c456e6668b36c3926e11a" @@ -2453,7 +2520,7 @@ handle-thing@^2.0.0: resolved "https://registry.yarnpkg.com/handle-thing/-/handle-thing-2.0.1.tgz#857f79ce359580c340d43081cc648970d0bb234e" integrity sha512-9Qn4yBxelxoh2Ow62nP+Ka/kMnOXRi8BXnRaUwezLNhqelnN49xKz4F/dPP8OYLxLxq6JDtZb2i9XznUQbNPTg== -handlebars@^4.1.0: +handlebars@^4.7.7: version "4.7.7" resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.7.tgz#9ce33416aad02dbd6c8fafa8240d5d98004945a1" integrity sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA== @@ -2478,6 +2545,11 @@ har-validator@~5.1.3: ajv "^6.12.3" har-schema "^2.0.0" +has-bigints@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/has-bigints/-/has-bigints-1.0.1.tgz#64fe6acb020673e3b78db035a5af69aa9d07b113" + integrity sha512-LSBS2LjbNBTf6287JEbEzvJgftkF5qFkmCo9hDRpAzKhUOlJ+hx8dd4USs00SgsUNwc4617J9ki5YtEClM2ffA== + has-flag@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" @@ -2493,6 +2565,11 @@ has-symbols@^1.0.1: resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.1.tgz#9f5214758a44196c406d9bd76cebf81ec2dd31e8" integrity sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg== +has-symbols@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.2.tgz#165d3070c00309752a1236a479331e3ac56f1423" + integrity sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw== + has-value@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/has-value/-/has-value-0.3.1.tgz#7b1f58bada62ca827ec0a2078025654845995e1f" @@ -2753,6 +2830,11 @@ is-arrayish@^0.2.1: resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0= +is-bigint@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-bigint/-/is-bigint-1.0.2.tgz#ffb381442503235ad245ea89e45b3dbff040ee5a" + integrity sha512-0JV5+SOCQkIdzjBK9buARcV804Ddu7A0Qet6sHi3FimE9ne6m4BGQZfRn+NZiXbBk4F4XmHfDZIipLj9pX8dSA== + is-binary-path@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-1.0.1.tgz#75f16642b480f187a711c814161fd3a4a7655898" @@ -2760,11 +2842,23 @@ is-binary-path@^1.0.0: dependencies: binary-extensions "^1.0.0" +is-boolean-object@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/is-boolean-object/-/is-boolean-object-1.1.1.tgz#3c0878f035cb821228d350d2e1e36719716a3de8" + integrity sha512-bXdQWkECBUIAcCkeH1unwJLIpZYaa5VvuygSyS/c2lf719mTKZDU5UdDRlpd01UjADgmW8RfqaP+mRaVPdr/Ng== + dependencies: + call-bind "^1.0.2" + is-buffer@^1.1.5: version "1.1.6" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w== +is-callable@^1.1.3, is-callable@^1.1.4, is-callable@^1.2.3: + version "1.2.3" + resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.3.tgz#8b1e0500b73a1d76c70487636f368e519de8db8e" + integrity sha512-J1DcMe8UYTBSrKezuIUTUwjXsho29693unXM2YhJUTR2txK/eG47bvNa/wipPFmZFgr/N6f1GA66dv0mEyTIyQ== + is-ci@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-2.0.0.tgz#6bc6334181810e04b5c22b3d589fdca55026404c" @@ -2867,6 +2961,16 @@ is-glob@^4.0.0, is-glob@^4.0.1: dependencies: is-extglob "^2.1.1" +is-negative-zero@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.1.tgz#3de746c18dda2319241a53675908d8f766f11c24" + integrity sha512-2z6JzQvZRa9A2Y7xC6dQQm4FSTSTNWjKIYYTt4246eMTJmIo0Q+ZyOsU66X8lxK1AbB92dFeglPLrhwpeRKO6w== + +is-number-object@^1.0.4: + version "1.0.5" + resolved "https://registry.yarnpkg.com/is-number-object/-/is-number-object-1.0.5.tgz#6edfaeed7950cff19afedce9fbfca9ee6dd289eb" + integrity sha512-RU0lI/n95pMoUKu9v1BZP5MBcZuNSVJkMkAG2dJqC4z2GlkGUNeH68SuHuBKBD/XFe+LHZ+f9BKkLET60Niedw== + is-number@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195" @@ -2917,6 +3021,14 @@ is-regex@^1.0.4: dependencies: has-symbols "^1.0.1" +is-regex@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.3.tgz#d029f9aff6448b93ebbe3f33dac71511fdcbef9f" + integrity sha512-qSVXFz28HM7y+IWX6vLCsexdlvzT1PJNFSBuaQLQ5o0IEw8UDYW6/2+eCMVyIsbM8CNLX2a/QWmSpyxYEHY7CQ== + dependencies: + call-bind "^1.0.2" + has-symbols "^1.0.2" + is-stream@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" @@ -2927,6 +3039,18 @@ is-stream@^2.0.0: resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.0.tgz#bde9c32680d6fae04129d6ac9d921ce7815f78e3" integrity sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw== +is-string@^1.0.5, is-string@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.6.tgz#3fe5d5992fb0d93404f32584d4b0179a71b54a5f" + integrity sha512-2gdzbKUuqtQ3lYNrUTQYoClPhm7oQu4UdpSZMp1/DGgkHBT8E2Z1l0yMdb6D4zNAxwDiMv8MdulKROJGNl0Q0w== + +is-symbol@^1.0.2, is-symbol@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.4.tgz#a6dac93b635b063ca6872236de88910a57af139c" + integrity sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg== + dependencies: + has-symbols "^1.0.2" + is-typedarray@^1.0.0, is-typedarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" @@ -3526,6 +3650,11 @@ kleur@^3.0.3: resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w== +leven@2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/leven/-/leven-2.1.0.tgz#c2e7a9f772094dee9d34202ae8acce4687875580" + integrity sha1-wuep93IJTe6dNCAq6KzORoeHVYA= + leven@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2" @@ -3590,7 +3719,7 @@ lodash.sortby@^4.7.0: resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg= -lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.19: +lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.19, lodash@^4.17.21: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== @@ -3760,6 +3889,11 @@ mkdirp@^0.5.1, mkdirp@^0.5.5: dependencies: minimist "^1.2.5" +mri@1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/mri/-/mri-1.1.4.tgz#7cb1dd1b9b40905f1fac053abe25b6720f44744a" + integrity sha512-6y7IjGPm8AzlvoUrwAaw1tLnUBudaS3752vcd8JtrpGGQn+rXIe63LFVHm/YMwtqAuh+LJPCFdlLYPWM1nYn6w== + ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" @@ -3927,6 +4061,11 @@ object-copy@^0.1.0: define-property "^0.2.5" kind-of "^3.0.3" +object-inspect@^1.10.3: + version "1.11.0" + resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.11.0.tgz#9dceb146cedd4148a0d9e51ab88d34cf509922b1" + integrity sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg== + object-is@^1.0.1: version "1.1.4" resolved "https://registry.yarnpkg.com/object-is/-/object-is-1.1.4.tgz#63d6c83c00a43f4cbc9434eb9757c8a5b8565068" @@ -3947,6 +4086,25 @@ object-visit@^1.0.0: dependencies: isobject "^3.0.0" +object.assign@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.2.tgz#0ed54a342eceb37b38ff76eb831a0e788cb63940" + integrity sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ== + dependencies: + call-bind "^1.0.0" + define-properties "^1.1.3" + has-symbols "^1.0.1" + object-keys "^1.1.1" + +object.getownpropertydescriptors@^2.1.1: + version "2.1.2" + resolved "https://registry.yarnpkg.com/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.1.2.tgz#1bd63aeacf0d5d2d2f31b5e393b03a7c601a23f7" + integrity sha512-WtxeKSzfBjlzL+F9b7M7hewDzMwy+C8NRssHd1YrNlzHzIDrXcXiNOMrezdAEM4UXixgV+vvnyBeN7Rygl2ttQ== + dependencies: + call-bind "^1.0.2" + define-properties "^1.1.3" + es-abstract "^1.18.0-next.2" + object.pick@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/object.pick/-/object.pick-1.3.0.tgz#87a10ac4c1694bd2e1cbf53591a66141fb5dd747" @@ -4997,6 +5155,22 @@ string-width@^4.1.0, string-width@^4.2.0: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.0" +string.prototype.trimend@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.4.tgz#e75ae90c2942c63504686c18b287b4a0b1a45f80" + integrity sha512-y9xCjw1P23Awk8EvTpcyL2NIr1j7wJ39f+k6lvRnSMz+mz9CGz9NYPelDk42kOz6+ql8xjfK8oYzy3jAP5QU5A== + dependencies: + call-bind "^1.0.2" + define-properties "^1.1.3" + +string.prototype.trimstart@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/string.prototype.trimstart/-/string.prototype.trimstart-1.0.4.tgz#b36399af4ab2999b4c9c648bd7a3fb2bb26feeed" + integrity sha512-jh6e984OBfvxS50tdY2nRZnoC5/mLFKOREQfw8t5yytkoUsJRNxvI/E39qu1sD0OtWI3OC0XgKSmcWwziwYuZw== + dependencies: + call-bind "^1.0.2" + define-properties "^1.1.3" + string_decoder@^1.1.1: version "1.3.0" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" @@ -5310,6 +5484,16 @@ uglify-js@^3.1.4: resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.12.6.tgz#f884584fcc42e10bca70db5cb32e8625c2c42535" integrity sha512-aqWHe3DfQmZUDGWBbabZ2eQnJlQd1fKlMUu7gV+MiTuDzdgDw31bI3wA2jLLsV/hNcDP26IfyEgSVoft5+0SVw== +unbox-primitive@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.1.tgz#085e215625ec3162574dc8859abee78a59b14471" + integrity sha512-tZU/3NqK3dA5gpE1KtyiJUrEB0lxnGkMFHptJ7q6ewdZ8s12QrODwNbhIJStmJkd1QDXa1NRA8aF2A1zk/Ypyw== + dependencies: + function-bind "^1.1.1" + has-bigints "^1.0.1" + has-symbols "^1.0.2" + which-boxed-primitive "^1.0.2" + union-value@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.1.tgz#0b6fe7b835aecda61c6ea4d4f02c14221e109847" @@ -5376,6 +5560,17 @@ util-deprecate@^1.0.1, util-deprecate@~1.0.1: resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= +util.promisify@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/util.promisify/-/util.promisify-1.1.1.tgz#77832f57ced2c9478174149cae9b96e9918cd54b" + integrity sha512-/s3UsZUrIfa6xDhr7zZhnE9SLQ5RIXyYfiVnMMyMDzOc8WhWN4Nbh36H842OyurKbCDAesZOJaVyvmSl6fhGQw== + dependencies: + call-bind "^1.0.0" + define-properties "^1.1.3" + for-each "^0.3.3" + has-symbols "^1.0.1" + object.getownpropertydescriptors "^2.1.1" + utils-merge@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" @@ -5637,6 +5832,17 @@ whatwg-url@^8.0.0: tr46 "^2.0.2" webidl-conversions "^6.1.0" +which-boxed-primitive@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6" + integrity sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg== + dependencies: + is-bigint "^1.0.1" + is-boolean-object "^1.1.0" + is-number-object "^1.0.4" + is-string "^1.0.5" + is-symbol "^1.0.3" + which-module@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"