function cleanJS() { for (const filename of jsPaths) { const content = fs.readFileSync(filename, "utf8") process.once("exit", () => fs.outputFileSync(filename, content)) fs.outputFileSync(filename, minifyJS(content)) } }
function cleanPackageJSON() { const content = fs.readFileSync(pkgPath, "utf8") process.once("exit", () => fs.outputFileSync(pkgPath, content)) const pkgJSON = JSON.parse(content) for (const field of fieldsToRemove) { Reflect.deleteProperty(pkgJSON, field) } pkgJSON.scripts = defaultScripts fs.outputFileSync(pkgPath, fleece.patch(content, pkgJSON)) }
function cleanReadme() { const content = fs.readFileSync(readmePath, "utf8") process.once("exit", () => fs.outputFileSync(readmePath, content)) fs.outputFileSync(readmePath, content.replace(tableRegExp, minifyHTML)) }
function renderBranding () { var brandingElement = React.createElement(BrandingTemplate, {branding: styleGuideConfig.pages.branding}) var brandingMarkup = ReactDOMServer.renderToStaticMarkup(brandingElement) var shellElement = React.createElement(ShellTemplate, { title: 'Branding', markup: brandingMarkup }) var html = ReactDOMServer.renderToStaticMarkup(shellElement) html = '<!doctype html>' + html fse.outputFileSync('./build/isg/branding/index.html', html) }
/** * @chaining * Generates and then saves metadata to specified file. Doesn't check if file exists. * * @param {String} destination File metadata will be written to * @return {PlatformJson} PlatformJson instance */ generateAndSaveMetadata (destination) { fs.outputFileSync(destination, this.generateMetadata()); return this; }
const getWebRouterEntryFile = (entry: string, router: string) => { const entryFile = path.resolve(this.vueTemplateFloder, this.entryFileName) const routerFile = path.resolve(this.vueTemplateFloder, this.routerFileName) fse.outputFileSync(entryFile, getEntryFileContent(entry, routerFile)) fse.outputFileSync(routerFile, getRouterFileContent(router)) return { index: entryFile, } }
it('should filter based on both path and stats', () => { const f1 = path.join(TEST_DIR, 'foo.js') const f2 = path.join(TEST_DIR, 'bar.js') fs.outputFileSync(f1, 'test file 1 contents') fs.outputFileSync(f2, 'test file 2 contents') const paths = [{path: f1, stats: fs.statSync(f1)}] const filterFunc = i => i.path === TEST_DIR || (path.basename(i.path).indexOf('foo') > -1 && i.stats.isFile() && i.stats.size > 0) const items = klawSync(TEST_DIR, {filter: filterFunc}) assert.strictEqual(items.length, paths.length) items.forEach((p, i) => { assert.deepStrictEqual(p, paths[i]) assert.strictEqual(p.path, paths[i].path) assert.deepStrictEqual(p.stats, paths[i].stats) }) })
function copyDirContent (source, target) { if (!fs.existsSync(source)) return // Create target dir if necessary. createDir(target) // Copy all files from source to target. findAllFiles(source).forEach((name) => { const nameWithoutSource = path.relative(source, name) const targetFile = path.join(target, nameWithoutSource) fse.outputFileSync(targetFile, fs.readFileSync(name)) }) }
function renderIntro () { var introElement = React.createElement(IntroTemplate) var introMarkup = ReactDOMServer.renderToStaticMarkup(introElement) var shellElement = React.createElement(ShellTemplate, { title: 'Intro', markup: introMarkup }) var html = ReactDOMServer.renderToStaticMarkup(shellElement) html = '<!doctype html>' + html fse.outputFileSync('./build/isg/intro/index.html', html) fse.outputFileSync('./build/isg/index.html', '<!doctype html><html><head><meta http-equiv="refresh" content="0; url=intro" /></head><body></body></html>') }
// 写入文件 function outputFile (file, content) { console.log('生成页面: %s', file.slice(outputDir.length + 1)); fse.outputFileSync(file, content); }
async function addRoutes(dirPath) { const data = await fs.readFileSync(`${dirPath}/app.js`, "utf8"); const requireMongoose = data.replace(/^#mongoose$/gm, "const mongoose = require('mongoose')"); const connectMongoose = requireMongoose.replace( /^#connectMongoose$/gm, "mongoose.connect(process.env.DATABASE)\nmongoose.connection.on('error', (err) => {\n console.log(err.message)\n})\nrequire('../models')" ); await fs.outputFileSync(`${dirPath}/app.js`, connectMongoose); }
function cleanPackageJSON() { const content = fs.readFileSync(pkgPath, "utf8") process.once("exit", () => fs.outputFileSync(pkgPath, content)) const pkgJSON = JSON.parse(content) fieldsToRemove.forEach((field) => Reflect.deleteProperty(pkgJSON, field)) pkgJSON.scripts = defaultScripts fs.outputFileSync(pkgPath, fleece.patch(content, pkgJSON)) }
async function importFile(dirPath) { const data = await fs.readFileSync(`${dirPath}/app.js`, "utf8"); const result = data.replace(/^#dotenv$/gm, "require('dotenv').config({ path: 'variables.env' })"); await fs.outputFileSync(`${dirPath}/app.js`, result); }
function renderScreens () { var screensElement = React.createElement(ScreensTemplate, {data: data}) var screensMarkup = ReactDOMServer.renderToStaticMarkup(screensElement) var shellElement = React.createElement(ShellTemplate, { title: 'Project Screens', markup: screensMarkup }) var html = ReactDOMServer.renderToStaticMarkup(shellElement) html = '<!doctype html>' + html fse.outputFileSync('./build/isg/screens/index.html', html) }
function cleanJS() { for (const filename of jsPaths) { const content = fs.readFileSync(filename, "utf8") process.once("exit", () => fs.outputFileSync(filename, content)) fs.outputFileSync(filename, minifyJS(content)) } }