@@ -7,7 +7,8 @@ const { rollup } = require('rollup');
77const typescript = require ( '@rollup/plugin-typescript' ) ;
88const { default : dts } = require ( 'rollup-plugin-dts' ) ;
99const { existsSync } = require ( 'fs' ) ;
10- const { writeFile, mkdir, cp, readFile } = require ( 'fs/promises' ) ;
10+ const { writeFile, mkdir, cp } = require ( 'fs/promises' ) ;
11+ // const { readFile } = require('fs/promises');
1112
1213class Package {
1314 constructor ( filePath ) {
@@ -23,8 +24,8 @@ class Package {
2324 this . outPath . name === 'index' ? this . outPath . dir : `${ this . outPath . dir } /${ this . outPath . name } ` ;
2425
2526 this . rollup = {
26- dir : `docs-out /${ this . outPath . dir } ` ,
27- name : `rollup. ${ this . name . replace ( '/' , '.' ) } ` ,
27+ dir : `tmp/rollup-types /${ this . outPath . dir } ` ,
28+ name : this . outPath . name ,
2829 ext : '.d.ts' ,
2930 } ;
3031 }
@@ -49,9 +50,9 @@ class Package {
4950 }
5051}
5152
52- async function build ( package ) {
53+ async function build ( path ) {
5354 let bundle = await rollup ( {
54- input : package . absolutePath ,
55+ input : path ,
5556 plugins : [
5657 typescript ( {
5758 tsconfig : './tsconfig.json' ,
@@ -61,16 +62,16 @@ async function build(package) {
6162 declarationMap : true ,
6263 sourceMap : true ,
6364 incremental : true ,
64- outDir : `temp` ,
65- declarationDir : `temp` ,
65+ outDir : 'tmp/build-types' ,
66+ declarationDir : 'tmp/build-types' ,
6667 } ,
6768 } ) ,
6869 ] ,
6970 } ) ;
7071
7172 await bundle . write ( {
7273 output : {
73- dir : 'temp ' ,
74+ dir : 'tmp/build-types ' ,
7475 format : 'es' ,
7576 sourcemap : true ,
7677 } ,
@@ -86,14 +87,14 @@ async function rollupTypes(package) {
8687 try {
8788 const bundle = await rollup ( {
8889 input : path . format ( {
89- dir : `${ __dirname } /temp /${ package . outPath . dir } ` ,
90+ dir : `${ __dirname } /tmp/build-types /${ package . outPath . dir } ` ,
9091 name : package . outPath . name ,
9192 ext : '.d.ts' ,
9293 } ) ,
9394 plugins : [
9495 dts ( {
9596 compilerOptions : {
96- baseUrl : `temp /${ package . outPath . dir } ` ,
97+ baseUrl : `tmp/build-types /${ package . outPath . dir } ` ,
9798 paths : {
9899 [ `${ package . outPath . dir } /*` ] : [ '*' ] ,
99100 '@ember/-internals/*' : [ `${ relativeTemp } /@ember/-internals/*` ] ,
@@ -114,27 +115,23 @@ async function rollupTypes(package) {
114115 }
115116}
116117
117- function docs ( package ) {
118- console . log ( 'DOCS ' , package . absolutePath ) ;
118+ function extract ( package ) {
119+ console . log ( 'EXTRACT ' , package . absolutePath ) ;
119120 try {
120121 const config = ExtractorConfig . prepare ( {
121122 configObject : {
122123 mainEntryPointFilePath : `<projectFolder>/${ path . format ( package . rollup ) } ` ,
123124 apiReport : {
124125 enabled : true ,
125126 reportFileName : `${ package . fileSafeName } .api.md` ,
126- reportFolder : 'docs-out' ,
127- reportTempFolder : 'docs-out' ,
128- } ,
129- docModel : {
130- enabled : true ,
131- apiJsonFilePath : `<projectFolder>/docs-out/${ package . fileSafeName } .api.json` ,
127+ reportFolder : 'api-report' ,
128+ reportTempFolder : 'api-report' ,
132129 } ,
133130 dtsRollup : {
134131 enabled : true ,
135- untrimmedFilePath : `<projectFolder>/types/${ package . fileSafeName } .untrimmed.d.ts` ,
136- betaTrimmedFilePath : `<projectFolder>/types/${ package . fileSafeName } .beta.d.ts` ,
137- publicTrimmedFilePath : `<projectFolder>/types/${ package . fileSafeName } .release.d.ts` ,
132+ untrimmedFilePath : `<projectFolder>/tmp/trimmed- types/${ package . fileSafeName } .untrimmed.d.ts` ,
133+ betaTrimmedFilePath : `<projectFolder>/tmp/trimmed- types/${ package . fileSafeName } .beta.d.ts` ,
134+ publicTrimmedFilePath : `<projectFolder>/tmp/trimmed- types/${ package . fileSafeName } .release.d.ts` ,
138135 } ,
139136 compiler : {
140137 tsconfigFilePath : '<projectFolder>/tsconfig.json' ,
@@ -212,7 +209,7 @@ async function run() {
212209 // '@ember/runloop',
213210 // '@ember/service',
214211 // '@ember/template',
215- // '@ember/utils',
212+ '@ember/utils' ,
216213 // '@ember/version',
217214 // 'ember',
218215 ] . map ( ( p ) => {
@@ -222,23 +219,23 @@ async function run() {
222219 return new Package ( path ) ;
223220 } ) ;
224221
225- await mkdir ( 'temp' ) ;
222+ await mkdir ( 'tmp/build-types' , { recursive : true } ) ;
226223 await writeFile (
227- 'temp /index.ts' ,
224+ 'tmp/build-types /index.ts' ,
228225 packages . map ( ( p , idx ) => `import _PKG${ idx } from '${ p . name } ';` ) . join ( '\n' )
229226 ) ;
230227
231- await build ( new Package ( 'temp/ index.ts') ) ;
228+ await build ( 'tmp/build-types/ index.ts') ;
232229
230+ // Copy over all pre-existing .d.ts paths
233231 for await ( const item of klaw ( path . join ( __dirname , 'packages' ) ) ) {
234232 if ( item . stats . isFile ( ) ) {
235233 if (
236234 item . path . endsWith ( '.d.ts' ) &&
237235 ! item . path . includes ( '/tests/' ) &&
238236 ! item . path . includes ( '/type-tests/' )
239237 ) {
240- let dest = `temp/${ path . relative ( `${ __dirname } /packages` , item . path ) } ` ;
241- // await mkdirp(path.dirname(dest));
238+ let dest = `tmp/build-types/${ path . relative ( `${ __dirname } /packages` , item . path ) } ` ;
242239 await cp ( item . path , dest ) ;
243240 }
244241 }
@@ -250,16 +247,26 @@ async function run() {
250247
251248 // Ideally we'd parallelize this. My first go didn't work.
252249 for ( let pkg of packages ) {
253- await docs ( pkg ) ;
250+ await extract ( pkg ) ;
254251 }
255252
256- // https://github.com/microsoft/rushstack/issues/2895
257- for await ( const item of klaw ( path . join ( __dirname , 'docs-out' ) ) ) {
258- if ( item . stats . isFile ( ) ) {
259- let data = await readFile ( item . path ) ;
260- await writeFile ( item . path , data . toString ( ) . replace ( / _ 2 / g, '' ) ) ;
253+ for ( let pkg of packages ) {
254+ for ( let r of [ 'beta' , 'release' , 'untrimmed' ] ) {
255+ await mkdir ( `types/${ r } /${ pkg . outPath . dir } ` , { recursive : true } ) ;
256+ await cp (
257+ `tmp/trimmed-types/${ pkg . fileSafeName } .${ r } .d.ts` ,
258+ `types/${ r } /${ pkg . outPath . dir } /${ pkg . outPath . name } .d.ts`
259+ ) ;
261260 }
262261 }
262+
263+ // // https://github.com/microsoft/rushstack/issues/2895
264+ // for await (const item of klaw(path.join(__dirname, 'docs-out'))) {
265+ // if (item.stats.isFile()) {
266+ // let data = await readFile(item.path);
267+ // await writeFile(item.path, data.toString().replace(/_2/g, ''));
268+ // }
269+ // }
263270}
264271
265272run ( ) ;
0 commit comments