1
1
import * as fs from "fs-extra" ;
2
2
3
3
async function main ( ) {
4
- await copyGettingStarted ( ) ;
5
- await copyCachingDocs ( ) ;
6
- await copyStorageAdapters ( ) ;
7
- await copyCompressionDocs ( ) ;
8
- await copyTestSuite ( ) ;
4
+
5
+ console . log ( "packages path:" + getRelativePackagePath ( ) ) ;
6
+ console . log ( "docs path:" + getRelativeDocsPath ( ) ) ;
7
+
8
+ await copyGettingStarted ( ) ;
9
+ await copyCachingDocs ( ) ;
10
+ await copyStorageAdapters ( ) ;
11
+ await copyCompressionDocs ( ) ;
12
+ await copyTestSuite ( ) ;
9
13
} ;
10
14
11
15
async function copyGettingStarted ( ) {
12
- const originalFileText = await fs . readFile ( "../../docs/getting-started/index.md" , "utf8" ) ;
16
+ const docsPath = getRelativeDocsPath ( ) ;
17
+ const packagesPath = getRelativePackagePath ( ) ;
18
+ const originalFileText = await fs . readFile ( `${ docsPath } /getting-started/index.md` , "utf8" ) ;
13
19
let newFileText = "---\n" ;
14
20
newFileText += `title: 'Getting Started Guide'\n` ;
15
21
newFileText += `permalink: /docs/\n` ;
@@ -19,28 +25,32 @@ async function copyGettingStarted() {
19
25
newFileText += originalFileText ;
20
26
21
27
console . log ( "Adding Getting Started Guide" ) ;
22
- await fs . writeFile ( " site/docs/index.md" , newFileText ) ;
28
+ await fs . writeFile ( ` ${ packagesPath } /website/ site/docs/index.md` , newFileText ) ;
23
29
}
24
30
25
31
async function copyCachingDocs ( ) {
26
- console . log ( "Adding in Caching Docs" ) ;
27
- await fs . copy ( "../../docs/caching/" , "site/docs/caching" ) ;
32
+ const docsPath = getRelativeDocsPath ( ) ;
33
+ const packagesPath = getRelativePackagePath ( ) ;
34
+ console . log ( "Adding Caching Docs" ) ;
35
+ await fs . copy ( `${ docsPath } /caching/` , `${ packagesPath } /website/site/docs/caching` ) ;
28
36
}
29
37
30
38
async function copyStorageAdapters ( ) {
31
- const storageAdapters = await fs . readdir ( "../../packages" ) ;
39
+ const packagesPath = getRelativePackagePath ( ) ;
40
+ const storageAdapters = await fs . readdir ( `${ packagesPath } ` ) ;
32
41
const filterList = [ "keyv" , "website" , "compress-brotli" , "compress-gzip" , "test-suite" ] ;
33
42
34
43
for ( const storageAdapter of storageAdapters ) {
35
44
if ( ( filterList . indexOf ( storageAdapter ) > - 1 ) !== true ) {
36
45
console . log ( "Adding storage adapter: " + storageAdapter ) ;
37
- await createDoc ( storageAdapter , "../../packages" , " site/docs/storage-adapters" , "Storage Adapters" ) ;
46
+ await createDoc ( storageAdapter , ` ${ packagesPath } ` , ` ${ packagesPath } /website/ site/docs/storage-adapters` , "Storage Adapters" ) ;
38
47
}
39
48
} ;
40
49
}
41
50
42
51
async function copyTestSuite ( ) {
43
- const originalFileText = await fs . readFile ( "../../packages/test-suite/readme.md" , "utf8" ) ;
52
+ const packagesPath = getRelativePackagePath ( ) ;
53
+ const originalFileText = await fs . readFile ( `${ packagesPath } /test-suite/README.md` , "utf8" ) ;
44
54
let newFileText = "---\n" ;
45
55
newFileText += `title: 'Test Suite'\n` ;
46
56
newFileText += `permalink: /docs/test-suite/\n` ;
@@ -50,16 +60,17 @@ async function copyTestSuite() {
50
60
51
61
newFileText = cleanDocumentFromImage ( newFileText ) ;
52
62
53
- console . log ( "Adding in Test Suite" ) ;
54
- await fs . writeFile ( " site/docs/test-suite/index.md" , newFileText ) ;
63
+ console . log ( "Adding Test Suite" ) ;
64
+ await fs . writeFile ( ` ${ packagesPath } /website/ site/docs/test-suite/index.md` , newFileText ) ;
55
65
}
56
66
57
67
async function copyCompressionDocs ( ) {
58
- const compressionAdapters = await fs . readdir ( "../../packages" ) ;
68
+ const packagesPath = getRelativePackagePath ( ) ;
69
+ const compressionAdapters = await fs . readdir ( `${ packagesPath } ` ) ;
59
70
for ( const compressionAdapter of compressionAdapters ) {
60
71
if ( compressionAdapter . startsWith ( "compress-" ) ) {
61
72
console . log ( "Adding compression adapter: " + compressionAdapter ) ;
62
- await createDoc ( compressionAdapter , "../../packages" , " site/docs/compression" , "Compression" ) ;
73
+ await createDoc ( compressionAdapter , ` ${ packagesPath } ` , ` ${ packagesPath } /website/ site/docs/compression` , "Compression" ) ;
63
74
}
64
75
}
65
76
}
@@ -69,8 +80,28 @@ function cleanDocumentFromImage(document: string) {
69
80
return document ;
70
81
} ;
71
82
83
+ function getRelativePackagePath ( ) {
84
+ if ( fs . pathExistsSync ( "packages" ) ) {
85
+ //we are in the root
86
+ return "packages" ;
87
+ }
88
+
89
+ //we are in the website folder
90
+ return "../../packages"
91
+ }
92
+
93
+ function getRelativeDocsPath ( ) {
94
+ if ( fs . pathExistsSync ( "docs" ) ) {
95
+ //we are in the root
96
+ return "docs" ;
97
+ }
98
+
99
+ //we are in the website folder
100
+ return "../../docs"
101
+ }
102
+
72
103
async function createDoc ( adapterName : string , path : string , outputPath : string , parent :string ) {
73
- const originalFileName = "readme .md" ;
104
+ const originalFileName = "README .md" ;
74
105
const newFileName = `${ adapterName } .md` ;
75
106
const packageJSONPath = `${ path } /${ adapterName } /package.json` ;
76
107
const packageJSON = await fs . readJSON ( packageJSONPath ) ;
0 commit comments