本文整理匯總了TypeScript中fs.renameSync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript renameSync函數的具體用法?TypeScript renameSync怎麽用?TypeScript renameSync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了renameSync函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
utils.downloadRelease(downloadURL, newSystemPath, (err) => {
if (err != null) utils.emitError("Failed to update the system.", err);
for (const oldItem of fs.readdirSync(systemPath)) {
if (oldItem === "plugins") {
for (const pluginAuthor of fs.readdirSync(`${systemPath}/plugins`)) {
if (utils.builtInPluginAuthors.indexOf(pluginAuthor) === -1) continue;
rimraf.sync(`${systemPath}/plugins/${pluginAuthor}`);
}
} else {
rimraf.sync(`${systemPath}/${oldItem}`);
}
}
for (const newItem of fs.readdirSync(newSystemPath)) {
if (newItem === "plugins") {
for (const pluginAuthor of fs.readdirSync(`${newSystemPath}/plugins`)) {
if (utils.builtInPluginAuthors.indexOf(pluginAuthor) === -1) continue;
fs.renameSync(`${newSystemPath}/plugins/${pluginAuthor}`, `${systemPath}/plugins/${pluginAuthor}`);
}
} else {
fs.renameSync(`${newSystemPath}/${newItem}`, `${systemPath}/${newItem}`);
}
}
rimraf.sync(newSystemPath);
console.log(`System successfully updated.`);
process.exit(0);
});
示例2: createFlatModuleInNodeModules
function createFlatModuleInNodeModules() {
// compile the flat module
writeFlatModule('index.js');
expect(main(['-p', basePath], errorSpy)).toBe(0);
// move the flat module output into node_modules
const flatModuleNodeModulesPath = path.resolve(basePath, 'node_modules', 'flat_module');
fs.renameSync(outDir, flatModuleNodeModulesPath);
fs.renameSync(
path.resolve(basePath, 'src/flat.component.html'),
path.resolve(flatModuleNodeModulesPath, 'src/flat.component.html'));
// and remove the sources.
fs.renameSync(path.resolve(basePath, 'src'), path.resolve(basePath, 'flat_module_src'));
fs.unlinkSync(path.resolve(basePath, 'public-api.ts'));
// add a flatModuleIndexRedirect
write('node_modules/flat_module/redirect.metadata.json', `{
"__symbolic": "module",
"version": 3,
"metadata": {},
"exports": [
{
"from": "./index"
}
],
"flatModuleIndexRedirect": true,
"importAs": "flat_module"
}`);
write('node_modules/flat_module/redirect.d.ts', `export * from './index';`);
// add a package.json to use the redirect
write('node_modules/flat_module/package.json', `{"typings": "./redirect.d.ts"}`);
}
示例3: it
it('should use the importAs for flat libraries instead of deep imports', () => {
// compile the flat module
writeFlatModule('index.js');
expect(main(['-p', basePath], errorSpy)).toBe(0);
// move the flat module output into node_modules
const flatModuleNodeModulesPath = path.resolve(basePath, 'node_modules', 'flat_module');
fs.renameSync(outDir, flatModuleNodeModulesPath);
fs.renameSync(
path.resolve(basePath, 'src/flat.component.html'),
path.resolve(flatModuleNodeModulesPath, 'src/flat.component.html'));
// add a package.json
fs.writeFileSync(
path.resolve(flatModuleNodeModulesPath, 'package.json'), `{"typings": "./index.d.ts"}`);
// and remove the sources.
fs.renameSync(path.resolve(basePath, 'src'), path.resolve(basePath, 'flat_module_src'));
fs.unlinkSync(path.resolve(basePath, 'public-api.ts'));
writeConfig(`
{
"extends": "./tsconfig-base.json",
"files": ["index.ts"]
}
`);
write('index.ts', `
import {NgModule} from '@angular/core';
import {FlatModule} from 'flat_module';
@NgModule({
imports: [FlatModule]
})
export class MyModule {}
`);
expect(main(['-p', basePath], errorSpy)).toBe(0);
shouldExist('index.js');
const summary =
fs.readFileSync(path.resolve(basePath, 'built', 'index.ngsummary.json')).toString();
// reference to the module itself
expect(summary).toMatch(/"filePath":"flat_module"/);
// no reference to a deep file
expect(summary).not.toMatch(/"filePath":"flat_module\//);
const factory =
fs.readFileSync(path.resolve(basePath, 'built', 'index.ngfactory.js')).toString();
// reference to the module itself
expect(factory).toMatch(/from "flat_module"/);
// no reference to a deep file
expect(factory).not.toMatch(/from "flat_module\//);
});
示例4: switchEnvironment
public static switchEnvironment(fromEnv: string, toEnv: string): Promise<Configuration> {
let fromConfig = `${Configuration.path()}.${fromEnv}`;
let toConfig = `${Configuration.path()}.${toEnv}`;
try {
fs.accessSync(toConfig);
} catch (e) {
return Configuration.read();
}
fs.renameSync(Configuration.path(), fromConfig);
fs.renameSync(toConfig, Configuration.path());
return Configuration.read();
}
示例5: rename
export function rename(directory: string, newname: string, log: Function = function() {}) {
if(newname.indexOf("/") !== -1 || newname.indexOf("\\") !== -1) {
throw Error("folder newname argument cannot be a path.")
}
let sourceEntry = scan_entry(path.resolve(directory))
let targetEntry = scan_entry(path.join(sourceEntry.dirname, newname))
switch(sourceEntry.type){
case "null":
throw Error(`unable to rename directory ${sourceEntry.fullname} because it doesn't exist.`)
case "file":
throw Error(`unable to rename directory ${sourceEntry.fullname} because it is a file.`)
case "directory":
break;
}
switch(targetEntry.type) {
case "file":
throw Error(`unable to rename directory ${sourceEntry.fullname} to ${targetEntry.fullname} because an existing file of that name already exists.`)
case "directory":
throw Error(`unable to rename directory ${sourceEntry.fullname} to ${targetEntry.fullname} because an existing directory of that name already exists.`)
case "null":
break;
}
log(`renaming: ${sourceEntry.fullname} to ${targetEntry.basename}`)
fs.renameSync(sourceEntry.fullname, targetEntry.fullname)
}
示例6: move
export function move(target: string, directory: string, log: Function = function() {}): void {
let targetEntry = scan_entry(path.resolve(target))
let directoryEntry = scan_entry(path.resolve(directory))
let moveEntry = scan_entry(path.resolve(path.join(directoryEntry.fullname, targetEntry.basename)))
switch(targetEntry.type) {
case "directory":
throw Error(`unable to move file ${targetEntry.fullname} because it is a directory.`)
case "null":
throw Error(`unable to move file ${targetEntry.fullname} because it does not exist.`)
case "file":
break;
}
switch(directoryEntry.type) {
case "null":
throw Error(`unable to move file ${targetEntry.fullname} into ${directoryEntry.type} because it does not exist.`)
case "file":
throw Error(`unable to move file ${targetEntry.fullname} into ${directoryEntry.type} because it is a file.`)
case "directory":
break;
}
switch(moveEntry.type) {
case "directory":
throw Error(`unable to move file ${targetEntry.fullname} into ${directoryEntry.type} because a directory of this name already exists in the target directory.`)
case "file":
throw Error(`unable to move file ${targetEntry.fullname} into ${directoryEntry.type} because a file of this name already exists in the target directory.`)
case "null":
break;
}
log(`moving: ${targetEntry.fullname} to ${moveEntry.fullname}`)
fs.renameSync(targetEntry.fullname, moveEntry.fullname)
}
示例7: reject
process.on('close', (code) => {
if (code === 0) {
fs.renameSync(temp, to);
resolve();
}
else reject('Shader compiler error.')
});
示例8: function
return fs.unlink(clockfile, function(err){
if (err) {
println("** Could not remove " + clockfile);
process.exit(1);
}
return fs.renameSync(tmpfile, clockfile);
});
示例9: saveTimeData
function saveTimeData(data){
var clockfile, backupfile, tmpfile, out, i$, len$, it;
clockfile = config.clockfile;
backupfile = clockfile + config.backupfile;
tmpfile = clockfile + ("-" + clockText(startDate).replace(/[^0-9]/g, ''));
if (!fs.existsSync(backupfile)) {
fs.renameSync(clockfile, backupfile);
}
out = fs.createWriteStream(tmpfile);
out.on('error', function(it){
println("Error: " + it);
return process.exit(1);
});
out.on('finish', function(){
if (fs.existsSync(clockfile)) {
return fs.unlink(clockfile, function(err){
if (err) {
println("** Could not remove " + clockfile);
process.exit(1);
}
return fs.renameSync(tmpfile, clockfile);
});
} else {
return fs.renameSync(tmpfile, clockfile);
}
});
for (i$ = 0, len$ = data.length; i$ < len$; ++i$) {
it = data[i$];
out.write(generateLine(it) + "\n");
}
return out.end();
};