@@ -18,6 +18,15 @@ const RE_END_SNIPPET = /\[END\s+([A-Za-z_]+)\s*\]/;
18
18
// TODO: Handle multiline imports?
19
19
const RE_REQUIRE = / c o n s t { ( .+ ?) } = r e q u i r e \( ( .+ ?) \) / ;
20
20
21
+ // Regex for ref docs URLs
22
+ // eg. "https://firebase.google.com/docs/reference/js/v8/firebase.User"
23
+ const RE_REF_DOCS = / h t t p s : \/ \/ f i r e b a s e \. g o o g l e \. c o m \/ d o c s \/ r e f e r e n c e \/ j s \/ ( .* ) / ;
24
+
25
+ // Maps v8 ref docs URLs to their v9 counterpart
26
+ const REF_DOCS_MAPPINGS : { [ key : string ] : string } = {
27
+ "v8/firebase.User" : "auth.user"
28
+ } ;
29
+
21
30
type SnippetsConfig = {
22
31
enabled : boolean ;
23
32
suffix : string ;
@@ -30,6 +39,26 @@ function isBlank(line: string) {
30
39
return line . trim ( ) . length === 0 ;
31
40
}
32
41
42
+ /**
43
+ * Replace all v8 ref doc urls with their v9 counterpart.
44
+ */
45
+ function replaceRefDocsUrls ( lines : string [ ] ) {
46
+ const outputLines = [ ] ;
47
+ for ( const line of lines ) {
48
+ if ( line . match ( RE_REF_DOCS ) ) {
49
+ outputLines . push ( line . replace ( RE_REF_DOCS , ( match : string , p1 ?: string ) => {
50
+ if ( p1 ) {
51
+ return `https://firebase.google.com/docs/reference/js/${ REF_DOCS_MAPPINGS [ p1 ] } ` ;
52
+ }
53
+ return match ;
54
+ } ) ) ;
55
+ } else {
56
+ outputLines . push ( line ) ;
57
+ }
58
+ }
59
+ return outputLines ;
60
+ }
61
+
33
62
/**
34
63
* Replace all const { foo } = require('bar') with import { foo } from 'bar';
35
64
*/
@@ -119,6 +148,7 @@ function processSnippet(
119
148
outputLines = addSuffixToSnippetNames ( outputLines , snippetSuffix ) ;
120
149
outputLines = adjustIndentation ( outputLines ) ;
121
150
outputLines = removeFirstLineAfterComments ( outputLines ) ;
151
+ outputLines = replaceRefDocsUrls ( outputLines ) ;
122
152
123
153
// Add a preamble to every snippet
124
154
const preambleLines = [
0 commit comments