fix: support deeper file structure

This commit is contained in:
Chen Asraf
2021-02-01 15:23:50 +02:00
parent 7bee2a51c7
commit 4afafa5a4a
13 changed files with 3293 additions and 3156 deletions

3
.prettierrc Normal file
View File

@@ -0,0 +1,3 @@
{
"semi": false
}

View File

@@ -1,3 +1,4 @@
{
"typescript.tsdk": "./node_modules/typescript/lib"
}
"typescript.tsdk": "./node_modules/typescript/lib",
"npm.packageManager": "yarn"
}

52
.vscode/tasks.json vendored
View File

@@ -1,7 +1,47 @@
{
"version": "0.1.0",
"command": "webpack",
"isShellCommand": true,
"args": [],
"showOutput": "always"
}
"version": "2.0.0",
"tasks": [
{
"script": "build",
"label": "build",
"type": "npm",
"problemMatcher": [],
},
{
"script": "dev",
"label": "dev",
"type": "npm",
"problemMatcher": [],
},
{
"script": "start",
"label": "start",
"type": "npm",
"problemMatcher": [],
},
{
"script": "test",
"label": "test",
"type": "npm",
"problemMatcher": [],
},
{
"script": "cmd",
"label": "cmd",
"type": "npm",
"problemMatcher": [],
},
{
"script": "build-test",
"label": "build-test",
"type": "npm",
"problemMatcher": [],
},
{
"script": "build-cmd",
"label": "build-cmd",
"type": "npm",
"problemMatcher": [],
},
],
}

2
dist/cmd.js vendored

File diff suppressed because one or more lines are too long

2
dist/cmd.js.map vendored

File diff suppressed because one or more lines are too long

2
dist/index.js vendored
View File

@@ -1,2 +1,2 @@
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.library=t():e.library=t()}(global,function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t){e.exports=require("path")},function(e,t,n){"use strict";var o=this&&this.__assign||function(){return(o=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i=n(0),s=n(3),f=n(4),c=function(){function e(e){this.locals={};var t={name:"scaffold",templates:[],output:process.cwd(),createSubfolder:!0};this.config=o({},t,e);var n={Name:this.config.name[0].toUpperCase()+this.config.name.slice(1),name:this.config.name[0].toLowerCase()+this.config.name.slice(1)};this.locals=o({},n,e.locals)}return e.prototype.parseLocals=function(e){return f.compile(e,{noEscape:!0})(this.locals)},e.prototype.fileList=function(e){for(var t=[],n=0,o=e;n<o.length;n++){var r=o[n],f=s.sync(r,{dot:!0}).map(function(e){return"/"==e[0]?e:i.join(process.cwd(),e)}),c=r.indexOf("*"),u=r;c>=0&&(u=r.slice(0,c-1));for(var a=0,l=f;a<l.length;a++){var p=l[a];t.push({base:u,file:p})}}return t},e.prototype.getFileContents=function(e){return console.log(r.readFileSync(e)),r.readFileSync(e).toString()},e.prototype.getOutputPath=function(e,t){var n;if("function"==typeof this.config.output)n=this.config.output(e,t);else{var o=this.config.output+(this.config.createSubfolder?"/"+this.config.name+"/":"/"),r=e.indexOf(t),i=e;r>=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.writeFile(e,t,{encoding:"utf-8"},function(e){if(e)throw e})},e.prototype.run=function(){console.log("Generating scaffold: "+this.config.name+"...");for(var e,t=0,n=0,o=this.fileList(this.config.templates);n<o.length;n++){t++;var r=(e=o[n]).file,i=e.base,s=this.getOutputPath(r,i),f=this.getFileContents(r),c=this.parseLocals(f);this.writeFile(s,c),console.info("Parsing:",{file:r,base:i,outputPath:s,outputContents:c.replace("\n","\\n")})}if(!t)throw new Error("No files to scaffold!");console.log("Done")},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(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.library=e():t.library=e()}(global,function(){return function(t){var e={};function o(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=1)}([function(t,e){t.exports=require("path")},function(t,e,o){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0});var r=o(2),i=o(0),s=o(3),c=o(4),f=function(){function t(t){this.locals={};var e={name:"scaffold",templates:[],output:process.cwd(),createSubfolder:!0};this.config=n({},e,t);var o={Name:this.config.name[0].toUpperCase()+this.config.name.slice(1),name:this.config.name[0].toLowerCase()+this.config.name.slice(1)};this.locals=n({},o,t.locals)}return t.prototype.parseLocals=function(t){return c.compile(t,{noEscape:!0})(this.locals)},t.prototype.fileList=function(t){for(var e=[],o=0,n=t;o<n.length;o++){var r=n[o],c=s.sync(r,{dot:!0}).map(function(t){return"/"==t[0]?t:i.join(process.cwd(),t)}),f=r.indexOf("*"),u=r;f>=0&&(u=r.slice(0,f-1));for(var l=0,a=c;l<a.length;l++){var p=a[l];e.push({base:u,file:p})}}return e},t.prototype.getFileContents=function(t){return console.log(r.readFileSync(t)),r.readFileSync(t).toString()},t.prototype.getOutputPath=function(t,e){var o;if("function"==typeof this.config.output)o=this.config.output(t,e);else{var n=this.config.output+(this.config.createSubfolder?"/"+this.config.name+"/":"/"),r=t.indexOf(e),i=t;r>=0&&(i=t.slice(r+e.length+1)),o=n+i}return this.parseLocals(o)},t.prototype.writeFile=function(t,e){var o=i.dirname(t);this.writeDirectory(o,t),console.info("Writing file:",t),r.writeFile(t,e,{encoding:"utf-8"},function(t){if(t)throw t})},t.prototype.run=function(){console.log("Generating scaffold: "+this.config.name+"...");var t,e=this.fileList(this.config.templates),o=0;console.log("Template files:",e);for(var n=0,i=e;n<i.length;n++){t=i[n];var s=void 0,c=void 0,f=void 0,u=void 0,l=void 0;try{if(o++,u=t.file,l=t.base,s=this.getOutputPath(u,l),r.lstatSync(u).isDirectory()){this.writeDirectory(s,u);continue}c=this.getFileContents(u),f=this.parseLocals(c),console.info("Writing:",{file:u,base:l,outputPath:s,outputContents:f.replace("\n","\\n")}),this.writeFile(s,f)}catch(t){throw console.error("Error while processing file:",{file:u,base:l,contents:c,outputPath:s,outputContents:f}),t}}if(!o)throw new Error("No files to scaffold!");console.log("Done")},t.prototype.writeDirectory=function(t,e){var o=i.dirname(t);r.existsSync(o)||this.writeDirectory(o,t),r.existsSync(t)||(console.info("Creating directory:",{file:e,outputPath:t}),r.mkdirSync(t))},t}();e.default=f},function(t,e){t.exports=require("fs")},function(t,e){t.exports=require("glob")},function(t,e){t.exports=require("handlebars")}])});
//# sourceMappingURL=index.js.map

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

5
dist/scaffold.d.ts vendored
View File

@@ -1,7 +1,7 @@
import { IScaffold } from './index.d';
import { IScaffold } from "./index.d";
declare class SimpleScaffold {
config: IScaffold.Config;
locals: IScaffold.Config['locals'];
locals: IScaffold.Config["locals"];
constructor(config: IScaffold.Config);
private parseLocals;
private fileList;
@@ -9,5 +9,6 @@ declare class SimpleScaffold {
private getOutputPath;
private writeFile;
run(): void;
private writeDirectory;
}
export default SimpleScaffold;

2
dist/test.js vendored
View File

@@ -1,2 +1,2 @@
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.library=t():e.library=t()}(global,function(){return function(e){var t={};function o(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=e,o.c=t,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)o.d(n,r,function(t){return e[t]}.bind(null,r));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=5)}([function(e,t){e.exports=require("path")},function(e,t,o){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var r in t=arguments[o])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0});var r=o(2),i=o(0),u=o(3),s=o(4),a=function(){function e(e){this.locals={};var t={name:"scaffold",templates:[],output:process.cwd(),createSubfolder:!0};this.config=n({},t,e);var o={Name:this.config.name[0].toUpperCase()+this.config.name.slice(1),name:this.config.name[0].toLowerCase()+this.config.name.slice(1)};this.locals=n({},o,e.locals)}return e.prototype.parseLocals=function(e){return s.compile(e,{noEscape:!0})(this.locals)},e.prototype.fileList=function(e){for(var t=[],o=0,n=e;o<n.length;o++){var r=n[o],s=u.sync(r,{dot:!0}).map(function(e){return"/"==e[0]?e:i.join(process.cwd(),e)}),a=r.indexOf("*"),l=r;a>=0&&(l=r.slice(0,a-1));for(var c=0,f=s;c<f.length;c++){var p=f[c];t.push({base:l,file:p})}}return t},e.prototype.getFileContents=function(e){return console.log(r.readFileSync(e)),r.readFileSync(e).toString()},e.prototype.getOutputPath=function(e,t){var o;if("function"==typeof this.config.output)o=this.config.output(e,t);else{var n=this.config.output+(this.config.createSubfolder?"/"+this.config.name+"/":"/"),r=e.indexOf(t),i=e;r>=0&&(i=e.slice(r+t.length+1)),o=n+i}return this.parseLocals(o)},e.prototype.writeFile=function(e,t){r.existsSync(i.dirname(e))||r.mkdirSync(i.dirname(e)),console.info("Writing file:",e),r.writeFile(e,t,{encoding:"utf-8"},function(e){if(e)throw e})},e.prototype.run=function(){console.log("Generating scaffold: "+this.config.name+"...");for(var e,t=0,o=0,n=this.fileList(this.config.templates);o<n.length;o++){t++;var r=(e=n[o]).file,i=e.base,u=this.getOutputPath(r,i),s=this.getFileContents(r),a=this.parseLocals(s);this.writeFile(u,a),console.info("Parsing:",{file:r,base:i,outputPath:u,outputContents:a.replace("\n","\\n")})}if(!t)throw new Error("No files to scaffold!");console.log("Done")},e}();t.default=a},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("glob")},function(e,t){e.exports=require("handlebars")},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=o(1),r=o(0).join(process.cwd(),"examples");new n.default({templates:[r+"/test-input/Component/**/*"],output:r+"/test-output/no-create-subpath",createSubfolder:!1,locals:{property:"myProp",value:'"value"'}}).run(),new n.default({templates:[r+"/test-input/Component/**/*"],output:r+"/test-output",locals:{property:"myProp",value:'"value"'}}).run()}])});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.library=e():t.library=e()}(global,function(){return function(t){var e={};function o(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=5)}([function(t,e){t.exports=require("path")},function(t,e,o){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0});var r=o(2),i=o(0),s=o(3),u=o(4),c=function(){function t(t){this.locals={};var e={name:"scaffold",templates:[],output:process.cwd(),createSubfolder:!0};this.config=n({},e,t);var o={Name:this.config.name[0].toUpperCase()+this.config.name.slice(1),name:this.config.name[0].toLowerCase()+this.config.name.slice(1)};this.locals=n({},o,t.locals)}return t.prototype.parseLocals=function(t){return u.compile(t,{noEscape:!0})(this.locals)},t.prototype.fileList=function(t){for(var e=[],o=0,n=t;o<n.length;o++){var r=n[o],u=s.sync(r,{dot:!0}).map(function(t){return"/"==t[0]?t:i.join(process.cwd(),t)}),c=r.indexOf("*"),l=r;c>=0&&(l=r.slice(0,c-1));for(var a=0,f=u;a<f.length;a++){var p=f[a];e.push({base:l,file:p})}}return e},t.prototype.getFileContents=function(t){return console.log(r.readFileSync(t)),r.readFileSync(t).toString()},t.prototype.getOutputPath=function(t,e){var o;if("function"==typeof this.config.output)o=this.config.output(t,e);else{var n=this.config.output+(this.config.createSubfolder?"/"+this.config.name+"/":"/"),r=t.indexOf(e),i=t;r>=0&&(i=t.slice(r+e.length+1)),o=n+i}return this.parseLocals(o)},t.prototype.writeFile=function(t,e){var o=i.dirname(t);this.writeDirectory(o,t),console.info("Writing file:",t),r.writeFile(t,e,{encoding:"utf-8"},function(t){if(t)throw t})},t.prototype.run=function(){console.log("Generating scaffold: "+this.config.name+"...");var t,e=this.fileList(this.config.templates),o=0;console.log("Template files:",e);for(var n=0,i=e;n<i.length;n++){t=i[n];var s=void 0,u=void 0,c=void 0,l=void 0,a=void 0;try{if(o++,l=t.file,a=t.base,s=this.getOutputPath(l,a),r.lstatSync(l).isDirectory()){this.writeDirectory(s,l);continue}u=this.getFileContents(l),c=this.parseLocals(u),console.info("Writing:",{file:l,base:a,outputPath:s,outputContents:c.replace("\n","\\n")}),this.writeFile(s,c)}catch(t){throw console.error("Error while processing file:",{file:l,base:a,contents:u,outputPath:s,outputContents:c}),t}}if(!o)throw new Error("No files to scaffold!");console.log("Done")},t.prototype.writeDirectory=function(t,e){var o=i.dirname(t);r.existsSync(o)||this.writeDirectory(o,t),r.existsSync(t)||(console.info("Creating directory:",{file:e,outputPath:t}),r.mkdirSync(t))},t}();e.default=c},function(t,e){t.exports=require("fs")},function(t,e){t.exports=require("glob")},function(t,e){t.exports=require("handlebars")},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=o(1),r=o(0).join(process.cwd(),"examples");new n.default({templates:[r+"/test-input/Component/**/*"],output:r+"/test-output/no-create-subpath",createSubfolder:!1,locals:{property:"myProp",value:'"value"'}}).run(),new n.default({templates:[r+"/test-input/Component/**/*"],output:r+"/test-output",locals:{property:"myProp",value:'"value"'}}).run()}])});
//# sourceMappingURL=test.js.map

2
dist/test.js.map vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
{
"name": "simple-scaffold",
"version": "0.5.0",
"version": "0.6.0",
"description": "Create files based on templates",
"repository": "https://github.com/chenasraf/simple-scaffold.git",
"author": "Chen Asraf <inbox@casraf.com>",

View File

@@ -1,16 +1,16 @@
import * as fs from 'fs'
import * as path from 'path'
import {IScaffold} from './index.d'
import * as glob from 'glob'
import * as handlebars from 'handlebars'
import * as fs from "fs"
import * as path from "path"
import { IScaffold } from "./index.d"
import * as glob from "glob"
import * as handlebars from "handlebars"
class SimpleScaffold {
public config: IScaffold.Config
public locals: IScaffold.Config['locals'] = {} as any
public locals: IScaffold.Config["locals"] = {} as any
constructor(config: IScaffold.Config) {
const DefaultConfig: IScaffold.Config = {
name: 'scaffold',
name: "scaffold",
templates: [],
output: process.cwd(),
createSubfolder: true,
@@ -20,7 +20,7 @@ class SimpleScaffold {
const DefaultLocals = {
Name: this.config.name![0].toUpperCase() + this.config.name!.slice(1),
name: this.config.name![0].toLowerCase() + this.config.name!.slice(1)
name: this.config.name![0].toLowerCase() + this.config.name!.slice(1),
}
this.locals = { ...DefaultLocals, ...config.locals }
@@ -28,7 +28,7 @@ class SimpleScaffold {
private parseLocals(text: string): string {
const template = handlebars.compile(text, {
noEscape: true
noEscape: true,
})
return template(this.locals)
}
@@ -36,9 +36,10 @@ class SimpleScaffold {
private fileList(input: string[]): IScaffold.FileRepr[] {
const output: IScaffold.FileRepr[] = []
for (const checkPath of input) {
const files = glob.sync(checkPath, { dot: true })
.map(g => g[0] == '/' ? g : path.join(process.cwd(), g))
const idx = checkPath.indexOf('*')
const files = glob
.sync(checkPath, { dot: true })
.map((g) => (g[0] == "/" ? g : path.join(process.cwd(), g)))
const idx = checkPath.indexOf("*")
let cleanCheckPath = checkPath
if (idx >= 0) {
cleanCheckPath = checkPath.slice(0, idx - 1)
@@ -58,10 +59,12 @@ class SimpleScaffold {
private getOutputPath(file: string, basePath: string): string {
let out: string
if (typeof this.config.output === 'function') {
if (typeof this.config.output === "function") {
out = this.config.output(file, basePath)
} else {
const outputDir = this.config.output + (this.config.createSubfolder ? `/${this.config.name}/` : '/')
const outputDir =
this.config.output +
(this.config.createSubfolder ? `/${this.config.name}/` : "/")
const idx = file.indexOf(basePath)
let relativeFilePath = file
if (idx >= 0) {
@@ -74,11 +77,10 @@ class SimpleScaffold {
}
private writeFile(filePath: string, fileContents: string): void {
if (!fs.existsSync(path.dirname(filePath))) {
fs.mkdirSync(path.dirname(filePath))
}
console.info('Writing file:', filePath)
fs.writeFile(filePath, fileContents, { encoding: 'utf-8' }, (err) => {
const baseDir = path.dirname(filePath)
this.writeDirectory(baseDir, filePath)
console.info("Writing file:", filePath)
fs.writeFile(filePath, fileContents, { encoding: "utf-8" }, (err) => {
if (err) {
throw err
}
@@ -89,23 +91,62 @@ class SimpleScaffold {
console.log(`Generating scaffold: ${this.config.name}...`)
const templates = this.fileList(this.config.templates)
let fileConf, count = 0
for (fileConf of templates) {
count++
const { file, base } = fileConf
const outputPath = this.getOutputPath(file, base)
const contents = this.getFileContents(file)
const outputContents = this.parseLocals(contents)
let fileConf,
count = 0
this.writeFile(outputPath, outputContents)
console.info('Parsing:', { file, base, outputPath, outputContents: outputContents.replace("\n", "\\n") })
console.log("Template files:", templates)
for (fileConf of templates) {
let outputPath, contents, outputContents, file, base
try {
count++
file = fileConf.file
base = fileConf.base
outputPath = this.getOutputPath(file, base)
if (fs.lstatSync(file).isDirectory()) {
this.writeDirectory(outputPath, file)
continue
}
contents = this.getFileContents(file)
outputContents = this.parseLocals(contents)
console.info("Writing:", {
file,
base,
outputPath,
outputContents: outputContents.replace("\n", "\\n"),
})
this.writeFile(outputPath, outputContents)
} catch (e) {
console.error("Error while processing file:", {
file,
base,
contents,
outputPath,
outputContents,
})
throw e
}
}
if (!count) {
throw new Error('No files to scaffold!')
throw new Error("No files to scaffold!")
}
console.log('Done')
console.log("Done")
}
private writeDirectory(outputPath: string, file: any): void {
const parent = path.dirname(outputPath)
if (!fs.existsSync(parent)) {
this.writeDirectory(parent, outputPath)
}
if (!fs.existsSync(outputPath)) {
console.info("Creating directory:", {
file,
outputPath,
})
fs.mkdirSync(outputPath)
}
}
}

6269
yarn.lock

File diff suppressed because it is too large Load Diff