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


TypeScript Project.getFileSystem方法代码示例

本文整理汇总了TypeScript中ts-simple-ast.Project.getFileSystem方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Project.getFileSystem方法的具体用法?TypeScript Project.getFileSystem怎么用?TypeScript Project.getFileSystem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ts-simple-ast.Project的用法示例。


在下文中一共展示了Project.getFileSystem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: loadFiles

export function loadFiles(project: Project, filePaths: string[]) {
  const fileSystem = project.getFileSystem();
  for (const filePath of filePaths) {
    const fileText = readFileSync(filePath, {
      encoding: "utf8"
    });
    fileSystem.writeFileSync(filePath, fileText);
  }
}
开发者ID:F001,项目名称:deno,代码行数:9,代码来源:ast_util.ts

示例2: createProject

export function createProject(files: { fileName: string, content: string }[]): Project {
  if (!project) {
    project = new Project({
      useVirtualFileSystem: true,
      compilerOptions: {
        target: ts.ScriptTarget.ES2016,
        moduleResolution: ModuleResolutionKind.NodeJs,
        // module: ModuleKind.CommonJS,
        // noEmit: true,
        // strict: true,
        jsx: JsxEmit.React,
        jsxFactory: 'JSXAlone.createElement',
        libs: ["es2015", "dom"],
        // typeRoots: ['node_modules/@types'],
      },
    })


    const fs: FileSystemHost = project.getFileSystem();
    // fs.writeFileSync(`node_modules/typescript/lib/lib.d.ts`, lib_d_ts);
    // fs.writeFileSync(`node_modules/typescript/lib/lib.d.ts`, lib_d_ts);
    // fs.writeFileSync(`node_modules/typescript/lib/lib.es5.d.ts`, lib_es5_d_ts);
    // fs.writeFileSync(`node_modules/typescript/lib/lib.es2015.core.d.ts`, lib_es2015_core_d_ts);
    fs.writeFileSync(`node_modules/typescript/lib/lib.es2015.symbol.d.ts`, lib_es2015_symbol_d_ts);
    // fs.writeFileSync(`node_modules/typescript/lib/lib.es2015.iterable.d.ts`, lib_es2015_iterable_d_ts);
    // fs.writeFileSync(`node_modules/typescript/lib/lib.es2015.collection.d.ts`, lib_es2015_collection_d_ts);
    // fs.writeFileSync(`node_modules/typescript/lib/lib.es2015.d.ts`, lib_es2015_d_ts);
    // fs.writeFileSync(`node_modules/typescript/lib/lib.es2015.promise.d.ts`, lib_es2015_promise_d_ts);
    // fs.writeFileSync(`node_modules/typescript/lib/lib.es2015.proxy.d.ts`, lib_es2015_proxy_d_ts);
    // fs.writeFileSync(`node_modules/typescript/lib/lib.es2015.reflect.d.ts`, lib_es2015_reflect_d_ts);
    // fs.writeFileSync(`node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts`, lib_es2015_symbol_wellknown_d_ts);
    // fs.writeFileSync(`node_modules/typescript/lib/lib.scripthost.d.ts`, lib_scripthost_d_ts);
    // fs.writeFileSync(`node_modules/typescript/lib/lib.webworker.d.ts`, lib_webworker_d_ts);
    // fs.writeFileSync(`node_modules/typescript/lib/lib.webworker.importscripts.d.ts`, lib_webworker_importscripts_d_ts);

    // fs.writeFileSync(`node_modules/typescript/lib/lib.dom.d.ts`, lib_dom_d_ts);

    // fs.writeFileSync(`node_modules/jsx-alone/index.d.ts`, jsx_alone_core_d_ts);

    // project.createSourceFile('lib.d.ts', lib_d_ts)
    project.createSourceFile('lib.es5.d.ts', lib_es5_d_ts)
    project.createSourceFile('lib.es2015.core.d.ts', lib_es2015_core_d_ts)
    // project.createSourceFile('lib.es2015.symbol.d.ts', lib_es2015_symbol_d_ts)
    project.createSourceFile('lib.es2015.iterable.d.ts', lib_es2015_iterable_d_ts)
    project.createSourceFile('lib.dom.d.ts', lib_dom_d_ts)
    // fs.writeFileSync(`node_modules/typescript/lib/lib.es2015.iterable.d.ts`, lib_es2015_iterable_d_ts);

    // project.createSourceFile('node_modules/typescript/lib/lib.es5.d.ts', lib_es5_d_ts)
    // project.createSourceFile('node_modules/typescript/lib/lib.es2015.core.d.ts', lib_es2015_core_d_ts)
    // project.createSourceFile('node_modules/typescript/lib/lib.es2015.symbol.d.ts', lib_es2015_symbol_d_ts)
    // project.createSourceFile('node_modules/typescript/lib/lib.es2015.iterable.d.ts', lib_es2015_iterable_d_ts)
    // project.createSourceFile('node_modules/typescript/lib/lib.dom.d.ts', lib_dom_d_ts)

    project.createSourceFile('index.d.ts', jsx_alone_core_d_ts)



    files.forEach(f => project!.createSourceFile(f.fileName, f.content, { overwrite: true }))
  }
  else {
    files.forEach(f => {
      let sf = project!.getSourceFile(f.fileName)
      if (!sf) {
        // this only happens in tests
        sf = project!.createSourceFile(f.fileName, f.content)
      }
      else if (sf!.getText() !== f.content) {
        sf.replaceWithText(f.content)
      }
    })
  }
  project.saveSync()
  return project
}
开发者ID:cancerberoSgx,项目名称:javascript-sample-projects,代码行数:74,代码来源:ts-simple-ast.ts

示例3: main


//.........这里部分代码省略.........
  const outputProject = new Project({
    compilerOptions: {
      baseUrl: buildPath,
      moduleResolution: ModuleResolutionKind.NodeJs,
      noLib: true,
      strict: true,
      target: ScriptTarget.ESNext
    },
    useVirtualFileSystem: true
  });

  // There are files we need to load into memory, so that the project "compiles"
  loadDtsFiles(outputProject);

  // libDts is the final output file we are looking to build and we are not
  // actually creating it, only in memory at this stage.
  const libDTs = outputProject.createSourceFile(outFile);

  // Deal with `js/deno.ts`

  // `gen/msg_generated.d.ts` contains too much exported information that is not
  // part of the public API surface of Deno, so we are going to extract just the
  // information we need.
  const msgGeneratedDts = inputProject.getSourceFileOrThrow(
    `${buildPath}${MSG_GENERATED_PATH}`
  );
  const msgGeneratedDtsText = extract(msgGeneratedDts, MSG_GENERATED_ENUMS);

  // Generate a object hash of substitutions of modules to use when flattening
  const customSources = {
    [msgGeneratedDts.getFilePath()]: `${
      debug ? getSourceComment(msgGeneratedDts, basePath) : ""
    }${msgGeneratedDtsText}\n`
  };

  mergeGlobal({
    basePath,
    debug,
    declarationProject,
    filePath: `${basePath}/js/globals.ts`,
    globalVarName: "window",
    inputProject,
    ignore: ["Deno"],
    interfaceName: "Window",
    targetSourceFile: libDTs
  });

  if (!silent) {
    console.log(`Merged "globals" into global scope.`);
  }

  flatten({
    basePath,
    customSources,
    debug,
    declarationProject,
    filePath: `${basePath}/js/deno.d.ts`,
    globalInterfaceName: "Window",
    moduleName: `"deno"`,
    namespaceName: "Deno",
    targetSourceFile: libDTs
  });

  if (!silent) {
    console.log(`Created module "deno" and namespace Deno.`);
  }

  // Inline any files that were passed in, to be used to add additional libs
  // which are not part of TypeScript.
  if (inline && inline.length) {
    inlineFiles({
      basePath,
      debug,
      inline,
      targetSourceFile: libDTs
    });
  }

  // Add the preamble
  libDTs.insertStatements(0, libPreamble);

  // Check diagnostics
  checkDiagnostics(outputProject);

  // Output the final library file
  libDTs.saveSync();
  const libDTsText = prettier.format(
    outputProject.getFileSystem().readFileSync(outFile, "utf8"),
    { parser: "typescript" }
  );
  if (!silent) {
    console.log(`Outputting library to: "${outFile}"`);
    console.log(`  Length: ${libDTsText.length}`);
  }
  writeFileSync(outFile, libDTsText, { encoding: "utf8" });
  if (!silent) {
    console.log("-----");
    console.log();
  }
}
开发者ID:F001,项目名称:deno,代码行数:101,代码来源:build_library.ts


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