forked from nglviewer/ngl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeScriptsList.js
35 lines (29 loc) · 995 Bytes
/
makeScriptsList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const fs = require( "fs" );
const path = require('path');
const exampleDir = path.join( __dirname, "../examples/scripts/" );
function flatten( arr ){
return arr.reduce( function( acc, val ){
return acc.concat(
Array.isArray( val ) ? flatten( val ) : val
);
}, [] );
}
function getExampleNames( dir, prefix ){
prefix = prefix || "";
return flatten( fs.readdirSync( dir )
.filter( name => !name.startsWith( "." ) )
.map( name => {
const filepath = path.join( dir, name );
const stats = fs.lstatSync( filepath );
if( stats.isDirectory( filepath ) ){
return getExampleNames( filepath, name + "/" );
}else if( stats.isFile( filepath ) ){
return prefix + name.substr( 0, name.length - 3 );
}
} )
);
}
fs.writeFileSync(
path.join( __dirname, "../build/scriptsList.json" ),
JSON.stringify( getExampleNames( exampleDir ) )
);