當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Project.saveSync方法代碼示例

本文整理匯總了TypeScript中ts-simple-ast.Project.saveSync方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Project.saveSync方法的具體用法?TypeScript Project.saveSync怎麽用?TypeScript Project.saveSync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ts-simple-ast.Project的用法示例。


在下文中一共展示了Project.saveSync方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: 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


注:本文中的ts-simple-ast.Project.saveSync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。