本文整理汇总了TypeScript中fs-extra.ensureFileSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript ensureFileSync函数的具体用法?TypeScript ensureFileSync怎么用?TypeScript ensureFileSync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ensureFileSync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: ProgressBar
(res) => {
let cfg = path.join('.jerk', 'config');
fse.ensureFileSync(cfg);
let bar = new ProgressBar(' remote [:bar] :percent :etas', { total: 100, clear: true });
let cp = child_process.spawn("rsync",
[`rsync://${remote.host}:${remote.port}/jerk/objects`, '--info=progress2',
'-E', '-hhh', '-r', '.jerk']);
cp.stdout.on('data', (stdout) => {
rsyncOutputProgressUpdate(stdout, bar);
});
let cpInterval = setInterval(() => bar.tick(0), 100);
res
.on('data', (chunk: Uint8Array) => {
let buf = new Buffer(chunk);
fs.appendFileSync(cfg, buf);
})
.on('end', () => {
cloneOnConfigFetched(cfg);
cp.on('exit', () => {
bar.tick(100);
clearInterval(cpInterval);
cloneOnObjectsFetched();
});
});
})
示例2: createConfig
function createConfig(): boolean {
if (!workspace || !workspace.rootPath) return null;
try {
fs.ensureFileSync(configPath);
return true;
} catch (err) {
return false;
}
}
示例3: verifyDatabaseFile
export function verifyDatabaseFile() {
let dir = dirHelper("notes.noam");
try {
fs.ensureFileSync(dir);
let contents = fs.readJsonSync(dir, {throws: false});
if(!contents) {
fs.writeJsonSync(dir, { notes: {} });
console.log("Initialied note database!");
} else {
console.log("Note database already exists!");
}
} catch (err) {
console.error("Note database error:", err);
}
}
示例4: verifyMetaFile
export function verifyMetaFile() {
let dir = dirHelper(".meta");
try {
fs.ensureFileSync(dir);
let contents = fs.readJsonSync(dir, {throws: false});
if(!contents) {
fs.writeJsonSync(dir, { settings: {} });
console.log("Initialized meta file")
} else {
console.log("Meta file already exists!");
}
} catch (err) {
console.error("Meta file error:", err);
}
}
示例5:
// stub
});
fs.writeJsonSync(file, object, writeOptions);
fs.writeJSONSync(file, object, writeOptions);
fs.ensureDir(path).then(() => {
// stub
});
fs.ensureDir(path, errorCallback);
fs.ensureDirSync(path);
fs.ensureFile(path).then(() => {
// stub
});
fs.ensureFile(path, errorCallback);
fs.ensureFileSync(path);
fs.ensureLink(path).then(() => {
// stub
});
fs.ensureLink(path, errorCallback);
fs.ensureLinkSync(path);
fs.ensureSymlink(path).then(() => {
// stub
});
fs.ensureSymlink(path, errorCallback);
fs.ensureSymlinkSync(path);
fs.emptyDir(path).then(() => {
// stub
});
fs.emptyDir(path, errorCallback);
fs.emptyDirSync(path);
示例6: function
fs.readFile(appRoot + "\\nodulus_modules\\" + module_name + ".zip", function (err: any, data: any) {
if (err) throw err;
var zip = new JSZip(data);
var fileData = zip.file(consts.MANIFEST_NAME).asText();
fs.writeFileSync(baseFolder + "\\" + consts.MANIFEST_NAME, fileData, 'utf8');
var manifest_file = fs.readJsonSync(baseFolder + "\\" + consts.MANIFEST_NAME, { throws: true });
if (manifest_file.files !== undefined) {
for (var i = 0; i < manifest_file.files.length; i++) {
var filename = manifest_file.files[i];
if (zip.file(filename)) {
var fileData = zip.file(filename).asText();
if (filename.indexOf('/') > -1) {
var directoryPath = (baseFolder + "\\" + filename.replace(/\//g, '\\'));
directoryPath = directoryPath.substr(0, directoryPath.lastIndexOf('\\'));
if (!fs.existsSync(directoryPath))
mkdirp.sync(directoryPath);
}
fs.writeFileSync(baseFolder + "\\" + filename, fileData, 'utf8');
}
}
}
if (manifest_file.routes !== undefined) {
for (var i = 0; i < manifest_file.routes.length; i++) {
var filename = manifest_file.routes[i].path;
if (zip.folder("routes").file(filename)) {
var fileData = zip.folder("routes").file(filename).asText();
fs.writeFileSync(serverRoot + "\\routes\\" + filename, fileData, 'utf8');
}
//attach the new route to express
app.use(module_name , require('../routes/' + filename));
}
}
if (manifest_file.scripts !== undefined) {
fs.ensureDirSync(baseFolder + "\\scripts\\");
for (var i = 0; i < manifest_file.scripts.length; i++) {
var filename = manifest_file.scripts[i];
if (zip.folder("scripts").file(filename)) {
var fileData = zip.folder("scripts").file(filename).asText();
fs.writeFileSync(baseFolder + "\\scripts\\" + filename, fileData, 'utf8');
}
}
}
var aboutfilename = "about.html";
if (zip.file(aboutfilename) !== null) {
var fileData = zip.file(aboutfilename).asText();
fs.writeFileSync(baseFolder + aboutfilename, fileData, 'utf8');
}
//register the module to the modules.json file
fs.ensureFileSync(modules_configuration_path);
var modules_file: any = {};
modules_file = fs.readJsonSync(modules_configuration_path);
if (modules_file[module_name] === undefined) {
modules_file[module_name] = {}
}
//merge the manifest into the modules.json file
if (manifest_file === null)
callback("invalid json, try using ascii file");
//update navigation
if (manifest_file.navigation)
dal.connect(function (err: any, db: any) {
for (var i = 0; i < manifest_file.navigation.length; i++) {
db.collection("Navigation").save(manifest_file.navigation[i], function (err: any, data: any) {
});
}
})
modules_file[module_name] = manifest_file;
if (manifest_file.npm !== undefined) {
var arr: Array<any> = [];
for (var x in manifest_file.npm) {
//.........这里部分代码省略.........
示例7: writeData
function writeData(path: string, data: any): void {
fs.ensureFileSync(path);
fs.writeJsonSync(path, data);
}
示例8: readdirSync
export = () => {
const pluginFolders: string[] = readdirSync(config.APP_SRC).filter(filterTrash);
const translations = {};
// Copying the files that are present in the framework
const staticFolder = join(config.FRAMEWORK_SRC, 'static');
copyNewer('**', join(config.SERVER_STATIC_SRC), { cwd: staticFolder });
copyNewer('**', config.SERVER_TEMPLATES_SRC, {
cwd: join(config.FRAMEWORK_SRC, 'server', 'framework', 'templates'),
});
// Copy the correct config file to the server folder
const configFileDest = join(config.SERVER_SRC, 'configuration.json');
let configIsNewer = true;
try {
configIsNewer = statSync(config.CONFIG_FILE_PATH).mtime > statSync(configFileDest).mtime;
} catch (e) {
// File not found
}
if (configIsNewer || config.isProdBuild) {
copySync(config.CONFIG_FILE_PATH, configFileDest);
}
const cfg = require(config.CONFIG_FILE_PATH);
const pluginCfg: { [ key: string ]: any } = {};
for (const plugin of (cfg.plugins || [])) {
if (plugin.client_configuration) {
pluginCfg[ plugin.name ] = plugin.client_configuration;
}
}
let clientConfig = JSON.stringify({
app_title: cfg.app_title,
languages: cfg.languages,
server_url: cfg.server_url,
firebase: cfg.firebase,
plugins: pluginCfg,
}, null, 2);
clientConfig = `/* tslint:disable */
export const configuration = ${clientConfig};`;
let isSame = false;
const configTsFilePath = join(config.GEN_FOLDER, 'configuration.ts');
try {
isSame = readFileSync(configTsFilePath, 'utf-8') === clientConfig;
} catch (ignored) {
}
if (!isSame) {
writeFileSync(configTsFilePath, clientConfig);
}
mergeTranslations(join(config.FRAMEWORK_SRC, 'i18n'), translations);
const moduleFile = join(config.SERVER_PLUGINS_SRC, '__init__.py');
ensureFileSync(moduleFile);
for (const pluginName of pluginFolders) {
const pluginDirectory = join(config.APP_SRC, pluginName);
const files: string[] = readdirSync(pluginDirectory).filter(filterTrash);
for (const file of files) {
const fileOrFolderPath = join(pluginDirectory, file);
const stat = statSync(fileOrFolderPath);
if (stat.isDirectory()) {
switch (file) {
case 'i18n':
mergeTranslations(fileOrFolderPath, translations);
break;
case 'plugins':
const destFolderPlugins = join(config.SERVER_PLUGINS_SRC, pluginName);
const serverFolder = join(fileOrFolderPath, pluginName);
copyNewer('**', destFolderPlugins, { cwd: serverFolder });
break;
case 'static':
const destFolderStatic = join(config.SERVER_STATIC_SRC, 'plugins', pluginName);
copyNewer('**', destFolderStatic, { cwd: fileOrFolderPath });
break;
case 'templates':
const destFolderTemplates = join(config.SERVER_TEMPLATES_SRC, 'plugins', pluginName);
const templatesFolder = join(fileOrFolderPath);
copyNewer('**', destFolderTemplates, { cwd: templatesFolder });
break;
}
}
}
}
generateTranslationFiles(translations);
};
示例9: ensureFileSync
import * as glob from 'glob';
import {ensureFileSync, writeFileSync} from 'fs-extra';
import {parseOutApiDocs} from './api-doc';
/**
* Extracts documentation from all ng-bootstrap sources to a single TS file
* used by the demo application
*/
const file = 'demo/src/api-docs.ts';
const fileNames = glob.sync('src/**/*.ts', {ignore: ['src/**/*.spec.ts', 'src/util/**']});
const json = JSON.stringify(parseOutApiDocs(fileNames), null, 2);
ensureFileSync(file);
writeFileSync(file, `const API_DOCS = ${json};\n\nexport default API_DOCS;`);
示例10: getDemoNames
getDemoNames(componentName).forEach(demoName => {
const file = `${base}/${componentName}/demos/${demoName}/stackblitz.html`;
fs.ensureFileSync(file);
fs.writeFileSync(file, generateStackblitzContent(componentName, demoName));
});