5
5
import chalk from 'chalk' ;
6
6
import path from 'path' ;
7
7
import fs from 'fs' ;
8
- import { findWorkspaceDir } from '@pnpm/find-workspace-dir' ;
8
+ import {
9
+ determinePackageManager ,
10
+ docsViewerRoot ,
11
+ generateDocs ,
12
+ getCurrentVersion ,
13
+ log ,
14
+ maybeMakePNPMInstallable ,
15
+ projectRoot ,
16
+ repoDetails ,
17
+ workspaceRoot ,
18
+ } from './-utils' ;
9
19
10
20
const EMBER_API_DOCS_REPO = `git@github.com:ember-learn/ember-api-docs.git` ;
11
21
const EMBER_JSONAPI_DOCS_REPO = `git@github.com:ember-learn/ember-jsonapi-docs.git` ;
12
22
const EMBER_API_DOCS_DATA_REPO = `git@github.com:ember-learn/ember-api-docs-data.git` ;
13
23
14
- const workspaceRoot = ( await findWorkspaceDir ( process . cwd ( ) ) ) as string ;
15
-
16
- if ( ! workspaceRoot ) {
17
- throw new Error ( 'Could not find workspace root' ) ;
18
- }
19
-
20
- const docsViewerRoot = path . join ( workspaceRoot , 'docs-viewer' ) ;
21
-
22
- function log ( message : string ) {
23
- console . log ( chalk . grey ( `[docs-viewer]\t${ message } ` ) ) ;
24
- }
25
-
26
- function repoDetails ( gitUrl : string ) {
27
- const repoPath = gitUrl . replace ( '.git' , '' ) . replace ( 'git@github.com:' , '' ) ;
28
- const [ org , name ] = repoPath . split ( '/' ) ;
29
- const installPathFromRoot = path . join ( './projects' , name ) ;
30
- const location = path . join ( docsViewerRoot , installPathFromRoot ) ;
31
-
32
- return {
33
- org,
34
- name,
35
- repoPath,
36
- gitUrl,
37
- installPathFromRoot,
38
- location,
39
- relativePath : path . relative ( __dirname , path . join ( docsViewerRoot , installPathFromRoot ) ) ,
40
- } ;
41
- }
42
-
43
- async function getCurrentVersion ( tool : string ) {
44
- const proc = Bun . spawn ( [ tool , '--version' ] , {
45
- env : process . env ,
46
- stdio : [ 'inherit' , 'pipe' , 'inherit' ] ,
47
- } ) ;
48
- await proc . exited ;
49
- const version = await new Response ( proc . stdout ) . text ( ) ;
50
- return version . trim ( ) . replace ( 'v' , '' ) ;
51
- }
52
-
53
- function determinePackageManager ( dir : string ) {
54
- if ( fs . existsSync ( path . join ( dir , 'pnpm-lock.yaml' ) ) ) {
55
- return 'pnpm' ;
56
- }
57
- if ( fs . existsSync ( path . join ( dir , 'package-lock.json' ) ) ) {
58
- return 'npm' ;
59
- }
60
- if ( fs . existsSync ( path . join ( dir , 'yarn.lock' ) ) ) {
61
- return 'yarn' ;
62
- }
63
-
64
- return 'npm' ;
65
- }
66
-
67
24
async function getOrUpdateRepo ( gitUrl : string ) {
68
25
const details = repoDetails ( gitUrl ) ;
69
26
@@ -75,42 +32,11 @@ async function getOrUpdateRepo(gitUrl: string) {
75
32
76
33
// install dependencies
77
34
const packageManager = determinePackageManager ( details . location ) ;
78
-
79
35
if ( packageManager === 'pnpm' ) {
80
- // get the version to use from package.json
81
- const packageJson = require ( path . join ( details . location , 'package.json' ) ) ;
82
-
83
- let nodeVersion = await getCurrentVersion ( 'node' ) ;
84
- const pnpmVersion = await getCurrentVersion ( 'pnpm' ) ;
85
-
86
- // ember-api-docs requires an older node due to node-sass
87
- if ( packageJson . name === 'ember-api-docs' ) {
88
- nodeVersion = '20.19.0' ;
89
- }
90
-
91
- if (
92
- ! packageJson . volta ||
93
- packageJson . volta . node !== nodeVersion ||
94
- packageJson . volta . pnpm !== pnpmVersion ||
95
- packageJson . packageManager ||
96
- packageJson . engines ?. node !== nodeVersion
97
- ) {
98
- delete packageJson . packageManager ;
99
- packageJson . volta = {
100
- node : nodeVersion ,
101
- pnpm : pnpmVersion ,
102
- } ;
103
- packageJson . engines = packageJson . engines || { } ;
104
- packageJson . engines . node = nodeVersion ;
105
-
106
- fs . writeFileSync ( path . join ( details . location , 'package.json' ) , JSON . stringify ( packageJson , null , 2 ) ) ;
107
- const proc = Bun . spawn ( [ 'git' , 'commit' , '-am' , '"ensure volta works as expected"' ] , {
108
- cwd : details . location ,
109
- env : process . env ,
110
- stdio : [ 'inherit' , 'inherit' , 'inherit' ] ,
111
- } ) ;
112
- await proc . exited ;
113
- }
36
+ // some of the repositories use pnpm but do not have volta configured
37
+ // and have not had their engines/packageManager field updated in a while.
38
+ // this lets us still install them with pnpm if that is the case
39
+ await maybeMakePNPMInstallable ( details ) ;
114
40
}
115
41
116
42
log ( `Installing dependencies in ${ chalk . green ( details . installPathFromRoot ) } using ${ chalk . yellow ( packageManager ) } ` ) ;
@@ -125,6 +51,10 @@ async function getOrUpdateRepo(gitUrl: string) {
125
51
await proc . exited ;
126
52
}
127
53
54
+ /**
55
+ * Updates the repo by fetching only the latest commit on the main branch
56
+ * and resetting the local repo to that commit
57
+ */
128
58
async function getLatest ( details : ReturnType < typeof repoDetails > ) {
129
59
log ( `Updating ${ chalk . green ( details . repoPath ) } in ${ chalk . green ( details . installPathFromRoot ) } to latest` ) ;
130
60
const mainBranch = details . name === 'ember-jsonapi-docs' ? 'master' : 'main' ;
@@ -138,6 +68,9 @@ async function getLatest(details: ReturnType<typeof repoDetails>) {
138
68
await proc2 . exited ;
139
69
}
140
70
71
+ /**
72
+ * Clones the repo, fetching only the latest commit
73
+ */
141
74
async function cloneRepo ( details : ReturnType < typeof repoDetails > ) {
142
75
const relativePath = path . join ( './projects' , details . name ) ;
143
76
log ( `Cloning ${ chalk . green ( details . repoPath ) } to ${ chalk . green ( relativePath ) } ` ) ;
@@ -152,44 +85,45 @@ async function main() {
152
85
log ( `\tCurrent working directory: ${ chalk . green ( process . cwd ( ) ) } ` ) ;
153
86
154
87
// clone repos
88
+ //////////////
89
+ //
155
90
await getOrUpdateRepo ( EMBER_API_DOCS_DATA_REPO ) ;
156
91
await getOrUpdateRepo ( EMBER_JSONAPI_DOCS_REPO ) ;
157
92
await getOrUpdateRepo ( EMBER_API_DOCS_REPO ) ;
158
93
159
94
// symlink our own project root into projects as 'ember-data'
160
- const emberDataLocation = path . join ( docsViewerRoot , './projects/ember-data' ) ;
95
+ /////////////////////////////////////////////////////////////
96
+ //
97
+ const emberDataLocation = path . join ( projectRoot , 'ember-data' ) ;
161
98
if ( ! fs . existsSync ( emberDataLocation ) ) {
162
99
log ( `Symlinking ${ chalk . green ( 'ember-data' ) } to ${ chalk . green ( './projects/ember-data' ) } ` ) ;
163
100
fs . symlinkSync ( workspaceRoot , emberDataLocation ) ;
164
101
}
165
102
166
- // symlink `ember-api-docs-data` to `ember-api-docs`
167
- const projectRoot = path . join ( docsViewerRoot , './projects' ) ;
103
+ // symlink `ember-api-docs-data` into `ember-api-docs`
104
+ ////////////////////////////////////////////////////
105
+ //
168
106
const emberApiDocsData = path . join ( projectRoot , 'ember-api-docs-data' ) ;
169
107
const symLinkLocation = path . join ( projectRoot , 'ember-api-docs/ember-api-docs-data' ) ;
170
-
171
108
if ( ! fs . existsSync ( symLinkLocation ) ) {
172
109
log ( `Symlinking ${ chalk . green ( 'ember-api-docs-data' ) } to ${ chalk . green ( 'ember-api-docs' ) } ` ) ;
173
110
fs . symlinkSync ( emberApiDocsData , symLinkLocation ) ;
174
111
}
175
112
176
113
log ( 'Docs viewer setup complete' ) ;
177
-
178
114
log ( 'Generating the current docs in ember-jsonapi-docs (these will be inserted into ember-api-docs-data)' ) ;
179
- const currentVersion = require ( path . join ( workspaceRoot , 'package.json' ) ) . version ;
180
- const absoluteVersion = currentVersion . split ( '-' ) [ 0 ] ;
181
- const command = [ 'bun' , 'gen' , '--project' , 'ember-data' , '--version' , absoluteVersion ] ;
182
115
183
- const proc = Bun . spawn ( command , {
184
- cwd : path . join ( projectRoot , 'ember-jsonapi-docs' ) ,
185
- env : process . env ,
186
- stdio : [ 'inherit' , 'inherit' , 'inherit' ] ,
187
- } ) ;
188
- await proc . exited ;
116
+ // generate the docs
117
+ ////////////////////
118
+ //
119
+ await generateDocs ( ) ;
189
120
190
121
log ( 'Docs generated. Run `bun regenerate-docs` to update the docs with any changes' ) ;
191
122
log ( 'Starting the docs viewer' ) ;
192
123
124
+ // start the docs viewer
125
+ ////////////////////////
126
+ //
193
127
const proc2 = Bun . spawn ( [ 'pnpm' , 'start' ] , {
194
128
cwd : path . join ( projectRoot , 'ember-api-docs' ) ,
195
129
env : process . env ,
0 commit comments