本文整理汇总了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
}