Skip to content
Snippets Groups Projects
Select Git revision
  • 00da63ca6b89250993e202800fe0a04236473141
  • master default
  • neil
  • hpgl
  • sw-shawn-liu
  • ppa
  • fran
  • trotec-port
  • fs-hotfix
  • jake
  • ml-mods
  • fabmo-app
12 results

modules.js

Blame
  • modules.js 1.72 KiB
    //
    // modules.js
    //    node js/modules.js subdir
    //
    // Neil Gershenfeld 
    // (c) Massachusetts Institute of Technology 2018
    // 
    // This work may be reproduced, modified, distributed, performed, and 
    // displayed for any purpose, but must acknowledge the mods
    // project. Copyright is retained and must be preserved. The work is 
    // provided as is; no warranty is provided, and users accept all 
    // liability.
    //
    
    var fs = require('fs')
    
    var subdir = process.argv[2]
    var root = './'+subdir
    
    var str = ''
    
    list_files(root)
    console.log(str)
    
    function list_files(path) {
      var relpath = path.slice(root.length+1)
      var files = fs.readdirSync(path)
       for (var i = 0; i < files.length; ++i) {
          var file = files[i]
          var stats = fs.statSync(path+'/'+file)
          if (stats.isFile() == true) {
             if (relpath == '')
                continue
             else
                url = subdir+'/'+relpath+'/'+file
             var match = url.match(/\//g)
             if (match == null)
                var prefix = ''
             else {
                var prefix = Array(match.length).join('\u00A0\u00A0\u00A0')
                }
             str += "module_menu('"
             str += prefix+file+"','"
             str += encodeURI(url)
             str += "')\n"
             }
          else if (stats.isDirectory() == true) {
             if (relpath == '')
                url = subdir+'/'+file
             else
                url = subdir+'/'+relpath+'/'+file
             var match = url.match(/\//g)
             if (match == null)
                var prefix = ''
             else {
                var prefix = Array(match.length).join('\u00A0\u00A0\u00A0')
                }
             str += "module_label('"+prefix+file+"')\n"
             list_files(path+'/'+file)
             }
          else
             console.log('unknown file type')
          }
       }