当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript fs.renameSync函数代码示例

本文整理汇总了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);
  });
开发者ID:mk-pmb,项目名称:superpowers-core,代码行数:29,代码来源:update.ts

示例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"}`);
      }
开发者ID:smart-web-rock,项目名称:angular,代码行数:32,代码来源:ngc_spec.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\//);
    });
开发者ID:ox4,项目名称:angular,代码行数:53,代码来源:ngc_spec.ts

示例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();
    }
开发者ID:victorjacobs,项目名称:chullo-client,代码行数:15,代码来源:configuration.ts

示例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)
}
开发者ID:sinclairzx81,项目名称:tasksmith-js,代码行数:30,代码来源:rename.ts

示例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)
}
开发者ID:sinclairzx81,项目名称:tasksmith-js,代码行数:35,代码来源:move.ts

示例7: reject

						process.on('close', (code) => {
							if (code === 0) {
								fs.renameSync(temp, to);
								resolve();
							}
							else reject('Shader compiler error.')
						});
开发者ID:hammeron-art,项目名称:khamake,代码行数:7,代码来源:ShaderCompiler.ts

示例8: function

 return fs.unlink(clockfile, function(err){
   if (err) {
     println("** Could not remove " + clockfile);
     process.exit(1);
   }
   return fs.renameSync(tmpfile, clockfile);
 });
开发者ID:jramb,项目名称:punch,代码行数:7,代码来源:punch.ts

示例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();
 };
开发者ID:jramb,项目名称:punch,代码行数:32,代码来源:punch.ts


注:本文中的fs.renameSync函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。