本文整理匯總了TypeScript中fs.mkdirSync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript mkdirSync函數的具體用法?TypeScript mkdirSync怎麽用?TypeScript mkdirSync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了mkdirSync函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: catch
options.renderer.render(options.indexFilename, config, (err, html) => {
if (err) {
console.log(err);
return;
}
try {
fs.accessSync(options.targetPath);
} catch (e) {
fs.mkdirSync(options.targetPath);
}
console.log(html);
const mifiedHtml = minify(html, {
minifyCSS: true,
minifyJS: true,
removeComments: true,
collapseWhitespace: true
});
// console.log(mifiedHtml);
fs.writeFileSync(`${options.targetPath}/index.html`, mifiedHtml);
});
示例2: it
it('should find no files when the given extension has no files', function(finished) {
fsExtra.removeSync(__dirname + '/tmp');
fs.mkdirSync(__dirname + '/tmp');
fs.writeFileSync(__dirname + '/tmp/test.value', '');
const sequence: LazySequence.Sequence<
File.AbsoluteFilePath
> = ParallelProcessQueue.findFiles(
File.getAbsoluteFilePath(__dirname + '/tmp'),
'enumValue',
);
const future: Promise.Future<
File.AbsoluteFilePath[]
> = LazySequence.evaluate(sequence);
Promise.then(function(fileLocations: File.AbsoluteFilePath[]) {
expect(fileLocations).toEqualJSON([]);
fs.unlinkSync(__dirname + '/tmp/test.value');
fs.rmdirSync(__dirname + '/tmp');
finished();
}, future);
});
示例3: resolve
return targetDir.split(sep).reduce((parentDir: any, childDir: any) => {
const curDir = resolve(baseDir, parentDir, childDir);
try {
mkdirSync(curDir);
} catch (err) {
if (err.code === 'EEXIST') {
return curDir;
}
if (err.code === 'ENOENT') {
throw new Error(`EACCES: permission denied, mkdir '${parentDir}'`);
}
const caughtErr = ['EACCES', 'EPERM', 'EISDIR'].indexOf(err.code) > -1;
if (!caughtErr || (caughtErr && targetDir === curDir)) {
throw err;
}
}
return curDir;
}, initDir);
示例4: if
const newPath = parts.reduce((tempPath: string, part: string) => {
// if (tempPath === '') {
// return part;
// }
const withoutPlus = path.join(tempPath, part);
const withPlus = path.join(tempPath, '+' + part);
if (fs.existsSync(withoutPlus)) {
return withoutPlus;
} else if (fs.existsSync(withPlus)) {
return withPlus;
}
// Folder not found, create it, and return it
const dasherizedPart = stringUtils.dasherize(part);
const dasherizedDirName = path.join(tempPath, dasherizedPart);
fs.mkdirSync(dasherizedDirName);
return dasherizedDirName;
}, parsedOutputPath.root);
示例5: startEnsimeServer
// Start ensime server. If classpath file is out of date, make an update first
function startEnsimeServer(parsedDotEnsime: DotEnsime) {
log.debug('starting Ensime server for', parsedDotEnsime.rootDir)
vscode.window.showInformationMessage("Starting Ensime server")
if (!fs.existsSync(parsedDotEnsime.cacheDir)) {
fs.mkdirSync(parsedDotEnsime.cacheDir)
}
const ensimeConfig = vscode.workspace.getConfiguration('Ensime')
const ensimeServerVersion = ensimeConfig.get('ensimeServerVersion').toString()
const ensimeServerFlags = ensimeConfig.get('ensimeServerFlags').toString()
const assemblyJar = mkAssemblyJarFilename(parsedDotEnsime.scalaEdition, ensimeServerVersion)
if(fs.existsSync(assemblyJar)) {
log.debug('starting from assemblyJar')
return startServerFromAssemblyJar(assemblyJar, parsedDotEnsime, ensimeServerVersion, ensimeServerFlags)
} else {
log.debug('starting from classpath file (coursier)')
let cpF = mkClasspathFilename(parsedDotEnsime.scalaVersion, ensimeServerVersion)
const startFromCPFile = () => startServerFromFile(cpF, parsedDotEnsime, ensimeServerVersion, ensimeServerFlags)
if(!classpathFileOk(cpF)) {
log.debug('No classpath file found matching versions, creating with coursier')
return fileUtils.ensureExists(packageDir()).then((packageDir) => {
const p = updateEnsimeServerWithCoursier(parsedDotEnsime, ensimeServerVersion, cpF)
return p.then(
(thang) => {
log.debug('got thang', thang, 'starting from cp file')
return startFromCPFile();
},
(failure) => {
log.error(failure)
}
)
});
} else {
log.debug('classpath file ok, using')
return startFromCPFile()
}
}
}
示例6: saveEvents
function saveEvents() {
const tempFolder = path.join(__dirname, '../temp');
console.log(tempFolder);
if (!fs.existsSync(tempFolder)) {
fs.mkdirSync(tempFolder);
}
const time = new Date()
.toISOString()
.replace(/[-|:]/g, '_')
.replace(/\..+/, '');
const fileName = `replay_${time}.html`;
const content = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Record @${time}</title>
<link rel="stylesheet" href="../dist/rrweb.min.css" />
</head>
<body>
<script src="../dist/rrweb.min.js"></script>
<script>
/*<!--*/
const events = ${JSON.stringify(events).replace(
/<\/script>/g,
'<\\/script>',
)};
/*-->*/
const replayer = new rrweb.Replayer(events);
replayer.play();
</script>
</body>
</html>
`;
const savePath = path.resolve(tempFolder, fileName);
fs.writeFileSync(savePath, content);
console.log(`Saved at ${savePath}`);
}
示例7: start
public start() {
try {
if (!fs.existsSync(IMAGE_PATH)) {
fs.mkdirSync(IMAGE_PATH);
}
} catch (e) {
logger.exception(e);
return;
}
if (!this.cameraProcess) {
let fullPath = `${IMAGE_PATH}/${IMAGE_NAME}`;
this.cameraProcess = spawn("raspistill", [
"-rot", "0",
"-w", "640",
"-h", "480",
"-q", "5",
"-o", fullPath,
"-tl", "100",
"-t", "9999999",
"-th", "0:0:0"
]);
this.cameraProcess.on("exit", () => {
console.log("camera process has stopped");
this.cameraProcess = null;
});
}
if (!this.streamingProcess) {
this.streamingProcess = spawn("mjpg_streamer", [
"-i", `/usr/local/lib/input_file.so -f ${IMAGE_PATH} -n ${IMAGE_NAME}`,
"-o", "/usr/local/lib/output_http.so -w /usr/local/www"
]);
this.streamingProcess.on("exit", () => {
console.log("streaming process has stopped");
this.streamingProcess = null;
});
}
}
示例8: run
/**
* Create the text files and then zip them up using a CLI command that hopefully exists.
*/
public async run(argv: string[]): Promise<void> {
const filename = argv[3] || "./gtfs.zip";
if (fs.existsSync(filename)) {
fs.unlinkSync(filename);
}
argv[3] = "/tmp/gtfs/";
if (!fs.existsSync(argv[3])) {
fs.mkdirSync(argv[3]);
}
await this.command.run(argv);
// when node tells you it's finished writing a file, it's lying.
setTimeout(() => {
console.log("Writing " + filename);
execSync(`zip -j ${filename} ${argv[3]}/*.txt`);
}, 1000);
}
示例9: mkdirp
function mkdirp(dir: string) {
if (!dir) {
return;
}
try {
mkdirSync(dir);
}
catch (error) {
// A parent directory didn't exist, create it
if (error.code === 'ENOENT') {
mkdirp(dirname(dir));
mkdirp(dir);
}
else {
if (!statSync(dir).isDirectory()) {
throw error;
}
}
}
}
示例10: beforeEach
beforeEach("set logger", async function () {
if (!this.currentTest)
return;
const logFolder = process.env.DC_TEST_LOGS || path.join(ext.extensionPath, ".dart_code_test_logs");
if (!fs.existsSync(logFolder))
fs.mkdirSync(logFolder);
const logFile = filenameSafe(this.currentTest.fullTitle()) + ".txt";
const logPath = path.join(logFolder, logFile);
const logger = logTo(logPath);
deferUntilLast(async (testResult?: "passed" | "failed") => {
await logger.dispose();
// On CI, we delete logs for passing tests to save money on S3 :-)
if (process.env.CI && testResult === "passed") {
try {
fs.unlinkSync(logPath);
} catch { }
}
});
});