@@ -4,7 +4,6 @@ const process = require("node:process");
44const util = require ( "node:util" ) ;
55const YAML = require ( "yaml" ) ;
66
7- const env = { ...process . env , DEBUG : "rdme*" } ;
87const execFile = util . promisify ( require ( "node:child_process" ) . execFile ) ;
98
109const README_API_KEY = process . env . README_API_KEY ;
@@ -29,21 +28,6 @@ async function execAndLog(cmd, args) {
2928 }
3029}
3130
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-
4731async function updateSpecs ( ) {
4832 // fetch IDs of openapi specs via readme API
4933 const res = await fetch (
@@ -60,42 +44,30 @@ async function updateSpecs() {
6044 const outBase = path . resolve ( __dirname , `out` ) ;
6145 const filenames = fs
6246 . readdirSync ( outBase )
63- . filter ( ( fn ) => fn . endsWith ( `.yaml ` ) ) ;
47+ . filter ( ( fn ) => fn . endsWith ( `.json ` ) ) ;
6448
6549 if ( ! remoteSpecMetas ) {
6650 console . error ( `!!! No remote specs found, please double check the API` ) ;
6751 process . exit ( 1 ) ;
6852 }
6953
70- for ( specFile of filenames ) {
54+ for ( specFile of [ filenames [ 0 ] ] ) {
7155 // get ID of each spec by matching title between filename and metadata
7256 const fullPath = path . join ( outBase , specFile ) ;
7357 const yamlStr = fs . readFileSync ( fullPath , "utf8" ) ;
7458 const spec = YAML . parse ( yamlStr ) ;
75- const specMeta = remoteSpecMetas . data . find ( ( m ) => getSlugFromJson ( m . filename ) === getSlugFromYaml ( specFile ) ) ;
59+ const specMeta = remoteSpecMetas . data . find ( ( m ) => m . filename === specFile ) ;
7660 if ( ! specMeta ) {
7761 console . log ( `!!! No spec found for "${ spec . info . title } ". Please upload it as found in the developer.mixpanel.com runbook.` ) ;
7862 continue ;
7963 }
8064
8165 // validate and publish spec
82- console . log ( `Updating ${ spec . info . title } (${ specFile } ` ) ;
66+ console . log ( `Updating ${ spec . info . title } (${ specFile } ) ` ) ;
8367 await execAndLog ( 'npx' , [ '[email protected] ' , 'openapi:validate' , fullPath ] ) ; 84- // this converts the file to json, since it does this step directly in readme anyway
85- await execAndLog (
86- 'npx' , [ '[email protected] ' , 'openapi' , 'convert' , fullPath , `--out=${ convertSlugToJson ( fullPath ) } ` ] , { env
} 87- ) ;
8868 // publish the json version
8969 await execAndLog (
90- 'npx' , [
91- 92- 'openapi' ,
93- 'upload' ,
94- `${ convertSlugToJson ( fullPath ) } ` ,
95- `--key=${ README_API_KEY } ` ,
96- `--slug=${ convertSlugToJson ( specFile ) } ` ,
97- `--confirm-overwrite`
98- ] , { env}
70+ 'npx' , [ '[email protected] ' , 'openapi' , 'upload' , `${ fullPath } ` , `--key=${ README_API_KEY } ` , `--slug=${ specFile } ` , `--confirm-overwrite` ] , 9971 ) ;
10072 }
10173}
0 commit comments