PageRenderTime 40ms CodeModel.GetById 21ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/mongoose/website.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 86 lines | 74 code | 11 blank | 1 comment | 13 complexity | b8cf0ace159c7b770d400b4a2878cc47 MD5 | raw file
 1var fs = require('fs');
 2var jade = require('jade');
 3var package = require('./package');
 4var linktype = require('./docs/helpers/linktype');
 5var href = require('./docs/helpers/href');
 6var klass = require('./docs/helpers/klass');
 7
 8const markdown = require('marked');
 9const highlight = require('highlight.js');
10markdown.setOptions({
11  highlight: function(code) {
12    return highlight.highlight('JavaScript', code).value;
13  }
14});
15
16jade.filters.markdown = markdown;
17
18function getVersion() {
19  return require('./package.json').version;
20}
21
22function getLatestLegacyVersion(startsWith) {
23  var hist = fs.readFileSync('./History.md', 'utf8').replace(/\r/g, '\n').split('\n');
24  for (var i = 0; i < hist.length; ++i) {
25    var line = (hist[i] || '').trim();
26    if (!line) {
27      continue;
28    }
29    var match = /^\s*([^\s]+)\s/.exec(line);
30    if (match && match[1] && match[1].startsWith(startsWith)) {
31      return match[1];
32    }
33  }
34  throw new Error('no match found');
35}
36
37// use last release
38package.version = getVersion();
39package.latest4x = getLatestLegacyVersion('4.');
40package.latest38x = getLatestLegacyVersion('3.8');
41
42var filemap = require('./docs/source');
43var files = Object.keys(filemap);
44
45function jadeify(filename, options, newfile) {
46  options = options || {};
47  options.package = package;
48  options.linktype = linktype;
49  options.href = href;
50  options.klass = klass;
51  jade.renderFile(filename, options, function(err, str) {
52    if (err) {
53      console.error(err.stack);
54      return;
55    }
56
57    newfile = newfile || filename.replace('.jade', '.html');
58    fs.writeFile(newfile, str, function(err) {
59      if (err) {
60        console.error('could not write', err.stack);
61      } else {
62        console.log('%s : rendered ', new Date, newfile);
63      }
64    });
65  });
66}
67
68files.forEach(function(file) {
69  var filename = __dirname + '/' + file;
70  jadeify(filename, filemap[file]);
71
72  if (process.argv[2] === '--watch') {
73    fs.watchFile(filename, {interval: 1000}, function(cur, prev) {
74      if (cur.mtime > prev.mtime) {
75        jadeify(filename, filemap[file]);
76      }
77    });
78  }
79});
80
81var acquit = require('./docs/source/acquit');
82var acquitFiles = Object.keys(acquit);
83acquitFiles.forEach(function(file) {
84  var filename = __dirname + '/docs/acquit.jade';
85  jadeify(filename, acquit[file], __dirname + '/docs/' + file);
86});