File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ const importMd = require("./importmd.js");
5
5
const addLogo = require ( "./addlogo.js" ) ;
6
6
const genSampleCode = require ( "./gencode.js" ) ;
7
7
const devTier = require ( "./devTier.js" ) ;
8
+ const replaceInteger = require ( "./replaceint.js" ) ;
8
9
9
10
const program = new Command ( ) ;
10
11
program
@@ -37,4 +38,9 @@ program.command("devtier")
37
38
. description ( "Add sample for creating a dev tier cluster" )
38
39
. argument ( "<in-filename" , "Target JSON file" )
39
40
. action ( devTier )
41
+ program . command ( "replaceint" )
42
+ . description ( "Replace the example and default value of integer type to number type" )
43
+ . argument ( "<in-filename>" , "Input JSON file" )
44
+ . argument ( "[out-filename]" , "Output JSON file. If not specified, use in-filename." )
45
+ . action ( replaceInteger ) ;
40
46
program . parse ( ) ;
Original file line number Diff line number Diff line change
1
+ const fs = require ( "fs" ) ;
2
+
3
+ function replaceIntegerInternal ( obj ) {
4
+ for ( let item in obj ) {
5
+ if ( obj [ item ] instanceof Object ) {
6
+ replaceIntegerInternal ( obj [ item ] ) ;
7
+ }
8
+ else if ( item == "type" && obj [ item ] === "integer" ) {
9
+ if ( obj [ "example" ] != undefined && typeof ( obj [ "example" ] ) != "number" ) {
10
+ obj [ "example" ] = parseInt ( obj [ "example" ] ) ;
11
+ }
12
+ if ( obj [ "default" ] != undefined && typeof ( obj [ "default" ] ) != "number" ) {
13
+ obj [ "default" ] = parseInt ( obj [ "default" ] ) ;
14
+ }
15
+ }
16
+ }
17
+ return obj ;
18
+ }
19
+
20
+ async function replaceInteger ( readf , writef ) {
21
+ writef = writef || readf ;
22
+ const data = JSON . parse ( fs . readFileSync ( readf , 'utf8' ) ) ;
23
+ const schema = replaceIntegerInternal ( data ) ;
24
+ fs . writeFileSync ( writef , JSON . stringify ( schema , null , 2 ) ) ;
25
+
26
+ }
27
+
28
+ module . exports = replaceInteger ;
You can’t perform that action at this time.
0 commit comments