From 4ca7c6acb3b6575a2a93a707d61ac89fda15ecd6 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Fri, 5 Jan 2018 04:04:33 +0200 Subject: [PATCH] Fixed cmd --- cmd.ts | 2 ++ dist/cmd.js | 2 +- dist/cmd.js.map | 2 +- dist/scaffold.js | 2 +- dist/scaffold.js.map | 2 +- dist/test.js | 2 +- dist/test.js.map | 2 +- package.json | 6 ++++-- 8 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cmd.ts b/cmd.ts index 56f2b26..bdfe490 100644 --- a/cmd.ts +++ b/cmd.ts @@ -40,6 +40,7 @@ class ScaffoldCmd { } private getArgValue(arg: string, value: string, options: IScaffold.IConfig) { + console.log({arg}) switch (arg) { case 'template': return (options.templates || []).concat([value]) @@ -52,6 +53,7 @@ class ScaffoldCmd { const [k, v] = item.split('=') locals[k] = v } + return locals default: throw TypeError(`arguments invalid for config: arg=\`${arg}\`, value=\`${value}\``) } diff --git a/dist/cmd.js b/dist/cmd.js index d9d7033..6dc1459 100755 --- a/dist/cmd.js +++ b/dist/cmd.js @@ -1,3 +1,3 @@ #!/usr/bin/env node -!function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=6)}([function(e,t){e.exports=require("path")},function(e,t,n){"use strict";var o=this&&this.__generator||function(e,t){function n(e){return function(t){return o([e,t])}}function o(n){if(r)throw new TypeError("Generator is already executing.");for(;l;)try{if(r=1,i&&(s=i[2&n[0]?"return":n[0]?"throw":"next"])&&!(s=s.call(i,n[1])).done)return s;switch(i=0,s&&(n=[0,s.value]),n[0]){case 0:case 1:s=n;break;case 4:return l.label++,{value:n[1],done:!1};case 5:l.label++,i=n[1],n=[0];continue;case 7:n=l.ops.pop(),l.trys.pop();continue;default:if(s=l.trys,!(s=s.length>0&&s[s.length-1])&&(6===n[0]||2===n[0])){l=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]=0&&(c=r.slice(0,l-1)),u=0,f=a,o.label=2;case 2:return u=0&&(i=e.slice(r+t.length+1)),n=o+i}return this.parseLocals(n)},e.prototype.writeFile=function(e,t){r.existsSync(i.dirname(e))||r.mkdirSync(i.dirname(e)),console.info("Writing file:",e),r.writeFileSync(e,t,{encoding:"utf-8"})},e.prototype.run=function(){var e=this.fileList(this.config.templates);console.info("Templates input:",e),console.info("Locals:",this.locals);for(var t;t=e.next().value;){var n=t.file,o=t.base,r=this.getOutputPath(n,o),i=this.getFileContents(n),s=this.parseLocals(i);this.writeFile(r,s),console.info("Parsing:",{file:n,base:o,outputPath:r,outputContents:s.replace("\n","\\n")})}},e}();t.default=l},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("glob")},function(e,t){e.exports=require("handlebars")},,function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(1);console.log("wut");var r=process.argv.slice(2);new(function(){function e(){console.log("constructor"),console.log(this.getOptionsFromArgs())}return e.prototype.getOptionsFromArgs=function(){var e=this,t=!1,n={};return r.forEach(function(o,i){if(t)return void(t=!1);if("--"==o.slice(0,2)){t=!0;var s=void 0;s=o.indexOf("=")>=0?o.split("=").slice(1).join(""):r.length>=i+1&&r[i+1]&&"--"!==r[i+1].slice(0,2)?r[i+1]:"true";var a=o.slice(2);n[a]=e.getArgValue(a,s,n)}}),n},e.prototype.getArgValue=function(e,t,n){switch(e){case"template":return(n.templates||[]).concat([t]);case"output":return t;case"locals":for(var o=t.split(","),r=n.locals||{},i=0,s=o;i0&&s[s.length-1])&&(6===n[0]||2===n[0])){l=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]=0&&(c=r.slice(0,l-1)),u=0,f=a,o.label=2;case 2:return u=0&&(i=e.slice(r+t.length+1)),n=o+i}return this.parseLocals(n)},e.prototype.writeFile=function(e,t){r.existsSync(i.dirname(e))||r.mkdirSync(i.dirname(e)),console.info("Writing file:",e),r.writeFileSync(e,t,{encoding:"utf-8"})},e.prototype.run=function(){var e=this.fileList(this.config.templates);console.info("Templates input:",e),console.info("Locals:",this.locals);for(var t;t=e.next().value;){var n=t.file,o=t.base,r=this.getOutputPath(n,o),i=this.getFileContents(n),s=this.parseLocals(i);this.writeFile(r,s),console.info("Parsing:",{file:n,base:o,outputPath:r,outputContents:s.replace("\n","\\n")})}},e}();t.default=l},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("glob")},function(e,t){e.exports=require("handlebars")},,function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(1),r=process.argv.slice(2);new(function(){function e(){console.log(this.getOptionsFromArgs())}return e.prototype.getOptionsFromArgs=function(){var e=this,t=!1,n={};return r.forEach(function(o,i){if(t)return void(t=!1);if("--"==o.slice(0,2)){t=!0;var s=void 0;s=o.indexOf("=")>=0?o.split("=").slice(1).join(""):r.length>=i+1&&r[i+1]&&"--"!==r[i+1].slice(0,2)?r[i+1]:"true";var a=o.slice(2);n[a]=e.getArgValue(a,s,n)}}),n},e.prototype.getArgValue=function(e,t,n){switch(console.log({arg:e}),e){case"template":return(n.templates||[]).concat([t]);case"output":return t;case"locals":for(var o=t.split(","),r=n.locals||{},i=0,s=o;i 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar fs = __webpack_require__(2);\nvar path = __webpack_require__(0);\nvar glob = __webpack_require__(3);\nvar handlebars = __webpack_require__(4);\nvar SimpleScaffold = /** @class */ (function () {\n function SimpleScaffold(config) {\n this.locals = {};\n var DefaultConfig = {\n name: 'scaffold',\n templates: [],\n output: process.cwd(),\n };\n this.config = Object.assign({}, DefaultConfig, config);\n var 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 this.locals = Object.assign({}, DefaultLocals, config.locals);\n // console.info('Config loaded:', this.config)\n }\n SimpleScaffold.prototype.parseLocals = function (text) {\n var template = handlebars.compile(text, {\n noEscape: true\n });\n return template(this.locals);\n };\n SimpleScaffold.prototype.fileList = function (input) {\n var _i, input_1, checkPath, files, idx, cleanCheckPath, _a, files_1, file;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n console.info('input:', input);\n _i = 0, input_1 = input;\n _b.label = 1;\n case 1:\n if (!(_i < input_1.length)) return [3 /*break*/, 6];\n checkPath = input_1[_i];\n files = glob.sync(checkPath).map(function (g) { return path.resolve(g); });\n idx = checkPath.indexOf('*');\n cleanCheckPath = checkPath;\n if (idx >= 0) {\n cleanCheckPath = checkPath.slice(0, idx - 1);\n }\n _a = 0, files_1 = files;\n _b.label = 2;\n case 2:\n if (!(_a < files_1.length)) return [3 /*break*/, 5];\n file = files_1[_a];\n return [4 /*yield*/, { base: cleanCheckPath, file: file }];\n case 3:\n _b.sent();\n _b.label = 4;\n case 4:\n _a++;\n return [3 /*break*/, 2];\n case 5:\n _i++;\n return [3 /*break*/, 1];\n case 6: return [2 /*return*/];\n }\n });\n };\n SimpleScaffold.prototype.getFileContents = function (filePath) {\n return fs.readFileSync(filePath).toString();\n };\n SimpleScaffold.prototype.getOutputPath = function (file, basePath) {\n var out;\n if (typeof this.config.output === 'function') {\n out = this.config.output(file, basePath);\n }\n else {\n var outputDir = this.config.output + (\"/\" + this.config.name + \"/\");\n var idx = file.indexOf(basePath);\n var relativeFilePath = file;\n if (idx >= 0) {\n // console.info('file:', {file, idx, basePath})\n relativeFilePath = file.slice(idx + basePath.length + 1);\n }\n out = outputDir + relativeFilePath;\n }\n return this.parseLocals(out);\n };\n SimpleScaffold.prototype.writeFile = function (filePath, fileContents) {\n if (!fs.existsSync(path.dirname(filePath))) {\n fs.mkdirSync(path.dirname(filePath));\n }\n console.info('Writing file:', filePath);\n fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' });\n };\n SimpleScaffold.prototype.run = function () {\n var templates = this.fileList(this.config.templates);\n console.info('Templates input:', templates);\n console.info('Locals:', this.locals);\n var fileConf;\n while (fileConf = templates.next().value) {\n var file = fileConf.file, base = fileConf.base;\n var outputPath = this.getOutputPath(file, base);\n var contents = this.getFileContents(file);\n var outputContents = this.parseLocals(contents);\n this.writeFile(outputPath, outputContents);\n console.info('Parsing:', { file: file, base: base, outputPath: outputPath, outputContents: outputContents.replace(\"\\n\", \"\\\\n\") });\n }\n };\n return SimpleScaffold;\n}());\nexports.default = SimpleScaffold;\n\n\n/***/ }),\n/* 2 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"fs\");\n\n/***/ }),\n/* 3 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"glob\");\n\n/***/ }),\n/* 4 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"handlebars\");\n\n/***/ }),\n/* 5 */,\n/* 6 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar scaffold_1 = __webpack_require__(1);\nconsole.log('wut');\nvar args = process.argv.slice(2);\nvar ScaffoldCmd = /** @class */ (function () {\n function ScaffoldCmd() {\n console.log('constructor');\n console.log(this.getOptionsFromArgs());\n }\n ScaffoldCmd.prototype.getOptionsFromArgs = function () {\n var _this = this;\n var skipNext = false;\n var options = {};\n args.forEach(function (arg, i) {\n if (skipNext) {\n skipNext = false;\n return;\n }\n if (arg.slice(0, 2) == '--') {\n skipNext = true;\n var value = void 0;\n if (arg.indexOf('=') >= 0) {\n value = arg.split('=').slice(1).join('');\n }\n else if (args.length >= i + 1 && args[i + 1] && args[i + 1].slice(0, 2) !== '--') {\n value = args[i + 1];\n }\n else {\n value = 'true';\n }\n var argName = arg.slice(2);\n options[argName] = _this.getArgValue(argName, value, options);\n }\n });\n return options;\n };\n ScaffoldCmd.prototype.getArgValue = function (arg, value, options) {\n switch (arg) {\n case 'template':\n return (options.templates || []).concat([value]);\n case 'output':\n return value;\n case 'locals':\n var split = value.split(',');\n var locals = options.locals || {};\n for (var _i = 0, split_1 = split; _i < split_1.length; _i++) {\n var item = split_1[_i];\n var _a = item.split('='), k = _a[0], v = _a[1];\n locals[k] = v;\n }\n default:\n throw TypeError(\"arguments invalid for config: arg=`\" + arg + \"`, value=`\" + value + \"`\");\n }\n };\n ScaffoldCmd.prototype.run = function (config) {\n var scf = new scaffold_1.default({\n templates: config.templates,\n output: config.output,\n locals: config.locals,\n }).run();\n };\n return ScaffoldCmd;\n}());\nnew ScaffoldCmd();\nconsole.log('started');\n\n\n/***/ })\n/******/ ]);\n\n\n// WEBPACK FOOTER //\n// cmd.js"," \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, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\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 \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 6);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap ca56a8b8c9b0e51d2e17","module.exports = require(\"path\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"path\"\n// module id = 0\n// module chunks = 0 1 2","import * as fs from 'fs'\nimport * as path from 'path'\nimport IScaffold from './index'\nimport * as glob from 'glob'\nimport * as handlebars from 'handlebars'\n\nclass SimpleScaffold {\n private config: IScaffold.IConfig\n private locals = {} as any\n\n constructor(config: IScaffold.IConfig) {\n const DefaultConfig: IScaffold.IConfig = {\n name: 'scaffold',\n templates: [],\n output: process.cwd(),\n }\n\n this.config = (Object as any).assign({}, 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 = (Object as any).assign({}, DefaultLocals, config.locals)\n\n // console.info('Config loaded:', this.config)\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[]): IterableIterator {\n console.info('input:', input)\n for (const checkPath of input) {\n const files = glob.sync(checkPath).map(g => path.resolve(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 yield {base: cleanCheckPath, file}\n }\n }\n }\n\n private getFileContents(filePath: string): string {\n return fs.readFileSync(filePath).toString()\n }\n\n private getOutputPath(file: string, basePath: string): string {\n let out\n\n if (typeof this.config.output === 'function') {\n out = this.config.output(file, basePath)\n } else {\n const outputDir = this.config.output + `/${this.config.name}/`\n const idx = file.indexOf(basePath)\n let relativeFilePath = file\n if (idx >= 0) {\n // console.info('file:', {file, idx, basePath})\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 if (!fs.existsSync(path.dirname(filePath))) {\n fs.mkdirSync(path.dirname(filePath))\n }\n console.info('Writing file:', filePath)\n fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' })\n }\n\n public run(): void {\n const templates = this.fileList(this.config.templates)\n\n console.info('Templates input:', templates)\n console.info('Locals:', this.locals)\n\n let fileConf\n while (fileConf = templates.next().value) {\n const {file, base} = fileConf\n const outputPath = this.getOutputPath(file, base)\n const contents = this.getFileContents(file)\n const outputContents = this.parseLocals(contents)\n\n this.writeFile(outputPath, outputContents)\n console.info('Parsing:', {file, base, outputPath, outputContents: outputContents.replace(\"\\n\", \"\\\\n\")})\n }\n }\n}\n\nexport default SimpleScaffold\n\n\n\n// WEBPACK FOOTER //\n// ./scaffold.ts","module.exports = require(\"fs\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"fs\"\n// module id = 2\n// module chunks = 0 1 2","module.exports = require(\"glob\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"glob\"\n// module id = 3\n// module chunks = 0 1 2","module.exports = require(\"handlebars\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"handlebars\"\n// module id = 4\n// module chunks = 0 1 2","import Scaffolder from './scaffold'\nimport * as fs from 'fs'\nimport IScaffold from './index'\n\nconsole.log('wut')\nconst args = process.argv.slice(2)\n\nclass ScaffoldCmd {\n constructor() {\n console.log('constructor')\n console.log(this.getOptionsFromArgs())\n }\n\n private getOptionsFromArgs() {\n let skipNext = false\n const options = {} as any\n\n args.forEach((arg, i) => {\n if (skipNext) {\n skipNext = false\n return\n }\n\n if (arg.slice(0, 2) == '--') {\n skipNext = true\n let value: string\n\n if (arg.indexOf('=') >= 0) {\n value = arg.split('=').slice(1).join('')\n } else if (args.length >= i + 1 && args[i + 1] && args[i + 1].slice(0, 2) !== '--') {\n value = args[i + 1]\n } else {\n value = 'true'\n }\n\n const argName = arg.slice(2)\n options[argName] = this.getArgValue(argName, value, options)\n }\n })\n\n return options\n }\n\n private getArgValue(arg: string, value: string, options: IScaffold.IConfig) {\n switch (arg) {\n case 'template':\n return (options.templates || []).concat([value])\n case 'output':\n return value\n case 'locals':\n const split = value.split(',')\n const locals = options.locals || {}\n for (const item of split) {\n const [k, v] = item.split('=')\n locals[k] = v\n }\n default:\n throw TypeError(`arguments invalid for config: arg=\\`${arg}\\`, value=\\`${value}\\``)\n }\n }\n\n private run(config: IScaffold.IConfig) {\n const scf = new Scaffolder({\n templates: config.templates,\n output: config.output,\n locals: config.locals,\n }).run()\n }\n}\n\nnew ScaffoldCmd()\nconsole.log('started')\n\n\n\n// WEBPACK FOOTER //\n// ./cmd.ts"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack/universalModuleDefinition","cmd.js","webpack/bootstrap 455e10927aab1ecbd951","external \"path\"","/Users/chenasraf/Dev/simple-scaffold/scaffold.ts","external \"fs\"","external \"glob\"","external \"handlebars\"","/Users/chenasraf/Dev/simple-scaffold/cmd.ts"],"names":["root","factory","exports","module","define","amd","this","modules","__webpack_require__","moduleId","installedModules","i","l","call","m","c","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","require","__generator","thisArg","body","verb","v","step","op","f","TypeError","_","y","t","done","value","label","ops","pop","trys","length","push","e","g","sent","next","throw","return","Symbol","iterator","fs","path","glob","handlebars","SimpleScaffold","config","locals","DefaultConfig","templates","output","process","cwd","assign","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","text","compile","noEscape","fileList","input","_i","input_1","checkPath","files","idx","cleanCheckPath","_a","files_1","file","_b","console","info","sync","map","resolve","indexOf","base","getFileContents","filePath","readFileSync","toString","getOutputPath","basePath","out","outputDir","relativeFilePath","writeFile","fileContents","existsSync","dirname","mkdirSync","writeFileSync","encoding","run","fileConf","outputPath","contents","outputContents","replace","default","scaffold_1","args","argv","ScaffoldCmd","log","getOptionsFromArgs","_this","skipNext","options","forEach","arg","split","join","argName","getArgValue","concat","split_1","item","k"],"mappings":";CAAA,SAAAA,EAAAC,GACA,gBAAAC,UAAA,gBAAAC,QACAA,OAAAD,QAAAD,IACA,kBAAAG,gBAAAC,IACAD,UAAAH,GACA,gBAAAC,SACAA,QAAA,QAAAD,IAEAD,EAAA,QAAAC,KACCK,KAAA,WACD,MCCgB,UAAUC,GCP1B,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAP,OAGA,IAAAC,GAAAO,EAAAD,IACAE,EAAAF,EACAG,GAAA,EACAV,WAUA,OANAK,GAAAE,GAAAI,KAAAV,EAAAD,QAAAC,IAAAD,QAAAM,GAGAL,EAAAS,GAAA,EAGAT,EAAAD,QAvBA,GAAAQ,KA4DA,OAhCAF,GAAAM,EAAAP,EAGAC,EAAAO,EAAAL,EAGAF,EAAAQ,EAAA,SAAAd,EAAAe,EAAAC,GACAV,EAAAW,EAAAjB,EAAAe,IACAG,OAAAC,eAAAnB,EAAAe,GACAK,cAAA,EACAC,YAAA,EAC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GACPM,EAAAmD,EAAAN,MAAA,KAACO,EAAApD,EAAA,GAAGtD,EAAAsD,EAAA,EACVxB,GAAO4E,GAAK1G,EAEd,MAAO8B,EACT,SACE,KAAM1B,WAAU,sCAAuC8F,EAAG,aAAezF,EAAK,OAI5EkF,EAAApG,UAAA0F,IAAR,SAAYpD,GACE,GAAI2D,GAAAD,SACdvD,UAAWH,EAAOG,UAClBC,OAAQJ,EAAOI,OACfH,OAAQD,EAAOC,SACdmD,OAEPU","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})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition","#!/usr/bin/env node\n(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})(this, function() {\nreturn /******/ (function(modules) { // webpackBootstrap\n/******/ \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, {\n/******/ \t\t\t\tconfigurable: false,\n/******/ \t\t\t\tenumerable: true,\n/******/ \t\t\t\tget: getter\n/******/ \t\t\t});\n/******/ \t\t}\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/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = 6);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"path\");\n\n/***/ }),\n/* 1 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar fs = __webpack_require__(2);\nvar path = __webpack_require__(0);\nvar glob = __webpack_require__(3);\nvar handlebars = __webpack_require__(4);\nvar SimpleScaffold = /** @class */ (function () {\n function SimpleScaffold(config) {\n this.locals = {};\n var DefaultConfig = {\n name: 'scaffold',\n templates: [],\n output: process.cwd(),\n };\n this.config = Object.assign({}, DefaultConfig, config);\n var 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 this.locals = Object.assign({}, DefaultLocals, config.locals);\n // console.info('Config loaded:', this.config)\n }\n SimpleScaffold.prototype.parseLocals = function (text) {\n var template = handlebars.compile(text, {\n noEscape: true\n });\n return template(this.locals);\n };\n SimpleScaffold.prototype.fileList = function (input) {\n var _i, input_1, checkPath, files, idx, cleanCheckPath, _a, files_1, file;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n console.info('input:', input);\n _i = 0, input_1 = input;\n _b.label = 1;\n case 1:\n if (!(_i < input_1.length)) return [3 /*break*/, 6];\n checkPath = input_1[_i];\n files = glob.sync(checkPath).map(function (g) { return path.resolve(g); });\n idx = checkPath.indexOf('*');\n cleanCheckPath = checkPath;\n if (idx >= 0) {\n cleanCheckPath = checkPath.slice(0, idx - 1);\n }\n _a = 0, files_1 = files;\n _b.label = 2;\n case 2:\n if (!(_a < files_1.length)) return [3 /*break*/, 5];\n file = files_1[_a];\n return [4 /*yield*/, { base: cleanCheckPath, file: file }];\n case 3:\n _b.sent();\n _b.label = 4;\n case 4:\n _a++;\n return [3 /*break*/, 2];\n case 5:\n _i++;\n return [3 /*break*/, 1];\n case 6: return [2 /*return*/];\n }\n });\n };\n SimpleScaffold.prototype.getFileContents = function (filePath) {\n return fs.readFileSync(filePath).toString();\n };\n SimpleScaffold.prototype.getOutputPath = function (file, basePath) {\n var out;\n if (typeof this.config.output === 'function') {\n out = this.config.output(file, basePath);\n }\n else {\n var outputDir = this.config.output + (\"/\" + this.config.name + \"/\");\n var idx = file.indexOf(basePath);\n var relativeFilePath = file;\n if (idx >= 0) {\n // console.info('file:', {file, idx, basePath})\n relativeFilePath = file.slice(idx + basePath.length + 1);\n }\n out = outputDir + relativeFilePath;\n }\n return this.parseLocals(out);\n };\n SimpleScaffold.prototype.writeFile = function (filePath, fileContents) {\n if (!fs.existsSync(path.dirname(filePath))) {\n fs.mkdirSync(path.dirname(filePath));\n }\n console.info('Writing file:', filePath);\n fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' });\n };\n SimpleScaffold.prototype.run = function () {\n var templates = this.fileList(this.config.templates);\n console.info('Templates input:', templates);\n console.info('Locals:', this.locals);\n var fileConf;\n while (fileConf = templates.next().value) {\n var file = fileConf.file, base = fileConf.base;\n var outputPath = this.getOutputPath(file, base);\n var contents = this.getFileContents(file);\n var outputContents = this.parseLocals(contents);\n this.writeFile(outputPath, outputContents);\n console.info('Parsing:', { file: file, base: base, outputPath: outputPath, outputContents: outputContents.replace(\"\\n\", \"\\\\n\") });\n }\n };\n return SimpleScaffold;\n}());\nexports.default = SimpleScaffold;\n\n\n/***/ }),\n/* 2 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"fs\");\n\n/***/ }),\n/* 3 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"glob\");\n\n/***/ }),\n/* 4 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"handlebars\");\n\n/***/ }),\n/* 5 */,\n/* 6 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar scaffold_1 = __webpack_require__(1);\nvar args = process.argv.slice(2);\nvar ScaffoldCmd = /** @class */ (function () {\n function ScaffoldCmd() {\n console.log(this.getOptionsFromArgs());\n }\n ScaffoldCmd.prototype.getOptionsFromArgs = function () {\n var _this = this;\n var skipNext = false;\n var options = {};\n args.forEach(function (arg, i) {\n if (skipNext) {\n skipNext = false;\n return;\n }\n if (arg.slice(0, 2) == '--') {\n skipNext = true;\n var value = void 0;\n if (arg.indexOf('=') >= 0) {\n value = arg.split('=').slice(1).join('');\n }\n else if (args.length >= i + 1 && args[i + 1] && args[i + 1].slice(0, 2) !== '--') {\n value = args[i + 1];\n }\n else {\n value = 'true';\n }\n var argName = arg.slice(2);\n options[argName] = _this.getArgValue(argName, value, options);\n }\n });\n return options;\n };\n ScaffoldCmd.prototype.getArgValue = function (arg, value, options) {\n console.log({ arg: arg });\n switch (arg) {\n case 'template':\n return (options.templates || []).concat([value]);\n case 'output':\n return value;\n case 'locals':\n var split = value.split(',');\n var locals = options.locals || {};\n for (var _i = 0, split_1 = split; _i < split_1.length; _i++) {\n var item = split_1[_i];\n var _a = item.split('='), k = _a[0], v = _a[1];\n locals[k] = v;\n }\n return locals;\n default:\n throw TypeError(\"arguments invalid for config: arg=`\" + arg + \"`, value=`\" + value + \"`\");\n }\n };\n ScaffoldCmd.prototype.run = function (config) {\n var scf = new scaffold_1.default({\n templates: config.templates,\n output: config.output,\n locals: config.locals,\n }).run();\n };\n return ScaffoldCmd;\n}());\nnew ScaffoldCmd();\n\n\n/***/ })\n/******/ ]);\n});\n\n\n// WEBPACK FOOTER //\n// cmd.js"," \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, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\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 \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 6);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 455e10927aab1ecbd951","module.exports = require(\"path\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"path\"\n// module id = 0\n// module chunks = 0 1 2","import * as fs from 'fs'\nimport * as path from 'path'\nimport IScaffold from './index'\nimport * as glob from 'glob'\nimport * as handlebars from 'handlebars'\n\nclass SimpleScaffold {\n private config: IScaffold.IConfig\n private locals = {} as any\n\n constructor(config: IScaffold.IConfig) {\n const DefaultConfig: IScaffold.IConfig = {\n name: 'scaffold',\n templates: [],\n output: process.cwd(),\n }\n\n this.config = (Object as any).assign({}, 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 = (Object as any).assign({}, DefaultLocals, config.locals)\n\n // console.info('Config loaded:', this.config)\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[]): IterableIterator {\n console.info('input:', input)\n for (const checkPath of input) {\n const files = glob.sync(checkPath).map(g => path.resolve(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 yield {base: cleanCheckPath, file}\n }\n }\n }\n\n private getFileContents(filePath: string): string {\n return fs.readFileSync(filePath).toString()\n }\n\n private getOutputPath(file: string, basePath: string): string {\n let out\n\n if (typeof this.config.output === 'function') {\n out = this.config.output(file, basePath)\n } else {\n const outputDir = this.config.output + `/${this.config.name}/`\n const idx = file.indexOf(basePath)\n let relativeFilePath = file\n if (idx >= 0) {\n // console.info('file:', {file, idx, basePath})\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 if (!fs.existsSync(path.dirname(filePath))) {\n fs.mkdirSync(path.dirname(filePath))\n }\n console.info('Writing file:', filePath)\n fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' })\n }\n\n public run(): void {\n const templates = this.fileList(this.config.templates)\n\n console.info('Templates input:', templates)\n console.info('Locals:', this.locals)\n\n let fileConf\n while (fileConf = templates.next().value) {\n const {file, base} = fileConf\n const outputPath = this.getOutputPath(file, base)\n const contents = this.getFileContents(file)\n const outputContents = this.parseLocals(contents)\n\n this.writeFile(outputPath, outputContents)\n console.info('Parsing:', {file, base, outputPath, outputContents: outputContents.replace(\"\\n\", \"\\\\n\")})\n }\n }\n}\n\nexport default SimpleScaffold\n\n\n\n// WEBPACK FOOTER //\n// ./scaffold.ts","module.exports = require(\"fs\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"fs\"\n// module id = 2\n// module chunks = 0 1 2","module.exports = require(\"glob\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"glob\"\n// module id = 3\n// module chunks = 0 1 2","module.exports = require(\"handlebars\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"handlebars\"\n// module id = 4\n// module chunks = 0 1 2","import Scaffolder from './scaffold'\nimport * as fs from 'fs'\nimport IScaffold from './index'\n\nconst args = process.argv.slice(2)\n\nclass ScaffoldCmd {\n constructor() {\n console.log(this.getOptionsFromArgs())\n }\n\n private getOptionsFromArgs() {\n let skipNext = false\n const options = {} as any\n\n args.forEach((arg, i) => {\n if (skipNext) {\n skipNext = false\n return\n }\n\n if (arg.slice(0, 2) == '--') {\n skipNext = true\n let value: string\n\n if (arg.indexOf('=') >= 0) {\n value = arg.split('=').slice(1).join('')\n } else if (args.length >= i + 1 && args[i + 1] && args[i + 1].slice(0, 2) !== '--') {\n value = args[i + 1]\n } else {\n value = 'true'\n }\n\n const argName = arg.slice(2)\n options[argName] = this.getArgValue(argName, value, options)\n }\n })\n\n return options\n }\n\n private getArgValue(arg: string, value: string, options: IScaffold.IConfig) {\n console.log({arg})\n switch (arg) {\n case 'template':\n return (options.templates || []).concat([value])\n case 'output':\n return value\n case 'locals':\n const split = value.split(',')\n const locals = options.locals || {}\n for (const item of split) {\n const [k, v] = item.split('=')\n locals[k] = v\n }\n return locals\n default:\n throw TypeError(`arguments invalid for config: arg=\\`${arg}\\`, value=\\`${value}\\``)\n }\n }\n\n private run(config: IScaffold.IConfig) {\n const scf = new Scaffolder({\n templates: config.templates,\n output: config.output,\n locals: config.locals,\n }).run()\n }\n}\n\nnew ScaffoldCmd()\n\n\n\n// WEBPACK FOOTER //\n// ./cmd.ts"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/scaffold.js b/dist/scaffold.js index 4adbd35..984d9a6 100755 --- a/dist/scaffold.js +++ b/dist/scaffold.js @@ -1,2 +1,2 @@ -!function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t){e.exports=require("path")},function(e,t,n){"use strict";var r=this&&this.__generator||function(e,t){function n(e){return function(t){return r([e,t])}}function r(n){if(o)throw new TypeError("Generator is already executing.");for(;c;)try{if(o=1,i&&(s=i[2&n[0]?"return":n[0]?"throw":"next"])&&!(s=s.call(i,n[1])).done)return s;switch(i=0,s&&(n=[0,s.value]),n[0]){case 0:case 1:s=n;break;case 4:return c.label++,{value:n[1],done:!1};case 5:c.label++,i=n[1],n=[0];continue;case 7:n=c.ops.pop(),c.trys.pop();continue;default:if(s=c.trys,!(s=s.length>0&&s[s.length-1])&&(6===n[0]||2===n[0])){c=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]=0&&(l=o.slice(0,c-1)),u=0,f=a,r.label=2;case 2:return u=0&&(i=e.slice(o+t.length+1)),n=r+i}return this.parseLocals(n)},e.prototype.writeFile=function(e,t){o.existsSync(i.dirname(e))||o.mkdirSync(i.dirname(e)),console.info("Writing file:",e),o.writeFileSync(e,t,{encoding:"utf-8"})},e.prototype.run=function(){var e=this.fileList(this.config.templates);console.info("Templates input:",e),console.info("Locals:",this.locals);for(var t;t=e.next().value;){var n=t.file,r=t.base,o=this.getOutputPath(n,r),i=this.getFileContents(n),s=this.parseLocals(i);this.writeFile(o,s),console.info("Parsing:",{file:n,base:r,outputPath:o,outputContents:s.replace("\n","\\n")})}},e}();t.default=c},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("glob")},function(e,t){e.exports=require("handlebars")}]); +!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()}(this,function(){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t){e.exports=require("path")},function(e,t,n){"use strict";var o=this&&this.__generator||function(e,t){function n(e){return function(t){return o([e,t])}}function o(n){if(r)throw new TypeError("Generator is already executing.");for(;c;)try{if(r=1,i&&(s=i[2&n[0]?"return":n[0]?"throw":"next"])&&!(s=s.call(i,n[1])).done)return s;switch(i=0,s&&(n=[0,s.value]),n[0]){case 0:case 1:s=n;break;case 4:return c.label++,{value:n[1],done:!1};case 5:c.label++,i=n[1],n=[0];continue;case 7:n=c.ops.pop(),c.trys.pop();continue;default:if(s=c.trys,!(s=s.length>0&&s[s.length-1])&&(6===n[0]||2===n[0])){c=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]=0&&(u=r.slice(0,c-1)),l=0,f=a,o.label=2;case 2:return l=0&&(i=e.slice(r+t.length+1)),n=o+i}return this.parseLocals(n)},e.prototype.writeFile=function(e,t){r.existsSync(i.dirname(e))||r.mkdirSync(i.dirname(e)),console.info("Writing file:",e),r.writeFileSync(e,t,{encoding:"utf-8"})},e.prototype.run=function(){var e=this.fileList(this.config.templates);console.info("Templates input:",e),console.info("Locals:",this.locals);for(var t;t=e.next().value;){var n=t.file,o=t.base,r=this.getOutputPath(n,o),i=this.getFileContents(n),s=this.parseLocals(i);this.writeFile(r,s),console.info("Parsing:",{file:n,base:o,outputPath:r,outputContents:s.replace("\n","\\n")})}},e}();t.default=c},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("glob")},function(e,t){e.exports=require("handlebars")}])}); //# sourceMappingURL=scaffold.js.map \ No newline at end of file diff --git a/dist/scaffold.js.map b/dist/scaffold.js.map index 51b2a7a..043d913 100755 --- a/dist/scaffold.js.map +++ b/dist/scaffold.js.map @@ -1 +1 @@ -{"version":3,"sources":["scaffold.js","webpack/bootstrap ca56a8b8c9b0e51d2e17","external \"path\"","/Users/chenasraf/Dev/simple-scaffold/scaffold.ts","external \"fs\"","external \"glob\"","external \"handlebars\""],"names":["modules","__webpack_require__","moduleId","installedModules","exports","module","i","l","call","m","c","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","require","__generator","this","thisArg","body","verb","v","step","op","f","TypeError","_","y","t","done","value","label","ops","pop","trys","length","push","e","g","sent","next","throw","return","Symbol","iterator","fs","path","glob","handlebars","SimpleScaffold","config","locals","DefaultConfig","templates","output","process","cwd","assign","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","text","compile","noEscape","fileList","input","_i","input_1","checkPath","files","idx","cleanCheckPath","_a","files_1","file","_b","console","info","sync","map","resolve","indexOf","base","getFileContents","filePath","readFileSync","toString","getOutputPath","basePath","out","outputDir","relativeFilePath","writeFile","fileContents","existsSync","dirname","mkdirSync","writeFileSync","encoding","run","fileConf","outputPath","contents","outputContents","replace","default"],"mappings":"CAAS,SAAUA,GCInB,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAE,OAGA,IAAAC,GAAAF,EAAAD,IACAI,EAAAJ,EACAK,GAAA,EACAH,WAUA,OANAJ,GAAAE,GAAAM,KAAAH,EAAAD,QAAAC,IAAAD,QAAAH,GAGAI,EAAAE,GAAA,EAGAF,EAAAD,QAvBA,GAAAD,KA4BAF,GAAAQ,EAAAT,EAGAC,EAAAS,EAAAP,EAGAF,EAAAU,EAAA,SAAAP,EAAAQ,EAAAC,GACAZ,EAAAa,EAAAV,EAAAQ,IACAG,OAAAC,eAAAZ,EAAAQ,GACAK,cAAA,EACAC,YAAA,EACAC,IAAAN,KAMAZ,EAAAmB,EAAA,SAAAf,GACA,GAAAQ,GAAAR,KAAAgB,WACA,WAA2B,MAAAhB,GAAA,SAC3B,WAAiC,MAAAA,GAEjC,OADAJ,GAAAU,EAAAE,EAAA,IAAAA,GACAA,GAIAZ,EAAAa,EAAA,SAAAQ,EAAAC,GAAsD,MAAAR,QAAAS,UAAAC,eAAAjB,KAAAc,EAAAC,IAGtDtB,EAAAyB,EAAA,GAGAzB,IAAA0B,EAAA,KDMM,SAAUtB,EAAQD,GEnExBC,EAAAD,QAAAwB,QAAA,SFyEM,SAAUvB,EAAQD,EAASH,GAEjC,YAEA,IAAI4B,GAAeC,MAAQA,KAAKD,aAAgB,SAAUE,EAASC,GAG/D,QAASC,GAAKb,GAAK,MAAO,UAAUc,GAAK,MAAOC,IAAMf,EAAGc,KACzD,QAASC,GAAKC,GACV,GAAIC,EAAG,KAAM,IAAIC,WAAU,kCAC3B,MAAOC,GAAG,IACN,GAAI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uD,cAAcb,EAAUS,GAAgBK,SAAU,WAGhDpD,EAAAtC,UAAA2F,IAAP,WACE,GAAMjD,GAAYpC,KAAKkD,SAASlD,KAAKiC,OAAOG,UAE5C0B,SAAQC,KAAK,mBAAoB3B,GACjC0B,QAAQC,KAAK,UAAW/D,KAAKkC,OAG7B,KADA,GAAIoD,GACGA,EAAWlD,EAAUb,OAAOV,OAAO,CACjC,GAAA+C,GAAA0B,EAAA1B,KAAMQ,EAAAkB,EAAAlB,KACPmB,EAAavF,KAAKyE,cAAcb,EAAMQ,GACtCoB,EAAWxF,KAAKqE,gBAAgBT,GAChC6B,EAAiBzF,KAAK8C,YAAY0C,EAExCxF,MAAK8E,UAAUS,EAAYE,GAC3B3B,QAAQC,KAAK,YAAaH,KAAIA,EAAEQ,KAAIA,EAAEmB,WAAUA,EAAEE,eAAgBA,EAAeC,QAAQ,KAAM,WAGrG1D,IAEA1D,GAAAqH,QAAe3D,GHkHT,SAAUzD,EAAQD,GIvNxBC,EAAAD,QAAAwB,QAAA,OJ6NM,SAAUvB,EAAQD,GK7NxBC,EAAAD,QAAAwB,QAAA,SLmOM,SAAUvB,EAAQD,GMnOxBC,EAAAD,QAAAwB,QAAA","file":"scaffold.js","sourcesContent":["/******/ (function(modules) { // webpackBootstrap\n/******/ \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, {\n/******/ \t\t\t\tconfigurable: false,\n/******/ \t\t\t\tenumerable: true,\n/******/ \t\t\t\tget: getter\n/******/ \t\t\t});\n/******/ \t\t}\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/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = 1);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"path\");\n\n/***/ }),\n/* 1 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar fs = __webpack_require__(2);\nvar path = __webpack_require__(0);\nvar glob = __webpack_require__(3);\nvar handlebars = __webpack_require__(4);\nvar SimpleScaffold = /** @class */ (function () {\n function SimpleScaffold(config) {\n this.locals = {};\n var DefaultConfig = {\n name: 'scaffold',\n templates: [],\n output: process.cwd(),\n };\n this.config = Object.assign({}, DefaultConfig, config);\n var 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 this.locals = Object.assign({}, DefaultLocals, config.locals);\n // console.info('Config loaded:', this.config)\n }\n SimpleScaffold.prototype.parseLocals = function (text) {\n var template = handlebars.compile(text, {\n noEscape: true\n });\n return template(this.locals);\n };\n SimpleScaffold.prototype.fileList = function (input) {\n var _i, input_1, checkPath, files, idx, cleanCheckPath, _a, files_1, file;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n console.info('input:', input);\n _i = 0, input_1 = input;\n _b.label = 1;\n case 1:\n if (!(_i < input_1.length)) return [3 /*break*/, 6];\n checkPath = input_1[_i];\n files = glob.sync(checkPath).map(function (g) { return path.resolve(g); });\n idx = checkPath.indexOf('*');\n cleanCheckPath = checkPath;\n if (idx >= 0) {\n cleanCheckPath = checkPath.slice(0, idx - 1);\n }\n _a = 0, files_1 = files;\n _b.label = 2;\n case 2:\n if (!(_a < files_1.length)) return [3 /*break*/, 5];\n file = files_1[_a];\n return [4 /*yield*/, { base: cleanCheckPath, file: file }];\n case 3:\n _b.sent();\n _b.label = 4;\n case 4:\n _a++;\n return [3 /*break*/, 2];\n case 5:\n _i++;\n return [3 /*break*/, 1];\n case 6: return [2 /*return*/];\n }\n });\n };\n SimpleScaffold.prototype.getFileContents = function (filePath) {\n return fs.readFileSync(filePath).toString();\n };\n SimpleScaffold.prototype.getOutputPath = function (file, basePath) {\n var out;\n if (typeof this.config.output === 'function') {\n out = this.config.output(file, basePath);\n }\n else {\n var outputDir = this.config.output + (\"/\" + this.config.name + \"/\");\n var idx = file.indexOf(basePath);\n var relativeFilePath = file;\n if (idx >= 0) {\n // console.info('file:', {file, idx, basePath})\n relativeFilePath = file.slice(idx + basePath.length + 1);\n }\n out = outputDir + relativeFilePath;\n }\n return this.parseLocals(out);\n };\n SimpleScaffold.prototype.writeFile = function (filePath, fileContents) {\n if (!fs.existsSync(path.dirname(filePath))) {\n fs.mkdirSync(path.dirname(filePath));\n }\n console.info('Writing file:', filePath);\n fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' });\n };\n SimpleScaffold.prototype.run = function () {\n var templates = this.fileList(this.config.templates);\n console.info('Templates input:', templates);\n console.info('Locals:', this.locals);\n var fileConf;\n while (fileConf = templates.next().value) {\n var file = fileConf.file, base = fileConf.base;\n var outputPath = this.getOutputPath(file, base);\n var contents = this.getFileContents(file);\n var outputContents = this.parseLocals(contents);\n this.writeFile(outputPath, outputContents);\n console.info('Parsing:', { file: file, base: base, outputPath: outputPath, outputContents: outputContents.replace(\"\\n\", \"\\\\n\") });\n }\n };\n return SimpleScaffold;\n}());\nexports.default = SimpleScaffold;\n\n\n/***/ }),\n/* 2 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"fs\");\n\n/***/ }),\n/* 3 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"glob\");\n\n/***/ }),\n/* 4 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"handlebars\");\n\n/***/ })\n/******/ ]);\n\n\n// WEBPACK FOOTER //\n// scaffold.js"," \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, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\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 \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap ca56a8b8c9b0e51d2e17","module.exports = require(\"path\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"path\"\n// module id = 0\n// module chunks = 0 1 2","import * as fs from 'fs'\nimport * as path from 'path'\nimport IScaffold from './index'\nimport * as glob from 'glob'\nimport * as handlebars from 'handlebars'\n\nclass SimpleScaffold {\n private config: IScaffold.IConfig\n private locals = {} as any\n\n constructor(config: IScaffold.IConfig) {\n const DefaultConfig: IScaffold.IConfig = {\n name: 'scaffold',\n templates: [],\n output: process.cwd(),\n }\n\n this.config = (Object as any).assign({}, 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 = (Object as any).assign({}, DefaultLocals, config.locals)\n\n // console.info('Config loaded:', this.config)\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[]): IterableIterator {\n console.info('input:', input)\n for (const checkPath of input) {\n const files = glob.sync(checkPath).map(g => path.resolve(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 yield {base: cleanCheckPath, file}\n }\n }\n }\n\n private getFileContents(filePath: string): string {\n return fs.readFileSync(filePath).toString()\n }\n\n private getOutputPath(file: string, basePath: string): string {\n let out\n\n if (typeof this.config.output === 'function') {\n out = this.config.output(file, basePath)\n } else {\n const outputDir = this.config.output + `/${this.config.name}/`\n const idx = file.indexOf(basePath)\n let relativeFilePath = file\n if (idx >= 0) {\n // console.info('file:', {file, idx, basePath})\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 if (!fs.existsSync(path.dirname(filePath))) {\n fs.mkdirSync(path.dirname(filePath))\n }\n console.info('Writing file:', filePath)\n fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' })\n }\n\n public run(): void {\n const templates = this.fileList(this.config.templates)\n\n console.info('Templates input:', templates)\n console.info('Locals:', this.locals)\n\n let fileConf\n while (fileConf = templates.next().value) {\n const {file, base} = fileConf\n const outputPath = this.getOutputPath(file, base)\n const contents = this.getFileContents(file)\n const outputContents = this.parseLocals(contents)\n\n this.writeFile(outputPath, outputContents)\n console.info('Parsing:', {file, base, outputPath, outputContents: outputContents.replace(\"\\n\", \"\\\\n\")})\n }\n }\n}\n\nexport default SimpleScaffold\n\n\n\n// WEBPACK FOOTER //\n// ./scaffold.ts","module.exports = require(\"fs\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"fs\"\n// module id = 2\n// module chunks = 0 1 2","module.exports = require(\"glob\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"glob\"\n// module id = 3\n// module chunks = 0 1 2","module.exports = require(\"handlebars\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"handlebars\"\n// module id = 4\n// module chunks = 0 1 2"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack/universalModuleDefinition","scaffold.js","webpack/bootstrap 455e10927aab1ecbd951","external \"path\"","/Users/chenasraf/Dev/simple-scaffold/scaffold.ts","external \"fs\"","external \"glob\"","external \"handlebars\""],"names":["root","factory","exports","module","define","amd","this","modules","__webpack_require__","moduleId","installedModules","i","l","call","m","c","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","require","__generator","thisArg","body","verb","v","step","op","f","TypeError","_","y","t","done","value","label","ops","pop","trys","length","push","e","g","sent","next","throw","return","Symbol","iterator","fs","path","glob","handlebars","SimpleScaffold","config","locals","DefaultConfig","templates","output","process","cwd","assign","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","text","compile","noEscape","fileList","input","_i","input_1","checkPath","files","idx","cleanCheckPath","_a","files_1","file","_b","console","info","sync","map","resolve","indexOf","base","getFileContents","filePath","readFileSync","toString","getOutputPath","basePath","out","outputDir","relativeFilePath","writeFile","fileContents","existsSync","dirname","mkdirSync","writeFileSync","encoding","run","fileConf","outputPath","contents","outputContents","replace","default"],"mappings":"CAAA,SAAAA,EAAAC,GACA,gBAAAC,UAAA,gBAAAC,QACAA,OAAAD,QAAAD,IACA,kBAAAG,gBAAAC,IACAD,UAAAH,GACA,gBAAAC,SACAA,QAAA,QAAAD,IAEAD,EAAA,QAAAC,KACCK,KAAA,WACD,MCAgB,UAAUC,GCN1B,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAP,OAGA,IAAAC,GAAAO,EAAAD,IACAE,EAAAF,EACAG,GAAA,EACAV,WAUA,OANAK,GAAAE,GAAAI,KAAAV,EAAAD,QAAAC,IAAAD,QAAAM,GAGAL,EAAAS,GAAA,EAGAT,EAAAD,QAvBA,GAAAQ,KA4DA,OAhCAF,GAAAM,EAAAP,EAGAC,EAAAO,EAAAL,EAGAF,EAAAQ,EAAA,SAAAd,EAAAe,EAAAC,GACAV,EAAAW,EAAAjB,EAAAe,IACAG,OAAAC,eAAAnB,EAAAe,GACAK,cAAA,EACAC,YAAA,EACAC,IAAAN,KAMAV,EAAAiB,EAAA,SAAAtB,GACA,GAAAe,GAAAf,KAAAuB,WACA,WAA2B,MAAAvB,GAAA,SAC3B,WAAiC,MAAAA,GAEjC,OADAK,GAAAQ,EAAAE,EAAA,IAAAA,GACAA,GAIAV,EAAAW,EAAA,SAAAQ,E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AK6D,OAAOI,OAAS,IAAIjE,KAAK6D,OAAOlD,KAAI,IACrDyE,EAAMI,EAAKO,QAAQO,GACrBG,EAAmBjB,CACnBJ,IAAO,IAETqB,EAAmBjB,EAAKhB,MAAMY,EAAMkB,EAASxD,OAAS,IAExDyD,EAAMC,EAAYC,EAGpB,MAAOzG,MAAK0E,YAAY6B,IAGlB3C,EAAArC,UAAAmF,UAAR,SAAkBR,EAAkBS,GAC7BnD,EAAGoD,WAAWnD,EAAKoD,QAAQX,KAC9B1C,EAAGsD,UAAUrD,EAAKoD,QAAQX,IAE5BR,QAAQC,KAAK,gBAAiBO,GAC9B1C,EAAGuD,cAAcb,EAAUS,GAAgBK,SAAU,WAGhDpD,EAAArC,UAAA0F,IAAP,WACE,GAAMjD,GAAYhE,KAAK8E,SAAS9E,KAAK6D,OAAOG,UAE5C0B,SAAQC,KAAK,mBAAoB3B,GACjC0B,QAAQC,KAAK,UAAW3F,KAAK8D,OAG7B,KADA,GAAIoD,GACGA,EAAWlD,EAAUb,OAAOV,OAAO,CACjC,GAAA+C,GAAA0B,EAAA1B,KAAMQ,EAAAkB,EAAAlB,KACPmB,EAAanH,KAAKqG,cAAcb,EAAMQ,GACtCoB,EAAWpH,KAAKiG,gBAAgBT,GAChC6B,EAAiBrH,KAAK0E,YAAY0C,EAExCpH,MAAK0G,UAAUS,EAAYE,GAC3B3B,QAAQC,KAAK,YAAaH,KAAIA,EAAEQ,KAAIA,EAAEmB,WAAUA,EAAEE,eAAgBA,EAAeC,QAAQ,KAAM,WAGrG1D,IAEAhE,GAAA2H,QAAe3D,GH4HT,SAAU/D,EAAQD,GIjOxBC,EAAAD,QAAA+B,QAAA,OJuOM,SAAU9B,EAAQD,GKvOxBC,EAAAD,QAAA+B,QAAA,SL6OM,SAAU9B,EAAQD,GM7OxBC,EAAAD,QAAA+B,QAAA","file":"scaffold.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})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition","(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})(this, function() {\nreturn /******/ (function(modules) { // webpackBootstrap\n/******/ \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, {\n/******/ \t\t\t\tconfigurable: false,\n/******/ \t\t\t\tenumerable: true,\n/******/ \t\t\t\tget: getter\n/******/ \t\t\t});\n/******/ \t\t}\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/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = 1);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"path\");\n\n/***/ }),\n/* 1 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar fs = __webpack_require__(2);\nvar path = __webpack_require__(0);\nvar glob = __webpack_require__(3);\nvar handlebars = __webpack_require__(4);\nvar SimpleScaffold = /** @class */ (function () {\n function SimpleScaffold(config) {\n this.locals = {};\n var DefaultConfig = {\n name: 'scaffold',\n templates: [],\n output: process.cwd(),\n };\n this.config = Object.assign({}, DefaultConfig, config);\n var 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 this.locals = Object.assign({}, DefaultLocals, config.locals);\n // console.info('Config loaded:', this.config)\n }\n SimpleScaffold.prototype.parseLocals = function (text) {\n var template = handlebars.compile(text, {\n noEscape: true\n });\n return template(this.locals);\n };\n SimpleScaffold.prototype.fileList = function (input) {\n var _i, input_1, checkPath, files, idx, cleanCheckPath, _a, files_1, file;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n console.info('input:', input);\n _i = 0, input_1 = input;\n _b.label = 1;\n case 1:\n if (!(_i < input_1.length)) return [3 /*break*/, 6];\n checkPath = input_1[_i];\n files = glob.sync(checkPath).map(function (g) { return path.resolve(g); });\n idx = checkPath.indexOf('*');\n cleanCheckPath = checkPath;\n if (idx >= 0) {\n cleanCheckPath = checkPath.slice(0, idx - 1);\n }\n _a = 0, files_1 = files;\n _b.label = 2;\n case 2:\n if (!(_a < files_1.length)) return [3 /*break*/, 5];\n file = files_1[_a];\n return [4 /*yield*/, { base: cleanCheckPath, file: file }];\n case 3:\n _b.sent();\n _b.label = 4;\n case 4:\n _a++;\n return [3 /*break*/, 2];\n case 5:\n _i++;\n return [3 /*break*/, 1];\n case 6: return [2 /*return*/];\n }\n });\n };\n SimpleScaffold.prototype.getFileContents = function (filePath) {\n return fs.readFileSync(filePath).toString();\n };\n SimpleScaffold.prototype.getOutputPath = function (file, basePath) {\n var out;\n if (typeof this.config.output === 'function') {\n out = this.config.output(file, basePath);\n }\n else {\n var outputDir = this.config.output + (\"/\" + this.config.name + \"/\");\n var idx = file.indexOf(basePath);\n var relativeFilePath = file;\n if (idx >= 0) {\n // console.info('file:', {file, idx, basePath})\n relativeFilePath = file.slice(idx + basePath.length + 1);\n }\n out = outputDir + relativeFilePath;\n }\n return this.parseLocals(out);\n };\n SimpleScaffold.prototype.writeFile = function (filePath, fileContents) {\n if (!fs.existsSync(path.dirname(filePath))) {\n fs.mkdirSync(path.dirname(filePath));\n }\n console.info('Writing file:', filePath);\n fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' });\n };\n SimpleScaffold.prototype.run = function () {\n var templates = this.fileList(this.config.templates);\n console.info('Templates input:', templates);\n console.info('Locals:', this.locals);\n var fileConf;\n while (fileConf = templates.next().value) {\n var file = fileConf.file, base = fileConf.base;\n var outputPath = this.getOutputPath(file, base);\n var contents = this.getFileContents(file);\n var outputContents = this.parseLocals(contents);\n this.writeFile(outputPath, outputContents);\n console.info('Parsing:', { file: file, base: base, outputPath: outputPath, outputContents: outputContents.replace(\"\\n\", \"\\\\n\") });\n }\n };\n return SimpleScaffold;\n}());\nexports.default = SimpleScaffold;\n\n\n/***/ }),\n/* 2 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"fs\");\n\n/***/ }),\n/* 3 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"glob\");\n\n/***/ }),\n/* 4 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"handlebars\");\n\n/***/ })\n/******/ ]);\n});\n\n\n// WEBPACK FOOTER //\n// scaffold.js"," \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, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\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 \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 455e10927aab1ecbd951","module.exports = require(\"path\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"path\"\n// module id = 0\n// module chunks = 0 1 2","import * as fs from 'fs'\nimport * as path from 'path'\nimport IScaffold from './index'\nimport * as glob from 'glob'\nimport * as handlebars from 'handlebars'\n\nclass SimpleScaffold {\n private config: IScaffold.IConfig\n private locals = {} as any\n\n constructor(config: IScaffold.IConfig) {\n const DefaultConfig: IScaffold.IConfig = {\n name: 'scaffold',\n templates: [],\n output: process.cwd(),\n }\n\n this.config = (Object as any).assign({}, 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 = (Object as any).assign({}, DefaultLocals, config.locals)\n\n // console.info('Config loaded:', this.config)\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[]): IterableIterator {\n console.info('input:', input)\n for (const checkPath of input) {\n const files = glob.sync(checkPath).map(g => path.resolve(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 yield {base: cleanCheckPath, file}\n }\n }\n }\n\n private getFileContents(filePath: string): string {\n return fs.readFileSync(filePath).toString()\n }\n\n private getOutputPath(file: string, basePath: string): string {\n let out\n\n if (typeof this.config.output === 'function') {\n out = this.config.output(file, basePath)\n } else {\n const outputDir = this.config.output + `/${this.config.name}/`\n const idx = file.indexOf(basePath)\n let relativeFilePath = file\n if (idx >= 0) {\n // console.info('file:', {file, idx, basePath})\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 if (!fs.existsSync(path.dirname(filePath))) {\n fs.mkdirSync(path.dirname(filePath))\n }\n console.info('Writing file:', filePath)\n fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' })\n }\n\n public run(): void {\n const templates = this.fileList(this.config.templates)\n\n console.info('Templates input:', templates)\n console.info('Locals:', this.locals)\n\n let fileConf\n while (fileConf = templates.next().value) {\n const {file, base} = fileConf\n const outputPath = this.getOutputPath(file, base)\n const contents = this.getFileContents(file)\n const outputContents = this.parseLocals(contents)\n\n this.writeFile(outputPath, outputContents)\n console.info('Parsing:', {file, base, outputPath, outputContents: outputContents.replace(\"\\n\", \"\\\\n\")})\n }\n }\n}\n\nexport default SimpleScaffold\n\n\n\n// WEBPACK FOOTER //\n// ./scaffold.ts","module.exports = require(\"fs\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"fs\"\n// module id = 2\n// module chunks = 0 1 2","module.exports = require(\"glob\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"glob\"\n// module id = 3\n// module chunks = 0 1 2","module.exports = require(\"handlebars\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"handlebars\"\n// module id = 4\n// module chunks = 0 1 2"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/test.js b/dist/test.js index b67a368..57abea3 100755 --- a/dist/test.js +++ b/dist/test.js @@ -1,2 +1,2 @@ -!function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=5)}([function(e,t){e.exports=require("path")},function(e,t,n){"use strict";var o=this&&this.__generator||function(e,t){function n(e){return function(t){return o([e,t])}}function o(n){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,i&&(s=i[2&n[0]?"return":n[0]?"throw":"next"])&&!(s=s.call(i,n[1])).done)return s;switch(i=0,s&&(n=[0,s.value]),n[0]){case 0:case 1:s=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,i=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(s=u.trys,!(s=s.length>0&&s[s.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]=0&&(l=r.slice(0,u-1)),c=0,f=a,o.label=2;case 2:return c=0&&(i=e.slice(r+t.length+1)),n=o+i}return this.parseLocals(n)},e.prototype.writeFile=function(e,t){r.existsSync(i.dirname(e))||r.mkdirSync(i.dirname(e)),console.info("Writing file:",e),r.writeFileSync(e,t,{encoding:"utf-8"})},e.prototype.run=function(){var e=this.fileList(this.config.templates);console.info("Templates input:",e),console.info("Locals:",this.locals);for(var t;t=e.next().value;){var n=t.file,o=t.base,r=this.getOutputPath(n,o),i=this.getFileContents(n),s=this.parseLocals(i);this.writeFile(r,s),console.info("Parsing:",{file:n,base:o,outputPath:r,outputContents:s.replace("\n","\\n")})}},e}();t.default=u},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("glob")},function(e,t){e.exports=require("handlebars")},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(1),r=n(0),i=r.join(process.cwd(),"examples");new o.default({templates:[i+"/test-input/Component/**/*"],output:i+"/test-output",locals:{property:"myProp",value:'"value"'}}).run()}]); +!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()}(this,function(){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=5)}([function(e,t){e.exports=require("path")},function(e,t,n){"use strict";var o=this&&this.__generator||function(e,t){function n(e){return function(t){return o([e,t])}}function o(n){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,i&&(s=i[2&n[0]?"return":n[0]?"throw":"next"])&&!(s=s.call(i,n[1])).done)return s;switch(i=0,s&&(n=[0,s.value]),n[0]){case 0:case 1:s=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,i=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(s=u.trys,!(s=s.length>0&&s[s.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]=0&&(c=r.slice(0,u-1)),l=0,f=a,o.label=2;case 2:return l=0&&(i=e.slice(r+t.length+1)),n=o+i}return this.parseLocals(n)},e.prototype.writeFile=function(e,t){r.existsSync(i.dirname(e))||r.mkdirSync(i.dirname(e)),console.info("Writing file:",e),r.writeFileSync(e,t,{encoding:"utf-8"})},e.prototype.run=function(){var e=this.fileList(this.config.templates);console.info("Templates input:",e),console.info("Locals:",this.locals);for(var t;t=e.next().value;){var n=t.file,o=t.base,r=this.getOutputPath(n,o),i=this.getFileContents(n),s=this.parseLocals(i);this.writeFile(r,s),console.info("Parsing:",{file:n,base:o,outputPath:r,outputContents:s.replace("\n","\\n")})}},e}();t.default=u},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("glob")},function(e,t){e.exports=require("handlebars")},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(1),r=n(0),i=r.join(process.cwd(),"examples");new o.default({templates:[i+"/test-input/Component/**/*"],output:i+"/test-output",locals:{property:"myProp",value:'"value"'}}).run()}])}); //# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/dist/test.js.map b/dist/test.js.map index c007a0c..f7c1887 100755 --- a/dist/test.js.map +++ b/dist/test.js.map @@ -1 +1 @@ -{"version":3,"sources":["test.js","webpack/bootstrap ca56a8b8c9b0e51d2e17","external \"path\"","/Users/chenasraf/Dev/simple-scaffold/scaffold.ts","external \"fs\"","external \"glob\"","external \"handlebars\"","/Users/chenasraf/Dev/simple-scaffold/test.ts"],"names":["modules","__webpack_require__","moduleId","installedModules","exports","module","i","l","call","m","c","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","require","__generator","this","thisArg","body","verb","v","step","op","f","TypeError","_","y","t","done","value","label","ops","pop","trys","length","push","e","g","sent","next","throw","return","Symbol","iterator","fs","path","glob","handlebars","SimpleScaffold","config","locals","DefaultConfig","templates","output","process","cwd","assign","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","text","compile","noEscape","fileList","input","_i","input_1","checkPath","files","idx","cleanCheckPath","_a","files_1","file","_b","console","info","sync","map","resolve","indexOf","base","getFileContents","filePath","readFileSync","toString","getOutputPath","basePath","out","outputDir","relativeFilePath","writeFile","fileContents","existsSync","dirname","mkdirSync","writeFileSync","encoding","run","fileConf","outputPath","contents","outputContents","replace","default","scaffold_1","templateDir","join"],"mappings":"CAAS,SAAUA,GCInB,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAE,OAGA,IAAAC,GAAAF,EAAAD,IACAI,EAAAJ,EACAK,GAAA,EACAH,WAUA,OANAJ,GAAAE,GAAAM,KAAAH,EAAAD,QAAAC,IAAAD,QAAAH,GAGAI,EAAAE,GAAA,EAGAF,EAAAD,QAvBA,GAAAD,KA4BAF,GAAAQ,EAAAT,EAGAC,EAAAS,EAAAP,EAGAF,EAAAU,EAAA,SAAAP,EAAAQ,EAAAC,GACAZ,EAAAa,EAAAV,EAAAQ,IACAG,OAAAC,eAAAZ,EAAAQ,GACAK,cAAA,EACAC,YAAA,EACAC,IAAAN,KAMAZ,EAAAmB,EAAA,SAAAf,GACA,GAAAQ,GAAAR,KAAAgB,WACA,WAA2B,MAAAhB,GAAA,SAC3B,WAAiC,MAAAA,GAEjC,OADAJ,GAAAU,EAAA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AEjC,YAEAc,QAAOC,eAAeZ,EAAS,cAAgBuC,OAAO,GO7OtD,IAAA+E,GAAAzH,EAAA,GACA0D,EAAA1D,EAAA,GAEM0H,EAAchE,EAAKiE,KAAKxD,QAAQC,MAAO,WAE7C,IAAIqD,GAAAD,SACFvD,WAAYyD,EAAc,8BAC1BxD,OAAQwD,EAAc,eACtB3D,QACEzC,SAAU,SACVoB,MAAO,aAERwE","file":"test.js","sourcesContent":["/******/ (function(modules) { // webpackBootstrap\n/******/ \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, {\n/******/ \t\t\t\tconfigurable: false,\n/******/ \t\t\t\tenumerable: true,\n/******/ \t\t\t\tget: getter\n/******/ \t\t\t});\n/******/ \t\t}\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/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = 5);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"path\");\n\n/***/ }),\n/* 1 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar fs = __webpack_require__(2);\nvar path = __webpack_require__(0);\nvar glob = __webpack_require__(3);\nvar handlebars = __webpack_require__(4);\nvar SimpleScaffold = /** @class */ (function () {\n function SimpleScaffold(config) {\n this.locals = {};\n var DefaultConfig = {\n name: 'scaffold',\n templates: [],\n output: process.cwd(),\n };\n this.config = Object.assign({}, DefaultConfig, config);\n var 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 this.locals = Object.assign({}, DefaultLocals, config.locals);\n // console.info('Config loaded:', this.config)\n }\n SimpleScaffold.prototype.parseLocals = function (text) {\n var template = handlebars.compile(text, {\n noEscape: true\n });\n return template(this.locals);\n };\n SimpleScaffold.prototype.fileList = function (input) {\n var _i, input_1, checkPath, files, idx, cleanCheckPath, _a, files_1, file;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n console.info('input:', input);\n _i = 0, input_1 = input;\n _b.label = 1;\n case 1:\n if (!(_i < input_1.length)) return [3 /*break*/, 6];\n checkPath = input_1[_i];\n files = glob.sync(checkPath).map(function (g) { return path.resolve(g); });\n idx = checkPath.indexOf('*');\n cleanCheckPath = checkPath;\n if (idx >= 0) {\n cleanCheckPath = checkPath.slice(0, idx - 1);\n }\n _a = 0, files_1 = files;\n _b.label = 2;\n case 2:\n if (!(_a < files_1.length)) return [3 /*break*/, 5];\n file = files_1[_a];\n return [4 /*yield*/, { base: cleanCheckPath, file: file }];\n case 3:\n _b.sent();\n _b.label = 4;\n case 4:\n _a++;\n return [3 /*break*/, 2];\n case 5:\n _i++;\n return [3 /*break*/, 1];\n case 6: return [2 /*return*/];\n }\n });\n };\n SimpleScaffold.prototype.getFileContents = function (filePath) {\n return fs.readFileSync(filePath).toString();\n };\n SimpleScaffold.prototype.getOutputPath = function (file, basePath) {\n var out;\n if (typeof this.config.output === 'function') {\n out = this.config.output(file, basePath);\n }\n else {\n var outputDir = this.config.output + (\"/\" + this.config.name + \"/\");\n var idx = file.indexOf(basePath);\n var relativeFilePath = file;\n if (idx >= 0) {\n // console.info('file:', {file, idx, basePath})\n relativeFilePath = file.slice(idx + basePath.length + 1);\n }\n out = outputDir + relativeFilePath;\n }\n return this.parseLocals(out);\n };\n SimpleScaffold.prototype.writeFile = function (filePath, fileContents) {\n if (!fs.existsSync(path.dirname(filePath))) {\n fs.mkdirSync(path.dirname(filePath));\n }\n console.info('Writing file:', filePath);\n fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' });\n };\n SimpleScaffold.prototype.run = function () {\n var templates = this.fileList(this.config.templates);\n console.info('Templates input:', templates);\n console.info('Locals:', this.locals);\n var fileConf;\n while (fileConf = templates.next().value) {\n var file = fileConf.file, base = fileConf.base;\n var outputPath = this.getOutputPath(file, base);\n var contents = this.getFileContents(file);\n var outputContents = this.parseLocals(contents);\n this.writeFile(outputPath, outputContents);\n console.info('Parsing:', { file: file, base: base, outputPath: outputPath, outputContents: outputContents.replace(\"\\n\", \"\\\\n\") });\n }\n };\n return SimpleScaffold;\n}());\nexports.default = SimpleScaffold;\n\n\n/***/ }),\n/* 2 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"fs\");\n\n/***/ }),\n/* 3 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"glob\");\n\n/***/ }),\n/* 4 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"handlebars\");\n\n/***/ }),\n/* 5 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar scaffold_1 = __webpack_require__(1);\nvar path = __webpack_require__(0);\nvar templateDir = path.join(process.cwd(), 'examples');\nnew scaffold_1.default({\n templates: [templateDir + '/test-input/Component/**/*'],\n output: templateDir + '/test-output',\n locals: {\n property: 'myProp',\n value: '\"value\"'\n }\n}).run();\n\n\n/***/ })\n/******/ ]);\n\n\n// WEBPACK FOOTER //\n// test.js"," \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, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\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 \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 5);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap ca56a8b8c9b0e51d2e17","module.exports = require(\"path\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"path\"\n// module id = 0\n// module chunks = 0 1 2","import * as fs from 'fs'\nimport * as path from 'path'\nimport IScaffold from './index'\nimport * as glob from 'glob'\nimport * as handlebars from 'handlebars'\n\nclass SimpleScaffold {\n private config: IScaffold.IConfig\n private locals = {} as any\n\n constructor(config: IScaffold.IConfig) {\n const DefaultConfig: IScaffold.IConfig = {\n name: 'scaffold',\n templates: [],\n output: process.cwd(),\n }\n\n this.config = (Object as any).assign({}, 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 = (Object as any).assign({}, DefaultLocals, config.locals)\n\n // console.info('Config loaded:', this.config)\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[]): IterableIterator {\n console.info('input:', input)\n for (const checkPath of input) {\n const files = glob.sync(checkPath).map(g => path.resolve(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 yield {base: cleanCheckPath, file}\n }\n }\n }\n\n private getFileContents(filePath: string): string {\n return fs.readFileSync(filePath).toString()\n }\n\n private getOutputPath(file: string, basePath: string): string {\n let out\n\n if (typeof this.config.output === 'function') {\n out = this.config.output(file, basePath)\n } else {\n const outputDir = this.config.output + `/${this.config.name}/`\n const idx = file.indexOf(basePath)\n let relativeFilePath = file\n if (idx >= 0) {\n // console.info('file:', {file, idx, basePath})\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 if (!fs.existsSync(path.dirname(filePath))) {\n fs.mkdirSync(path.dirname(filePath))\n }\n console.info('Writing file:', filePath)\n fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' })\n }\n\n public run(): void {\n const templates = this.fileList(this.config.templates)\n\n console.info('Templates input:', templates)\n console.info('Locals:', this.locals)\n\n let fileConf\n while (fileConf = templates.next().value) {\n const {file, base} = fileConf\n const outputPath = this.getOutputPath(file, base)\n const contents = this.getFileContents(file)\n const outputContents = this.parseLocals(contents)\n\n this.writeFile(outputPath, outputContents)\n console.info('Parsing:', {file, base, outputPath, outputContents: outputContents.replace(\"\\n\", \"\\\\n\")})\n }\n }\n}\n\nexport default SimpleScaffold\n\n\n\n// WEBPACK FOOTER //\n// ./scaffold.ts","module.exports = require(\"fs\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"fs\"\n// module id = 2\n// module chunks = 0 1 2","module.exports = require(\"glob\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"glob\"\n// module id = 3\n// module chunks = 0 1 2","module.exports = require(\"handlebars\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"handlebars\"\n// module id = 4\n// module chunks = 0 1 2","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',\n locals: {\n property: 'myProp',\n value: '\"value\"'\n }\n}).run()\n\n\n\n// WEBPACK FOOTER //\n// ./test.ts"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack/universalModuleDefinition","test.js","webpack/bootstrap 455e10927aab1ecbd951","external \"path\"","/Users/chenasraf/Dev/simple-scaffold/scaffold.ts","external \"fs\"","external \"glob\"","external \"handlebars\"","/Users/chenasraf/Dev/simple-scaffold/test.ts"],"names":["root","factory","exports","module","define","amd","this","modules","__webpack_require__","moduleId","installedModules","i","l","call","m","c","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","require","__generator","thisArg","body","verb","v","step","op","f","TypeError","_","y","t","done","value","label","ops","pop","trys","length","push","e","g","sent","next","throw","return","Symbol","iterator","fs","path","glob","handlebars","SimpleScaffold","config","locals","DefaultConfig","templates","output","process","cwd","assign","DefaultLocals","Name","toUpperCase","slice","toLowerCase","parseLocals","text","compile","noEscape","fileList","input","_i","input_1","checkPath","files","idx","cleanCheckPath","_a","files_1","file","_b","console","info","sync","map","resolve","indexOf","base","getFileContents","filePath","readFileSync","toString","getOutputPath","basePath","out","outputDir","relativeFilePath","writeFile","fileContents","existsSync","dirname","mkdirSync","writeFileSync","encoding","run","fileConf","outputPath","contents","outputContents","replace","default","scaffold_1","templateDir","join"],"mappings":"CAAA,SAAAA,EAAAC,GACA,gBAAAC,UAAA,gBAAAC,QACAA,OAAAD,QAAAD,IACA,kBAAAG,gBAAAC,IACAD,UAAAH,GACA,gBAAAC,SACAA,QAAA,QAAAD,IAEAD,EAAA,QAAAC,KACCK,KAAA,WACD,MCAgB,UAAUC,GCN1B,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAP,OAGA,IAAAC,GAAAO,EAAAD,IACAE,EAAAF,EACAG,GAAA,EACAV,WAUA,OANAK,GAAAE,GAAAI,KAAAV,EAAAD,QAAAC,IAAAD,QAAAM,GAGAL,EAAAS,GAAA,EAGAT,EAAAD,QAvBA,GAAAQ,KA4DA,OAhCAF,GAAAM,EAAAP,EAGAC,EAAAO,EAAAL,EAGAF,EAAAQ,EAAA,SAAAd,EAAAe,EAAAC,GACAV,EAAAW,EAAAjB,EAAAe,IACAG,OAAAC,eAAAnB,EAAAe,GACAK,cAAA,EACAC,YAAA,EACAC,IAAAN,KAMAV,EAAAiB,EAAA,SAAAtB,GACA,GAAAe,GAAAf,KAAAuB,WACA,WAA2B,MAAAvB,GAAA,SAC3B,WAAiC,MAAAA,GAEjC,OADAK,GAAAQ,EAAA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AEAY,QAAOC,eAAenB,EAAS,cAAgB6C,OAAO,GOvPtD,IAAA+E,GAAAtH,EAAA,GACAuD,EAAAvD,EAAA,GAEMuH,EAAchE,EAAKiE,KAAKxD,QAAQC,MAAO,WAE7C,IAAIqD,GAAAD,SACFvD,WAAYyD,EAAc,8BAC1BxD,OAAQwD,EAAc,eACtB3D,QACExC,SAAU,SACVmB,MAAO,aAERwE","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})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition","(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})(this, function() {\nreturn /******/ (function(modules) { // webpackBootstrap\n/******/ \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, {\n/******/ \t\t\t\tconfigurable: false,\n/******/ \t\t\t\tenumerable: true,\n/******/ \t\t\t\tget: getter\n/******/ \t\t\t});\n/******/ \t\t}\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/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = 5);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"path\");\n\n/***/ }),\n/* 1 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar fs = __webpack_require__(2);\nvar path = __webpack_require__(0);\nvar glob = __webpack_require__(3);\nvar handlebars = __webpack_require__(4);\nvar SimpleScaffold = /** @class */ (function () {\n function SimpleScaffold(config) {\n this.locals = {};\n var DefaultConfig = {\n name: 'scaffold',\n templates: [],\n output: process.cwd(),\n };\n this.config = Object.assign({}, DefaultConfig, config);\n var 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 this.locals = Object.assign({}, DefaultLocals, config.locals);\n // console.info('Config loaded:', this.config)\n }\n SimpleScaffold.prototype.parseLocals = function (text) {\n var template = handlebars.compile(text, {\n noEscape: true\n });\n return template(this.locals);\n };\n SimpleScaffold.prototype.fileList = function (input) {\n var _i, input_1, checkPath, files, idx, cleanCheckPath, _a, files_1, file;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n console.info('input:', input);\n _i = 0, input_1 = input;\n _b.label = 1;\n case 1:\n if (!(_i < input_1.length)) return [3 /*break*/, 6];\n checkPath = input_1[_i];\n files = glob.sync(checkPath).map(function (g) { return path.resolve(g); });\n idx = checkPath.indexOf('*');\n cleanCheckPath = checkPath;\n if (idx >= 0) {\n cleanCheckPath = checkPath.slice(0, idx - 1);\n }\n _a = 0, files_1 = files;\n _b.label = 2;\n case 2:\n if (!(_a < files_1.length)) return [3 /*break*/, 5];\n file = files_1[_a];\n return [4 /*yield*/, { base: cleanCheckPath, file: file }];\n case 3:\n _b.sent();\n _b.label = 4;\n case 4:\n _a++;\n return [3 /*break*/, 2];\n case 5:\n _i++;\n return [3 /*break*/, 1];\n case 6: return [2 /*return*/];\n }\n });\n };\n SimpleScaffold.prototype.getFileContents = function (filePath) {\n return fs.readFileSync(filePath).toString();\n };\n SimpleScaffold.prototype.getOutputPath = function (file, basePath) {\n var out;\n if (typeof this.config.output === 'function') {\n out = this.config.output(file, basePath);\n }\n else {\n var outputDir = this.config.output + (\"/\" + this.config.name + \"/\");\n var idx = file.indexOf(basePath);\n var relativeFilePath = file;\n if (idx >= 0) {\n // console.info('file:', {file, idx, basePath})\n relativeFilePath = file.slice(idx + basePath.length + 1);\n }\n out = outputDir + relativeFilePath;\n }\n return this.parseLocals(out);\n };\n SimpleScaffold.prototype.writeFile = function (filePath, fileContents) {\n if (!fs.existsSync(path.dirname(filePath))) {\n fs.mkdirSync(path.dirname(filePath));\n }\n console.info('Writing file:', filePath);\n fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' });\n };\n SimpleScaffold.prototype.run = function () {\n var templates = this.fileList(this.config.templates);\n console.info('Templates input:', templates);\n console.info('Locals:', this.locals);\n var fileConf;\n while (fileConf = templates.next().value) {\n var file = fileConf.file, base = fileConf.base;\n var outputPath = this.getOutputPath(file, base);\n var contents = this.getFileContents(file);\n var outputContents = this.parseLocals(contents);\n this.writeFile(outputPath, outputContents);\n console.info('Parsing:', { file: file, base: base, outputPath: outputPath, outputContents: outputContents.replace(\"\\n\", \"\\\\n\") });\n }\n };\n return SimpleScaffold;\n}());\nexports.default = SimpleScaffold;\n\n\n/***/ }),\n/* 2 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"fs\");\n\n/***/ }),\n/* 3 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"glob\");\n\n/***/ }),\n/* 4 */\n/***/ (function(module, exports) {\n\nmodule.exports = require(\"handlebars\");\n\n/***/ }),\n/* 5 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar scaffold_1 = __webpack_require__(1);\nvar path = __webpack_require__(0);\nvar templateDir = path.join(process.cwd(), 'examples');\nnew scaffold_1.default({\n templates: [templateDir + '/test-input/Component/**/*'],\n output: templateDir + '/test-output',\n locals: {\n property: 'myProp',\n value: '\"value\"'\n }\n}).run();\n\n\n/***/ })\n/******/ ]);\n});\n\n\n// WEBPACK FOOTER //\n// test.js"," \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, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\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 \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 5);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 455e10927aab1ecbd951","module.exports = require(\"path\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"path\"\n// module id = 0\n// module chunks = 0 1 2","import * as fs from 'fs'\nimport * as path from 'path'\nimport IScaffold from './index'\nimport * as glob from 'glob'\nimport * as handlebars from 'handlebars'\n\nclass SimpleScaffold {\n private config: IScaffold.IConfig\n private locals = {} as any\n\n constructor(config: IScaffold.IConfig) {\n const DefaultConfig: IScaffold.IConfig = {\n name: 'scaffold',\n templates: [],\n output: process.cwd(),\n }\n\n this.config = (Object as any).assign({}, 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 = (Object as any).assign({}, DefaultLocals, config.locals)\n\n // console.info('Config loaded:', this.config)\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[]): IterableIterator {\n console.info('input:', input)\n for (const checkPath of input) {\n const files = glob.sync(checkPath).map(g => path.resolve(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 yield {base: cleanCheckPath, file}\n }\n }\n }\n\n private getFileContents(filePath: string): string {\n return fs.readFileSync(filePath).toString()\n }\n\n private getOutputPath(file: string, basePath: string): string {\n let out\n\n if (typeof this.config.output === 'function') {\n out = this.config.output(file, basePath)\n } else {\n const outputDir = this.config.output + `/${this.config.name}/`\n const idx = file.indexOf(basePath)\n let relativeFilePath = file\n if (idx >= 0) {\n // console.info('file:', {file, idx, basePath})\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 if (!fs.existsSync(path.dirname(filePath))) {\n fs.mkdirSync(path.dirname(filePath))\n }\n console.info('Writing file:', filePath)\n fs.writeFileSync(filePath, fileContents, { encoding: 'utf-8' })\n }\n\n public run(): void {\n const templates = this.fileList(this.config.templates)\n\n console.info('Templates input:', templates)\n console.info('Locals:', this.locals)\n\n let fileConf\n while (fileConf = templates.next().value) {\n const {file, base} = fileConf\n const outputPath = this.getOutputPath(file, base)\n const contents = this.getFileContents(file)\n const outputContents = this.parseLocals(contents)\n\n this.writeFile(outputPath, outputContents)\n console.info('Parsing:', {file, base, outputPath, outputContents: outputContents.replace(\"\\n\", \"\\\\n\")})\n }\n }\n}\n\nexport default SimpleScaffold\n\n\n\n// WEBPACK FOOTER //\n// ./scaffold.ts","module.exports = require(\"fs\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"fs\"\n// module id = 2\n// module chunks = 0 1 2","module.exports = require(\"glob\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"glob\"\n// module id = 3\n// module chunks = 0 1 2","module.exports = require(\"handlebars\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"handlebars\"\n// module id = 4\n// module chunks = 0 1 2","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',\n locals: {\n property: 'myProp',\n value: '\"value\"'\n }\n}).run()\n\n\n\n// WEBPACK FOOTER //\n// ./test.ts"],"sourceRoot":""} \ No newline at end of file diff --git a/package.json b/package.json index 7c73348..456c07e 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,10 @@ "build": "NODE_ENV=${NODE_ENV:-production} webpack -p && chmod -R +x ./dist", "dev": "webpack --watch", "start": "node dist/scaffold.js", - "test": "yarn build && node dist/test.js", - "cmd": "dist/cmd.js" + "test": "node dist/test.js", + "cmd": "dist/cmd.js", + "build-test": "yarn build && yarn test", + "build-cmd": "yarn build && yarn cmd" }, "dependencies": { "@types/glob": "^5.0.34",