javascript - js 自動(dòng)根據(jù)配置文件生成目錄結(jié)構(gòu)
問題描述
目前在初始化組件庫,為了靈活,需要一個(gè)快速的初始化目錄結(jié)構(gòu)。目前用的angular2目錄結(jié)構(gòu)的配置文件可能如下
+ grid - col - grid - row
這樣希望能夠生成grid.config.tsgrid.module.tsindex.tsSTATION.mdcol.component.ts,col.component.html,col.component.scss,grid.component.ts,...
自己也在github找了filemap跟baya,filemap測試了,已經(jīng)不能使用了,baya文件夾可以生成,文件不能生成
自己可能打算是把模板文件做成json,用gulp去讀,不過沒有tree樹這么直觀
有沒有大神有解決辦法的,或者對我的解決思路有建議的
問題解答
回答1:做了一個(gè)淺顯的版本,對于多層文件目錄的結(jié)構(gòu)還沒有考慮好,暫時(shí)還沒用遞歸
const gulp = require(’gulp’);const fs = require(’fs’);const path = require(’path’);const mkdirp = require(’mkdirp’);function writeFile(i) { if (!fs.existsSync(i)) { fs.writeFile(i, ’’, ’utf-8’); }}function pack(i) { return [’index.ts’, ’STATION.md’].concat(i + ’.config.ts’, i + ’.module.ts’);}function createList(path) { return [].concat(path + ’.component.ts’, path + ’.component.html’, path + ’.component.scss’)}function splitFlag(value, flag) { return value.split(flag)[1].replace(/s+/g, '');}gulp.task(’try’, function () { const paths = path.join(__dirname, './tempalte'); fs.readFile(paths, ’utf-8’, function (err, data) { if (err) throw err; const array = data.split(’n’); array.forEach(f![圖片描述][1]unction (i) { if (i.indexOf(’+’) > -1) {const folder = splitFlag(i, ’+’);mkdirp(folder);pack(folder).forEach(function (item) { writeFile(folder + ’/’ + item);}) } }); var parent; array.forEach(function (i) { if (i.indexOf(’+’) > -1) {parent = splitFlag(i, ’+’); } else {const pa = parent + ’/’ + splitFlag(i, ’-’);createList(pa).forEach(function (item) { writeFile(item);}) } }); });});
自己寫一個(gè) Node 輔助函數(shù),逐級讀取配置文件,生成需要的文件和文件夾就可以啦。就遞歸一下下。
回答3:自己用fs模塊寫一個(gè)嘛,不要偷懶
相關(guān)文章:
1. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””2. 前端 - ng-view不能加載進(jìn)模板3. docker容器呢SSH為什么連不通呢?4. android clickablespan獲取選中內(nèi)容5. debian - docker依賴的aufs-tools源碼哪里可以找到啊?6. docker綁定了nginx端口 外部訪問不到7. nignx - docker內(nèi)nginx 80端口被占用8. docker網(wǎng)絡(luò)端口映射,沒有方便點(diǎn)的操作方法么?9. angular.js - angular內(nèi)容過長展開收起效果10. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?
