vue-ant-patterns
Version:
vue-ant-patterns
49 lines (44 loc) • 1.67 kB
JavaScript
const fs = require('fs-extra');
const path = require('path');
const mkdirp = require('mkdirp');
const readline = require('readline');
const rimraf = require('rimraf');
const babel = require('babel-core');
// const Mustache = require('mustache');
// const debug = require('debug');
// const { fork, spawn } = require('child_process');
class GeneratorFiles {
constructor(opts = {}) {
this.cwd = path.join(__dirname, '../');
this._site = path.join(this.cwd, '_site');
this._examples = path.join(this._site, 'examples');
}
apply(compiler) {
const ID = 'generator-test-txt';
const _ = this;
const { _site, _examples, cwd } = this;
compiler.hooks.done.tap(ID, compilation => {
const txtFile = fs.readFileSync(path.join(cwd, 'site/devDemoChildren.js'), 'utf8');
// 生成 text, 用于 查看源码
// const rlDemoText = readline.createInterface({
// input: fs.createReadStream(path.join(cwd, 'site/devDemoChildren.js')),
// });
// rlDemoText.on('line', line => {
// if (line.indexOf('path:') > -1) {
// const name = line.split("'")[1].split("'")[0];
// const filePath = path.join(_site, name);
// const repName = name.replace('/examples/', '');
// const examplesPath = _examples;
// rimraf.sync(filePath);
// mkdirp(examplesPath, function() {
// fs.writeFileSync(
// path.join(examplesPath, `${repName}.txt`),
// fs.readFileSync(path.join(cwd, `site/dev-demo`, `${repName}.vue`)),
// );
// });
// }
// });
});
}
}
module.exports = GeneratorFiles;