@@ -8,11 +8,11 @@ const env = { ...process.env, DEBUG: "rdme*" };
88const execFile = util . promisify ( require ( "node:child_process" ) . execFile ) ;
99
1010const README_API_KEY = process . env . README_API_KEY ;
11+ const README_VERSION = process . env . README_VERSION ;
1112if ( ! README_API_KEY ) {
1213 console . error ( `README_API_KEY not set` ) ;
1314 process . exit ( 1 ) ;
1415}
15- const README_VERSION = process . env . README_VERSION ;
1616if ( ! README_VERSION ) {
1717 console . error ( `README_VERSION not set` ) ;
1818 process . exit ( 1 ) ;
@@ -29,6 +29,21 @@ async function execAndLog(cmd, args) {
2929 }
3030}
3131
32+ function getSlugFromJson ( file ) {
33+ const splitFile = file . split ( `.json` ) ;
34+ return splitFile [ 0 ] ;
35+ }
36+
37+ function getSlugFromYaml ( file ) {
38+ const splitFile = file . split ( `.yaml` ) ;
39+ return splitFile [ 0 ] ;
40+ }
41+
42+ function convertSlugToJson ( file ) {
43+ const slug = getSlugFromYaml ( file ) ;
44+ return `${ slug } .json` ;
45+ }
46+
3247async function updateSpecs ( ) {
3348 // fetch IDs of openapi specs via readme API
3449 const res = await fetch (
@@ -45,7 +60,7 @@ async function updateSpecs() {
4560 const outBase = path . resolve ( __dirname , `out` ) ;
4661 const filenames = fs
4762 . readdirSync ( outBase )
48- . filter ( ( fn ) => fn . endsWith ( `.json ` ) ) ;
63+ . filter ( ( fn ) => fn . endsWith ( `.yaml ` ) ) ;
4964
5065 if ( ! remoteSpecMetas ) {
5166 console . error ( `!!! No remote specs found, please double check the API` ) ;
@@ -57,7 +72,7 @@ async function updateSpecs() {
5772 const fullPath = path . join ( outBase , specFile ) ;
5873 const yamlStr = fs . readFileSync ( fullPath , "utf8" ) ;
5974 const spec = YAML . parse ( yamlStr ) ;
60- const specMeta = remoteSpecMetas . data . find ( ( m ) => m . filename === specFile ) ;
75+ const specMeta = remoteSpecMetas . data . find ( ( m ) => getSlugFromJson ( m . filename ) === getSlugFromYaml ( specFile ) ) ;
6176 if ( ! specMeta ) {
6277 console . log ( `!!! No spec found for "${ spec . info . title } ". Please upload it as found in the developer.mixpanel.com runbook.` ) ;
6378 continue ;
@@ -66,8 +81,21 @@ async function updateSpecs() {
6681 // validate and publish spec
6782 console . log ( `Updating ${ spec . info . title } (${ specFile } ` ) ;
6883 await execAndLog ( 'npx' , [ 'rdme' , 'openapi:validate' , fullPath ] ) ;
84+ // this converts the file to json, since it does this step directly in readme anyway
85+ await execAndLog (
86+ 'npx' , [ 'rdme' , 'openapi' , 'convert' , fullPath , `--out=openapi/out/${ convertSlugToJson ( specFile ) } ` ] , { env}
87+ ) ;
88+ // publish the json version
6989 await execAndLog (
70- 'npx' , [ 'rdme' , 'openapi' , 'upload' , fullPath , `--key=${ README_API_KEY } ` , `--slug=${ specFile } ` ] , { env}
90+ 'npx' , [
91+ 'rdme' ,
92+ 'openapi' ,
93+ 'upload' ,
94+ `${ convertSlugToJson ( fullPath ) } ` ,
95+ `--key=${ README_API_KEY } ` ,
96+ `--slug=${ convertSlugToJson ( specFile ) } ` ,
97+ `--confirm-overwrite`
98+ ] , { env}
7199 ) ;
72100 }
73101}
0 commit comments