Skip to content

Commit 1507591

Browse files
committed
Write into a sibling directory
1 parent 86418c8 commit 1507591

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

packages/rules-unit-testing/src/public_types/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,10 @@ export interface RulesTestContext {
266266
database(databaseURL?: string): firebase.database.Database;
267267

268268
/**
269-
* Get a {@link @firebase/storage#Storage} instance for this test context. The returned Firebase JS Client SDK instance
269+
* Get a {@link @firebase/storage#FirebaseStorage} instance for this test context. The returned Firebase JS Client SDK instance
270270
* can be used with the client SDK APIs (v9 modular or v9 compat).
271271
*
272-
* See: {@link @firebase/storage#Storage}
272+
* See: {@link @firebase/storage#FirebaseStorage}
273273
* @param settings - the gs:// url to the Firebase Storage Bucket for testing. If specified,
274274
* returns a `Storage` instance for an emulated version of the bucket name
275275
* @returns a `Storage` instance configured to connect to the emulator

scripts/docgen/docgen.ts

+53
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,57 @@ async function generateDocs(forDevsite: boolean = false) {
100100
[command, 'markdown', '--input', 'temp', '--output', outputFolder],
101101
{ stdio: 'inherit' }
102102
);
103+
104+
moveRulesUnitTestingDocs(outputFolder, command);
105+
}
106+
107+
async function moveRulesUnitTestingDocs(
108+
mainDocsFolder: string,
109+
command: string
110+
) {
111+
const rulesOutputFolder = `${projectRoot}/docs-rut`;
112+
113+
// Generate from rules-unit-testing.api.json only, to get an index.md.
114+
// Hide output warnings about being unable to link to external packages.
115+
await spawn(
116+
'yarn',
117+
[
118+
command,
119+
'markdown',
120+
'--input',
121+
'packages/rules-unit-testing/temp',
122+
'--output',
123+
rulesOutputFolder
124+
],
125+
{ stdio: ['inherit', 'ignore', 'inherit'] }
126+
);
127+
128+
const rulesDocPaths = await new Promise<string[]>(resolve =>
129+
glob(`${mainDocsFolder}/rules-unit-testing.*`, (err, paths) => {
130+
if (err) throw err;
131+
resolve(paths);
132+
})
133+
);
134+
135+
// Overwrite non-index files with files generated from global docgen script,
136+
// which have links to external packages.
137+
// These paths also need to be adjusted to point to a sibling directory.
138+
for (const sourcePath of rulesDocPaths) {
139+
const destinationPath = sourcePath.replace(
140+
mainDocsFolder,
141+
rulesOutputFolder
142+
);
143+
const originalText = fs.readFileSync(sourcePath, 'utf-8');
144+
let alteredPathText = originalText.replace(
145+
/\.\/database/g,
146+
'../js/database'
147+
);
148+
alteredPathText = alteredPathText.replace(/\.\/storage/g, '../js/storage');
149+
alteredPathText = alteredPathText.replace(
150+
/\.\/firestore/g,
151+
'../js/firestore'
152+
);
153+
fs.writeFileSync(destinationPath, alteredPathText);
154+
fs.unlinkSync(sourcePath);
155+
}
103156
}

0 commit comments

Comments
 (0)