diff --git a/dist/cmd.js b/dist/cmd.js index 5422ca6..19efcf1 100755 --- a/dist/cmd.js +++ b/dist/cmd.js @@ -1,3 +1,3 @@ #!/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 function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=6)}([function(e,t){e.exports=require("path")},function(e,t,n){"use strict";var o=this&&this.__assign||function(){return(o=Object.assign||function(e){for(var t,n=1,o=arguments.length;n=0&&(u=r.slice(0,s-1));for(var c=0,f=l;c=0&&(i=e.slice(r+t.length+1)),n=o+i}return this.parseLocals(n)},e.prototype.writeFile=function(e,t){var n=i.dirname(e);this.writeDirectory(n,e),console.info("Writing file:",e),r.writeFile(e,t,{encoding:"utf-8"},function(e){if(e)throw e})},e.prototype.run=function(){console.log("Generating scaffold: "+this.config.name+"...");var e,t=this.fileList(this.config.templates),n=0;console.log("Template files:",t);for(var o=0,i=t;o{"use strict";var e={784:function(e,t,o){var n=this&&this.__assign||function(){return(n=Object.assign||function(e){for(var t,o=1,n=arguments.length;o=0&&(c=r.slice(0,l-1));for(var u=0,p=s;u=0&&(i=e.slice(r+t.length+1)),o=n+i}return this.parseLocals(o)},e.prototype.writeFile=function(e,t){var o=i.dirname(e);this.writeDirectory(o,e),console.info("Writing file:",e),r.writeFile(e,t,{encoding:"utf-8"},(function(e){if(e)throw e}))},e.prototype.run=function(){console.log("Generating scaffold: "+this.config.name+"...");var e,t=this.fileList(this.config.templates),o=0;console.log("Template files:",t);for(var n=0,i=t;n{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(n){if(t[n])return t[n].exports;var r=t[n]={exports:{}};return e[n].call(r.exports,r,r.exports,o),r.exports}(784)})()})); //# sourceMappingURL=cmd.js.map \ No newline at end of file diff --git a/dist/cmd.js.map b/dist/cmd.js.map index 2cd87b3..157c431 100755 --- a/dist/cmd.js.map +++ b/dist/cmd.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack/universalModuleDefinition","webpack/bootstrap","external \"path\"","/Users/planck/Dev/simple-scaffold/scaffold.ts","external \"fs\"","external \"glob\"","external \"handlebars\"","/Users/planck/Dev/simple-scaffold/cmd.ts","external \"command-line-args\"","external \"command-line-usage\""],"names":["root","factory","exports","module","define","amd","global","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","require","fs","path","glob","handlebars","SimpleScaffold","config","this","locals","DefaultConfig","templates","output","process","cwd","createSubfolder","__assign","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","text","compile","noEscape","template","fileList","input","_i","input_1","length","checkPath","files","sync","dot","map","g","join","idx","indexOf","cleanCheckPath","_a","files_1","file","push","base","getFileContents","filePath","console","log","readFileSync","toString","getOutputPath","basePath","out","outputDir","relativeFilePath","writeFile","fileContents","baseDir","dirname","writeDirectory","info","encoding","err","run","fileConf","count","templates_1","outputPath","contents","outputContents","lstatSync","isDirectory","replace","e","error","Error","parent","existsSync","mkdirSync","default","scaffold_1","cliArgs","cliUsage","filePathParser","content","startsWith","sep","defs","alias","type","String","description","defaultOption","typeLabel","multiple","_b","split","trim","includes","defaultValue","Boolean","args","camelCase","help","header","optionList","reduce","all","cur","createSubFolder","exit"],"mappings":";CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,IACA,mBAAAG,eAAAC,IACAD,OAAA,GAAAH,GACA,iBAAAC,QACAA,QAAA,QAAAD,IAEAD,EAAA,QAAAC,IARA,CASCK,OAAA,WACD,mBCTA,IAAAC,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAP,QAGA,IAAAC,EAAAI,EAAAE,GAAA,CACAC,EAAAD,EACAE,GAAA,EACAT,QAAA,IAUA,OANAU,EAAAH,GAAAI,KAAAV,EAAAD,QAAAC,IAAAD,QAAAM,GAGAL,EAAAQ,GAAA,EAGAR,EAAAD,QA0DA,OArDAM,EAAAM,EAAAF,EAGAJ,EAAAO,EAAAR,EAGAC,EAAAQ,EAAA,SAAAd,EAAAe,EAAAC,GACAV,EAAAW,EAAAjB,EAAAe,IACAG,OAAAC,eAAAnB,EAAAe,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CV,EAAAgB,EAAA,SAAAtB,GACA,oBAAAuB,eAAAC,aACAN,OAAAC,eAAAnB,EAAAuB,OAAAC,YAAA,CAAwDC,MAAA,WAExDP,OAAAC,eAAAnB,EAAA,cAAiDyB,OAAA,KAQjDnB,EAAAoB,EAAA,SAAAD,EAAAE,GAEA,GADA,EAAAA,IAAAF,EAAAnB,EAAAmB,IACA,EAAAE,EAAA,OAAAF,EACA,KAAAE,GAAA,iBAAAF,QAAAG,W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+IACzC,CAAEoB,OAAQ,UAAWC,WAAYlB,IAGnCc,EAAK/F,QAAU+F,EAAK/F,QAAU,IAAIoG,OAAO,SAACC,EAAaC,GAAgB,OAAA/F,EAAA,GAAM8F,EAAQC,IAAQ,IAChE,OAAzBP,EAAKQ,kBACPR,EAAKQ,iBAAkB,IAGrBR,EAAKE,MAASF,EAAKhI,OACrByE,QAAQC,IAAImC,EAASqB,IACrB7F,QAAQoG,KAAK,IAGfhE,QAAQc,KAAK,UAAWyC,GACxB,IAAIrB,EAAAD,QAAe,CACjB1G,KAAMgI,EAAKhI,KACXmC,UAAW6F,EAAK7F,UAChBC,OAAQ4F,EAAK5F,OACbH,OAAQ+F,EAAK/F,OACbM,gBAAiByF,EAAKQ,kBACrB9C,qBChGHxG,EAAAD,QAAAwC,QAAA,oCCAAvC,EAAAD,QAAAwC,QAAA","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 "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 6);\n","module.exports = require(\"path\");","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 }\n\n this.config = { ...DefaultConfig, ...config }\n\n const DefaultLocals = {\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 const template = handlebars.compile(text, {\n noEscape: true,\n })\n return template(this.locals)\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 console.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)\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 relativeFilePath = file.slice(idx + basePath.length + 1)\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 console.info(\"Writing file:\", filePath)\n fs.writeFile(filePath, fileContents, { encoding: \"utf-8\" }, (err) => {\n if (err) {\n throw err\n }\n })\n }\n\n public run(): void {\n console.log(`Generating scaffold: ${this.config.name}...`)\n const templates = this.fileList(this.config.templates)\n\n let fileConf,\n count = 0\n\n console.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\n console.info(\"Writing:\", {\n file,\n base,\n outputPath,\n outputContents: outputContents.replace(\"\\n\", \"\\\\n\"),\n })\n this.writeFile(outputPath, outputContents)\n } catch (e) {\n console.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 console.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 console.info(\"Creating directory:\", {\n file,\n outputPath,\n })\n fs.mkdirSync(outputPath)\n }\n }\n}\n\nexport default SimpleScaffold\n","module.exports = require(\"fs\");","module.exports = require(\"glob\");","module.exports = require(\"handlebars\");","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 & { description?: string, typeLabel?: string }\n\nfunction localsParser(content: string) {\n const [key, value] = content.split('=')\n return { [key]: value }\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 ? ['true', '1', 'on'].includes(text.trim()) : 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 key-value map for the template to use in parsing.`,\n multiple: true,\n typeLabel: '{underline Key=Value}',\n type: localsParser,\n },\n {\n name: 'create-sub-folder',\n alias: 'S',\n typeLabel: '{underline Boolean}',\n description: '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 })\n\nconst help = [\n { header: 'Scaffold Generator', content: `Generate scaffolds for your project based on file templates.\\nUsage: {bold simple-scaffold} {underline scaffold-name} {underline [options]}` },\n { header: 'Options', optionList: defs }\n]\n\nargs.locals = (args.locals || []).reduce((all: object, cur: object) => ({ ...all, ...cur }), {} as IScaffold.Config['locals'])\nif (args.createSubFolder === null) {\n args.createSubFolder = true\n}\n\nif (args.help || !args.name) {\n console.log(cliUsage(help))\n process.exit(0)\n}\n\nconsole.info('Config:', args)\nnew SimpleScaffold({\n name: args.name,\n templates: args.templates,\n output: args.output,\n locals: args.locals,\n createSubfolder: args.createSubFolder,\n}).run()\n","module.exports = require(\"command-line-args\");","module.exports = require(\"command-line-usage\");"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack/universalModuleDefinition","/Users/planck/Dev/simple-scaffold/cmd.ts","/Users/planck/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","defs","name","alias","type","String","description","defaultOption","typeLabel","multiple","split","key","value","text","trim","length","includes","defaultValue","Boolean","args","cliArgs","camelCase","help","header","optionList","locals","reduce","all","cur","createSubFolder","console","log","cliUsage","exit","info","templates","output","createSubfolder","run","config","DefaultConfig","this","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","handlebars","compile","noEscape","template","fileList","input","checkPath","files","glob","sync","dot","map","g","idx","indexOf","cleanCheckPath","file","push","base","getFileContents","filePath","fs","readFileSync","toString","getOutputPath","basePath","out","outputDir","relativeFilePath","writeFile","fileContents","baseDir","dirname","writeDirectory","encoding","err","fileConf","count","outputPath","contents","outputContents","lstatSync","isDirectory","replace","e","error","Error","parent","existsSync","mkdirSync","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,uUCVA,aAGA,SACA,QACA,SASA,SAASC,EAAeC,GACtB,OAAIA,EAAQC,WAAW,KACdD,EAEF,CAACE,QAAQC,MAAOH,GAASI,KAAKC,EAAKC,KAO5C,IAAMC,EAAc,CAClB,CACEC,KAAM,OACNC,MAAO,IACPC,KAAMC,OACNC,YAAa,wBACbC,eAAe,GAEjB,CACEL,KAAM,YACNC,MAAO,IACPC,KAAMX,EACNe,UAAW,qBACXF,YAAa,8OACbG,UAAU,GAEZ,CACEP,KAAM,SACNC,MAAO,IACPC,KAAMX,EACNe,UAAW,mBACXF,YAAa,uIAEf,CACEJ,KAAM,SACNC,MAAO,IACPG,YAAa,sDACbG,UAAU,EACVD,UAAW,wBACXJ,KA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,WAAU,IAEZjB,EAAG4B,UAAUX,KAGnB,EAhJA,GAkJA,UAAeY,G,QCxJf7G,EAAOD,QAAU+G,QAAQ,sB,OCAzB9G,EAAOD,QAAU+G,QAAQ,uB,QCAzB9G,EAAOD,QAAU+G,QAAQ,O,QCAzB9G,EAAOD,QAAU+G,QAAQ,S,QCAzB9G,EAAOD,QAAU+G,QAAQ,e,QCAzB9G,EAAOD,QAAU+G,QAAQ,UCCrBC,EAA2B,GCE/B,ODCA,SAASC,EAAoBC,GAE5B,GAAGF,EAAyBE,GAC3B,OAAOF,EAAyBE,GAAUlH,QAG3C,IAAIC,EAAS+G,EAAyBE,GAAY,CAGjDlH,QAAS,IAOV,OAHAmH,EAAoBD,GAAUE,KAAKnH,EAAOD,QAASC,EAAQA,EAAOD,QAASiH,GAGpEhH,EAAOD,QCjBRiH,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 & { description?: string, typeLabel?: string }\n\nfunction localsParser(content: string) {\n const [key, value] = content.split('=')\n return { [key]: value }\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 ? ['true', '1', 'on'].includes(text.trim()) : 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 key-value map for the template to use in parsing.`,\n multiple: true,\n typeLabel: '{underline Key=Value}',\n type: localsParser,\n },\n {\n name: 'create-sub-folder',\n alias: 'S',\n typeLabel: '{underline Boolean}',\n description: '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 })\n\nconst help = [\n { header: 'Scaffold Generator', content: `Generate scaffolds for your project based on file templates.\\nUsage: {bold simple-scaffold} {underline scaffold-name} {underline [options]}` },\n { header: 'Options', optionList: defs }\n]\n\nargs.locals = (args.locals || []).reduce((all: object, cur: object) => ({ ...all, ...cur }), {} as IScaffold.Config['locals'])\nif (args.createSubFolder === null) {\n args.createSubFolder = true\n}\n\nif (args.help || !args.name) {\n console.log(cliUsage(help))\n process.exit(0)\n}\n\nconsole.info('Config:', args)\nnew SimpleScaffold({\n name: args.name,\n templates: args.templates,\n output: args.output,\n locals: args.locals,\n createSubfolder: args.createSubFolder,\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 }\n\n this.config = { ...DefaultConfig, ...config }\n\n const DefaultLocals = {\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 const template = handlebars.compile(text, {\n noEscape: true,\n })\n return template(this.locals)\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 console.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)\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 relativeFilePath = file.slice(idx + basePath.length + 1)\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 console.info(\"Writing file:\", filePath)\n fs.writeFile(filePath, fileContents, { encoding: \"utf-8\" }, (err) => {\n if (err) {\n throw err\n }\n })\n }\n\n public run(): void {\n console.log(`Generating scaffold: ${this.config.name}...`)\n const templates = this.fileList(this.config.templates)\n\n let fileConf,\n count = 0\n\n console.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\n console.info(\"Writing:\", {\n file,\n base,\n outputPath,\n outputContents: outputContents.replace(\"\\n\", \"\\\\n\"),\n })\n this.writeFile(outputPath, outputContents)\n } catch (e) {\n console.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 console.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 console.info(\"Creating directory:\", {\n file,\n outputPath,\n })\n fs.mkdirSync(outputPath)\n }\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 diff --git a/dist/index.js b/dist/index.js index 9a7501b..681e817 100755 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ -!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 function(t){var e={};function o(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=1)}([function(t,e){t.exports=require("path")},function(t,e,o){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(t){for(var e,o=1,n=arguments.length;o=0&&(u=r.slice(0,f-1));for(var l=0,a=c;l=0&&(i=t.slice(r+e.length+1)),o=n+i}return this.parseLocals(o)},t.prototype.writeFile=function(t,e){var o=i.dirname(t);this.writeDirectory(o,t),console.info("Writing file:",t),r.writeFile(t,e,{encoding:"utf-8"},function(t){if(t)throw t})},t.prototype.run=function(){console.log("Generating scaffold: "+this.config.name+"...");var t,e=this.fileList(this.config.templates),o=0;console.log("Template files:",e);for(var n=0,i=e;n{"use strict";var t={493:function(t,e,o){var i=this&&this.__assign||function(){return(i=Object.assign||function(t){for(var e,o=1,i=arguments.length;o=0&&(l=r.slice(0,a-1));for(var f=0,u=c;f=0&&(n=t.slice(r+e.length+1)),o=i+n}return this.parseLocals(o)},t.prototype.writeFile=function(t,e){var o=n.dirname(t);this.writeDirectory(o,t),console.info("Writing file:",t),r.writeFile(t,e,{encoding:"utf-8"},(function(t){if(t)throw t}))},t.prototype.run=function(){console.log("Generating scaffold: "+this.config.name+"...");var t,e=this.fileList(this.config.templates),o=0;console.log("Template files:",e);for(var i=0,n=e;i{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(i){if(e[i])return e[i].exports;var r=e[i]={exports:{}};return t[i].call(r.exports,r,r.exports,o),r.exports}(493)})()})); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map index 93e66e0..2b478af 100755 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack/universalModuleDefinition","webpack/bootstrap","external \"path\"","/Users/planck/Dev/simple-scaffold/scaffold.ts","external \"fs\"","external \"glob\"","external \"handlebars\""],"names":["root","factory","exports","module","define","amd","global","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","require","fs","path","glob","handlebars","SimpleScaffold","config","this","locals","DefaultConfig","templates","output","process","cwd","createSubfolder","__assign","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","text","compile","noEscape","template","fileList","input","_i","input_1","length","checkPath","files","sync","dot","map","g","join","idx","indexOf","cleanCheckPath","_a","files_1","file","push","base","getFileContents","filePath","console","log","readFileSync","toString","getOutputPath","basePath","out","outputDir","relativeFilePath","writeFile","fileContents","baseDir","dirname","writeDirectory","info","encoding","err","run","fileConf","count","templates_1","outputPath","contents","outputContents","lstatSync","isDirectory","replace","e","error","Error","parent","existsSync","mkdirSync","default"],"mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,IACA,mBAAA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,CAAvBsC,EAAQE,EAAAxC,GACX,IAAIyC,OAAU,EAAEC,OAAQ,EAAEC,OAAc,EAAE5B,OAAI,EAAEE,OAAI,EACpD,IAKE,GAJAsB,IACAxB,EAAOuB,EAASvB,KAChBE,EAAOqB,EAASrB,KAChBwB,EAAa9D,KAAK6C,cAAcT,EAAME,GAClC5C,EAAGuE,UAAU7B,GAAM8B,cAAe,CACpClE,KAAKsD,eAAeQ,EAAY1B,GAChC,SAEF2B,EAAW/D,KAAKuC,gBAAgBH,GAChC4B,EAAiBhE,KAAKc,YAAYiD,GAElCtB,QAAQc,KAAK,WAAY,CACvBnB,KAAIA,EACJE,KAAIA,EACJwB,WAAUA,EACVE,eAAgBA,EAAeG,QAAQ,KAAM,SAE/CnE,KAAKkD,UAAUY,EAAYE,GAC3B,MAAOI,GAQP,MAPA3B,QAAQ4B,MAAM,+BAAgC,CAC5CjC,KAAIA,EACJE,KAAIA,EACJyB,SAAQA,EACRD,WAAUA,EACVE,eAAcA,IAEVI,GAIV,IAAKR,EACH,MAAM,IAAIU,MAAM,yBAGlB7B,QAAQC,IAAI,SAGN5C,EAAAT,UAAAiE,eAAR,SAAuBQ,EAAoB1B,GACzC,IAAMmC,EAAS5E,EAAK0D,QAAQS,GACvBpE,EAAG8E,WAAWD,IACjBvE,KAAKsD,eAAeiB,EAAQT,GAEzBpE,EAAG8E,WAAWV,KACjBrB,QAAQc,KAAK,sBAAuB,CAClCnB,KAAIA,EACJ0B,WAAUA,IAEZpE,EAAG+E,UAAUX,KAGnBhE,EAhJA,GAkJA7C,EAAAyH,QAAe5E,iBCxJf5C,EAAAD,QAAAwC,QAAA,qBCAAvC,EAAAD,QAAAwC,QAAA,uBCAAvC,EAAAD,QAAAwC,QAAA","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 "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n","module.exports = require(\"path\");","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 }\n\n this.config = { ...DefaultConfig, ...config }\n\n const DefaultLocals = {\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 const template = handlebars.compile(text, {\n noEscape: true,\n })\n return template(this.locals)\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 console.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)\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 relativeFilePath = file.slice(idx + basePath.length + 1)\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 console.info(\"Writing file:\", filePath)\n fs.writeFile(filePath, fileContents, { encoding: \"utf-8\" }, (err) => {\n if (err) {\n throw err\n }\n })\n }\n\n public run(): void {\n console.log(`Generating scaffold: ${this.config.name}...`)\n const templates = this.fileList(this.config.templates)\n\n let fileConf,\n count = 0\n\n console.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\n console.info(\"Writing:\", {\n file,\n base,\n outputPath,\n outputContents: outputContents.replace(\"\\n\", \"\\\\n\"),\n })\n this.writeFile(outputPath, outputContents)\n } catch (e) {\n console.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 console.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 console.info(\"Creating directory:\", {\n file,\n outputPath,\n })\n fs.mkdirSync(outputPath)\n }\n }\n}\n\nexport default SimpleScaffold\n","module.exports = require(\"fs\");","module.exports = require(\"glob\");","module.exports = require(\"handlebars\");"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack/universalModuleDefinition","/Users/planck/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","this","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","text","handlebars","compile","noEscape","template","fileList","input","checkPath","files","glob","sync","dot","map","g","path","join","idx","indexOf","cleanCheckPath","file","push","base","getFileContents","filePath","console","log","fs","readFileSync","toString","getOutputPath","basePath","out","outputDir","relativeFilePath","length","writeFile","fileContents","baseDir","dirname","writeDirectory","info","encoding","err","run","fileConf","count","outputPath","contents","outputContents","lstatSync","isDirectory","replace","e","error","Error","parent","existsSync","mkdirSync","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,uUCVA,aACA,SAEA,SACA,SAEA,aAIE,WAAYC,GAFL,KAAAC,OAAqC,GAG1C,IAAMC,EAAkC,CACtCC,KAAM,WACNC,UAAW,GACXC,OAAQC,QAAQC,MAChBC,iBAAiB,GAGnBC,KAAKT,OAAS,EAAH,KAAQE,GAAkBF,GAErC,IAAMU,EAAgB,CACpBC,KAAMF,KAAKT,OAAOG,KAAM,GAAGS,cAAgBH,KAAKT,OAAOG,KAAMU,MAAM,GACnEV,KAAMM,KAAKT,OAAOG,KAAM,GAAGW,cAAgBL,K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AU,IAEZpB,EAAG+B,UAAUX,KAGnB,EAhJA,GAkJA,UAAeY,G,QCxJf9E,EAAOD,QAAUgF,QAAQ,O,QCAzB/E,EAAOD,QAAUgF,QAAQ,S,QCAzB/E,EAAOD,QAAUgF,QAAQ,e,QCAzB/E,EAAOD,QAAUgF,QAAQ,UCCrBC,EAA2B,GCE/B,ODCA,SAASC,EAAoBC,GAE5B,GAAGF,EAAyBE,GAC3B,OAAOF,EAAyBE,GAAUnF,QAG3C,IAAIC,EAASgF,EAAyBE,GAAY,CAGjDnF,QAAS,IAOV,OAHAoF,EAAoBD,GAAUE,KAAKpF,EAAOD,QAASC,EAAQA,EAAOD,QAASkF,GAGpEjF,EAAOD,QCjBRkF,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 }\n\n this.config = { ...DefaultConfig, ...config }\n\n const DefaultLocals = {\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 const template = handlebars.compile(text, {\n noEscape: true,\n })\n return template(this.locals)\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 console.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)\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 relativeFilePath = file.slice(idx + basePath.length + 1)\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 console.info(\"Writing file:\", filePath)\n fs.writeFile(filePath, fileContents, { encoding: \"utf-8\" }, (err) => {\n if (err) {\n throw err\n }\n })\n }\n\n public run(): void {\n console.log(`Generating scaffold: ${this.config.name}...`)\n const templates = this.fileList(this.config.templates)\n\n let fileConf,\n count = 0\n\n console.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\n console.info(\"Writing:\", {\n file,\n base,\n outputPath,\n outputContents: outputContents.replace(\"\\n\", \"\\\\n\"),\n })\n this.writeFile(outputPath, outputContents)\n } catch (e) {\n console.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 console.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 console.info(\"Creating directory:\", {\n file,\n outputPath,\n })\n fs.mkdirSync(outputPath)\n }\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 diff --git a/dist/test.js b/dist/test.js index c7d962a..55891b5 100755 --- a/dist/test.js +++ b/dist/test.js @@ -1,2 +1,2 @@ -!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 function(t){var e={};function o(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=5)}([function(t,e){t.exports=require("path")},function(t,e,o){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(t){for(var e,o=1,n=arguments.length;o=0&&(l=r.slice(0,c-1));for(var a=0,f=u;a=0&&(i=t.slice(r+e.length+1)),o=n+i}return this.parseLocals(o)},t.prototype.writeFile=function(t,e){var o=i.dirname(t);this.writeDirectory(o,t),console.info("Writing file:",t),r.writeFile(t,e,{encoding:"utf-8"},function(t){if(t)throw t})},t.prototype.run=function(){console.log("Generating scaffold: "+this.config.name+"...");var t,e=this.fileList(this.config.templates),o=0;console.log("Template files:",e);for(var n=0,i=e;n{"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&&(l=i.slice(0,c-1));for(var u=0,p=a;u=0&&(n=t.slice(i+e.length+1)),o=r+n}return this.parseLocals(o)},t.prototype.writeFile=function(t,e){var o=n.dirname(t);this.writeDirectory(o,t),console.info("Writing file:",t),i.writeFile(t,e,{encoding:"utf-8"},(function(t){if(t)throw t}))},t.prototype.run=function(){console.log("Generating scaffold: "+this.config.name+"...");var t,e=this.fileList(this.config.templates),o=0;console.log("Template files:",e);for(var r=0,n=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()},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 index 530d643..d3996b5 100755 --- a/dist/test.js.map +++ b/dist/test.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack/universalModuleDefinition","webpack/bootstrap","external \"path\"","/Users/planck/Dev/simple-scaffold/scaffold.ts","external \"fs\"","external \"glob\"","external \"handlebars\"","/Users/planck/Dev/simple-scaffold/test.ts"],"names":["root","factory","exports","module","define","amd","global","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","require","fs","path","glob","handlebars","SimpleScaffold","config","this","locals","DefaultConfig","templates","output","process","cwd","createSubfolder","__assign","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","text","compile","noEscape","template","fileList","input","_i","input_1","length","checkPath","files","sync","dot","map","g","join","idx","indexOf","cleanCheckPath","_a","files_1","file","push","base","getFileContents","filePath","console","log","readFileSync","toString","getOutputPath","basePath","out","outputDir","relativeFilePath","writeFile","fileContents","baseDir","dirname","writeDirectory","info","encoding","err","run","fileConf","count","templates_1","outputPath","contents","outputContents","lstatSync","isDirectory","replace","e","error","Error","parent","existsSync","mkdirSync","default","scaffold_1","templateDir"],"mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,IACA,mBAAAG,eAAAC,IACAD,OAAA,GAAAH,GACA,iBAAAC,QACAA,QAAA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,SACVV,MAAO,aAERgF,MAEH,IAAIiB,EAAAD,QAAe,CACjBvE,UAAW,CAACyE,EAAc,8BAC1BxE,OAAQwE,EAAc,eACtB3E,OAAQ,CACNb,SAAU,SACVV,MAAO,aAERgF","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 "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 5);\n","module.exports = require(\"path\");","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 }\n\n this.config = { ...DefaultConfig, ...config }\n\n const DefaultLocals = {\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 const template = handlebars.compile(text, {\n noEscape: true,\n })\n return template(this.locals)\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 console.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)\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 relativeFilePath = file.slice(idx + basePath.length + 1)\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 console.info(\"Writing file:\", filePath)\n fs.writeFile(filePath, fileContents, { encoding: \"utf-8\" }, (err) => {\n if (err) {\n throw err\n }\n })\n }\n\n public run(): void {\n console.log(`Generating scaffold: ${this.config.name}...`)\n const templates = this.fileList(this.config.templates)\n\n let fileConf,\n count = 0\n\n console.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\n console.info(\"Writing:\", {\n file,\n base,\n outputPath,\n outputContents: outputContents.replace(\"\\n\", \"\\\\n\"),\n })\n this.writeFile(outputPath, outputContents)\n } catch (e) {\n console.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 console.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 console.info(\"Creating directory:\", {\n file,\n outputPath,\n })\n fs.mkdirSync(outputPath)\n }\n }\n}\n\nexport default SimpleScaffold\n","module.exports = require(\"fs\");","module.exports = require(\"glob\");","module.exports = require(\"handlebars\");","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"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack/universalModuleDefinition","/Users/planck/Dev/simple-scaffold/scaffold.ts","/Users/planck/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","this","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","text","handlebars","compile","noEscape","template","fileList","input","checkPath","files","glob","sync","dot","map","g","path","join","idx","indexOf","cleanCheckPath","file","push","base","getFileContents","filePath","console","log","fs","readFileSync","toString","getOutputPath","basePath","out","outputDir","relativeFilePath","length","writeFile","fileContents","baseDir","dirname","writeDirectory","info","encoding","err","run","fileConf","count","outputPath","contents","outputContents","lstatSync","isDirectory","replace","e","error","Error","parent","existsSync","mkdirSync","SimpleScaffold","templateDir","property","value","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,uUCVA,aACA,SAEA,SACA,SAEA,aAIE,WAAYC,GAFL,KAAAC,OAAqC,GAG1C,IAAMC,EAAkC,CACtCC,KAAM,WACNC,UAAW,GACXC,OAAQC,QAAQC,MAChBC,iBAAiB,GAGnBC,KAAKT,OAAS,EAAH,KAAQE,GAAkBF,GAErC,IAAMU,EAAgB,CACpBC,KAAMF,KAAKT,OAAOG,KAAM,GAAGS,cAAgBH,KAAKT,OAAOG,KAAMU,MAAM,GACnEV,KAAMM,KAAKT,OAAOG,KAAM,GAAGW,cAAgBL,KAAKT,OAAOG,KAAMU,MAAM,IAGrEJ,KAAKR,OAAS,EAAH,KAAQS,GAAkBV,EAAOC,QA6HhD,OA1HU,YAAAc,YAAR,SAAoBC,GAIlB,OAHiBC,EAAWC,QAAQF,EAAM,CACxCG,UAAU,GAELC,CAASX,KAAKR,SAGf,YAAAoB,SAAR,SAAiBC,GAEf,IADA,IAAMjB,EAA+B,GACb,MAAAiB,EAAA,eAAO,CAA1B,IAAMC,EAAS,KACZC,EAAQC,EACXC,KAAKH,EAAW,CAAEI,KAAK,IACvBC,KAAI,SAACC,GAAM,MAAS,KAARA,EAAE,GAAYA,EAAIC,EAAKC,KAAKzB,QAAQC,MAAOsB,MACpDG,EAAMT,EAAUU,QAAQ,KAC1BC,EAAiBX,EACjBS,GAAO,IACTE,EAAiBX,EAAUV,MAAM,EAAGmB,EAAM,IAE5C,IAAmB,UAAAR,EAAA,eAAO,CAArB,IAAMW,EAAI,KACb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B,OAAOF,EAAyBE,GAAUtF,QAG3C,IAAIC,EAASmF,EAAyBE,GAAY,CAGjDtF,QAAS,IAOV,OAHAuF,EAAoBD,GAAUE,KAAKvF,EAAOD,QAASC,EAAQA,EAAOD,QAASqF,GAGpEpF,EAAOD,QCjBRqF,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 }\n\n this.config = { ...DefaultConfig, ...config }\n\n const DefaultLocals = {\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 const template = handlebars.compile(text, {\n noEscape: true,\n })\n return template(this.locals)\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 console.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)\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 relativeFilePath = file.slice(idx + basePath.length + 1)\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 console.info(\"Writing file:\", filePath)\n fs.writeFile(filePath, fileContents, { encoding: \"utf-8\" }, (err) => {\n if (err) {\n throw err\n }\n })\n }\n\n public run(): void {\n console.log(`Generating scaffold: ${this.config.name}...`)\n const templates = this.fileList(this.config.templates)\n\n let fileConf,\n count = 0\n\n console.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\n console.info(\"Writing:\", {\n file,\n base,\n outputPath,\n outputContents: outputContents.replace(\"\\n\", \"\\\\n\"),\n })\n this.writeFile(outputPath, outputContents)\n } catch (e) {\n console.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 console.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 console.info(\"Creating directory:\", {\n file,\n outputPath,\n })\n fs.mkdirSync(outputPath)\n }\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","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/package.json b/package.json index 117f6e6..5a7d396 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "bin": "dist/cmd.js", "types": "index.d.ts", "scripts": { - "build": "NODE_ENV=${NODE_ENV:-production} webpack -p && chmod -R +x ./dist", + "build": "NODE_ENV=${NODE_ENV:-production} webpack && chmod -R +x ./dist", "prepublishOnly": "yarn build", "dev": "webpack --watch", "start": "node dist/scaffold.js", @@ -20,7 +20,7 @@ }, "dependencies": { "command-line-args": "^5.0.2", - "command-line-usage": "^5.0.5", + "command-line-usage": "^6.1.1", "glob": "^7.1.3", "handlebars": "^4.1.0" }, @@ -28,16 +28,15 @@ "@types/command-line-args": "^5.0.0", "@types/command-line-usage": "^5.0.1", "@types/glob": "^7.1.1", - "@types/handlebars": "^4.0.40", - "@types/node": "^11.9.5", - "copy-webpack-plugin": "^5.0.0", - "jest": "^24.1.0", - "ts-loader": "^5.3.3", - "typescript": "^3.3.3333", - "webpack": "^4.29.5", - "webpack-cli": "^3.2.3", + "@types/node": "^14.14.22", + "copy-webpack-plugin": "^7.0.0", + "jest": "^26.6.3", + "ts-loader": "^8.0.14", + "typescript": "^4.1.3", + "webpack": "^5.19.0", + "webpack-cli": "^4.4.0", "webpack-dev-server": "^3.2.1", - "webpack-node-externals": "^1.7.2" + "webpack-node-externals": "^2.5.2" }, "jest": { "testPathIgnorePatterns": [ @@ -45,4 +44,4 @@ "dist" ] } -} +} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 1f0784a..832a696 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,45 +1,46 @@ -const path = require('path') -const webpack = require('webpack') -const nodeExternals = require('webpack-node-externals') -const CopyPlugin = require('copy-webpack-plugin') +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', + devtool: + process.env.NODE_ENV === "develop" ? "inline-source-map" : "source-map", + target: "node", entry: { - index: './scaffold.ts', - test: './test.ts', - cmd: './cmd.ts', + 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', + filename: "[name].js", + path: path.resolve(__dirname, "dist"), + devtoolModuleFilenameTemplate: "[absolute-resource-path]", + library: "library", + libraryTarget: "umd", }, resolve: { - extensions: ['.ts'] + extensions: [".ts"], }, externals: [nodeExternals()], module: { rules: [ { test: [/\.tsx?$/], - loader: 'ts-loader', - exclude: [/\/examples\//, /\/node_modules\//] - } - ] + loader: "ts-loader", + exclude: [/\/examples\//, /\/node_modules\//], + }, + ], }, plugins: [ new webpack.DefinePlugin({ - '__dirname': '__dirname' + __dirname: "__dirname", }), new webpack.BannerPlugin({ - banner: '#!/usr/bin/env node', + banner: "#!/usr/bin/env node", raw: true, include: [/cmd\.js/], }), - new CopyPlugin(['index.d.ts']), + new CopyPlugin({ patterns: ["index.d.ts"] }), ], }