本文整理汇总了TypeScript中ts-simple-ast.Project.emitToMemory方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Project.emitToMemory方法的具体用法?TypeScript Project.emitToMemory怎么用?TypeScript Project.emitToMemory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ts-simple-ast.Project
的用法示例。
在下文中一共展示了Project.emitToMemory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: setupFixtures
/** setups and returns the fixtures for testing */
function setupFixtures() {
const basePath = process.cwd();
const buildPath = `${basePath}/tools/ts_library_builder/testdata`;
const outputFile = `${buildPath}/lib.output.d.ts`;
const inputProject = new Project({
compilerOptions: {
baseUrl: basePath,
declaration: true,
emitDeclarationOnly: true,
module: ModuleKind.AMD,
moduleResolution: ModuleResolutionKind.NodeJs,
strict: true,
stripInternal: true,
target: ScriptTarget.ESNext
}
});
inputProject.addExistingSourceFiles([
`${buildPath}/globals.ts`,
`${buildPath}/api.ts`
]);
const declarationProject = new Project({
compilerOptions: {},
useVirtualFileSystem: true
});
loadDtsFiles(declarationProject);
for (const { filePath, text } of inputProject.emitToMemory().getFiles()) {
declarationProject.createSourceFile(filePath, text);
}
const outputProject = new Project({
compilerOptions: {},
useVirtualFileSystem: true
});
loadDtsFiles(outputProject);
const outputSourceFile = outputProject.createSourceFile(outputFile);
const debug = true;
return {
basePath,
buildPath,
inputProject,
outputFile,
declarationProject,
outputProject,
outputSourceFile,
debug
};
}
示例2: main
export function main({
basePath,
buildPath,
inline,
debug,
outFile,
silent
}: BuildLibraryOptions): void {
if (!silent) {
console.log("-----");
console.log("build_lib");
console.log();
console.log(`basePath: "${basePath}"`);
console.log(`buildPath: "${buildPath}"`);
if (inline && inline.length) {
console.log(`inline:`);
for (const filename of inline) {
console.log(` "${filename}"`);
}
}
console.log(`debug: ${!!debug}`);
console.log(`outFile: "${outFile}"`);
console.log();
}
// the inputProject will take in the TypeScript files that are internal
// to Deno to be used to generate the library
const inputProject = new Project({
compilerOptions: {
baseUrl: basePath,
declaration: true,
emitDeclarationOnly: true,
lib: [],
module: ModuleKind.AMD,
moduleResolution: ModuleResolutionKind.NodeJs,
noLib: true,
paths: {
"*": ["*", `${buildPath}/*`]
},
preserveConstEnums: true,
strict: true,
stripInternal: true,
target: ScriptTarget.ESNext
}
});
// Add the input files we will need to generate the declarations, `globals`
// plus any modules that are importable in the runtime need to be added here
// plus the `lib.esnext` which is used as the base library
inputProject.addExistingSourceFiles([
`${basePath}/node_modules/typescript/lib/lib.esnext.d.ts`,
`${basePath}/js/deno.ts`,
`${basePath}/js/globals.ts`
]);
// emit the project, which will be only the declaration files
const inputEmitResult = inputProject.emitToMemory();
const inputDiagnostics = inputEmitResult
.getDiagnostics()
.map(d => d.compilerObject);
logDiagnostics(inputDiagnostics);
if (inputDiagnostics.length) {
process.exit(1);
}
// the declaration project will be the target for the emitted files from
// the input project, these will be used to transfer information over to
// the final library file
const declarationProject = new Project({
compilerOptions: {
baseUrl: basePath,
moduleResolution: ModuleResolutionKind.NodeJs,
noLib: true,
paths: {
"*": ["*", `${buildPath}/*`]
},
strict: true,
target: ScriptTarget.ESNext
},
useVirtualFileSystem: true
});
// we don't want to add to the declaration project any of the original
// `.ts` source files, so we need to filter those out
const jsPath = normalizeSlashes(`${basePath}/js`);
const inputProjectFiles = inputProject
.getSourceFiles()
.map(sourceFile => sourceFile.getFilePath())
.filter(filePath => !filePath.startsWith(jsPath));
loadFiles(declarationProject, inputProjectFiles);
// now we add the emitted declaration files from the input project
for (const { filePath, text } of inputEmitResult.getFiles()) {
declarationProject.createSourceFile(filePath, text);
}
// the outputProject will contain the final library file we are looking to
// build
const outputProject = new Project({
//.........这里部分代码省略.........