Comparing version 0.1.1 to 0.1.2
@@ -10,4 +10,7 @@ #!/usr/bin/env node | ||
program.command('init-config') | ||
.action(function() { | ||
cliUtils.initConfig(); | ||
.option('-k, --key [key]') | ||
.option('-n, --name [name]') | ||
.option('-v, --version [version]') | ||
.action(function(opts) { | ||
cliUtils.initConfig(opts); | ||
}) | ||
@@ -17,5 +20,7 @@ | ||
.option('-v, --verbose') | ||
.option('-f, --force') | ||
.action(function(config, opts) { | ||
config = cliUtils.getConfig(config); | ||
config.verbose = opts.verbose; | ||
config.force = opts.force; | ||
treeBuilder(config); | ||
@@ -35,6 +40,5 @@ }) | ||
program.command('watch-server [config]') | ||
.option('-p, --port') | ||
.option('-p, --port [port]') | ||
.action(function(config, opts) { | ||
config = cliUtils.getConfig(config); | ||
var watcher = chokidar.watch(config.root, { | ||
@@ -59,3 +63,3 @@ ignored: [config.dist, /(^|[\/\\])\..|node_modules/]}); | ||
program.command('prod-server [config]') | ||
.option('-p, --port') | ||
.option('-p, --port [port]') | ||
.action(function(config, opts) { | ||
@@ -62,0 +66,0 @@ config = cliUtils.getConfig(config); |
module.exports = { | ||
projectKey: 'myProject-1.0.0', | ||
projectName: 'myProject', | ||
version: '1.0.0', | ||
projectKey: 'PROJECTKEY', | ||
projectName: 'PROJECTNAME', | ||
version: 'PROJECTVERSION', | ||
root: __dirname, | ||
@@ -6,0 +6,0 @@ dist: __dirname + '/jsdef', |
module.exports = { | ||
projectKey: 'myProject-1.0.0', | ||
projectName: 'myProject', | ||
projectKey: '12333', | ||
projectName: 'jsddd', | ||
version: '1.0.0', | ||
@@ -5,0 +5,0 @@ root: __dirname, |
{ | ||
"name": "jsdef", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A tool to parse documentation for javascript in a more straight-forward way", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -28,6 +28,6 @@ # jsDef | ||
```console | ||
jsdef init-config | ||
$ jsdef init-config | ||
``` | ||
A default config file (jsdef.config.js) will be created in the cwd: | ||
A default config file (jsdef.config.js) will be created under cwd: | ||
@@ -54,3 +54,3 @@ ```js | ||
### Parsing source files | ||
### Parse source files | ||
@@ -60,3 +60,3 @@ ```console | ||
``` | ||
### Generating dist files | ||
### Generate dist files | ||
@@ -81,3 +81,3 @@ ```console | ||
### Generate Writing | ||
### General Writing | ||
@@ -84,0 +84,0 @@ Add `#@link-key-words` or `[link-text#@link-key-words]` at any places in the files to create smart links: |
@@ -41,5 +41,2 @@ var cwd = process.cwd(); | ||
excludes: [/__test/, /test/] | ||
}, | ||
theme: { | ||
primaryColor: 'purple' | ||
} | ||
@@ -50,4 +47,13 @@ } | ||
}, | ||
initConfig: function () { | ||
initConfig: function (opts) { | ||
var config = utils.readFile(etc.path('/examples/jsdef.config.js')); | ||
if (opts.key) { | ||
config = config.replace(/'PROJECTKEY'/, '\'' + opts.key + '\''); | ||
} | ||
if (opts.name) { | ||
config = config.replace(/'PROJECTNAME'/, '\'' + opts.name + '\''); | ||
} | ||
if (opts.version) { | ||
config = config.replace(/'PROJECTVERSION'/, '\'' + opts.version + '\''); | ||
} | ||
utils.writeFile(cwd + '/jsdef.config.js', config); | ||
@@ -54,0 +60,0 @@ console.log('jsdef.config.js is added in ' + cwd); |
@@ -37,15 +37,17 @@ var utils = require('./utils'); | ||
var distPath = jsConfig.dist || jsConfig.root + '/jsdef'; | ||
var cachePath = ''; | ||
try { | ||
var cacheTree = utils.readFile(distPath + '/file-tree.js'); | ||
var cacheContent = utils.readFile(distPath + '/output-' + treeType + '.js'); | ||
cacheTree = JSON.parse(cacheTree.replace('var fileTree = ', '')); | ||
cacheContent = JSON.parse(cacheContent.replace('var output' | ||
+ (treeType === 'src' ? 'Src' : 'Doc') | ||
+ ' = ', '')); | ||
cachePath = distPath + '/file-tree.js'; | ||
if (!jsConfig.force) { | ||
var distPath = jsConfig.dist || jsConfig.root + '/jsdef'; | ||
var cachePath = ''; | ||
try { | ||
var cacheTree = utils.readFile(distPath + '/file-tree.js'); | ||
var cacheContent = utils.readFile(distPath + '/output-' + treeType + '.js'); | ||
cacheTree = JSON.parse(cacheTree.replace('var fileTree = ', '')); | ||
cacheContent = JSON.parse(cacheContent.replace('var output' | ||
+ (treeType === 'src' ? 'Src' : 'Doc') | ||
+ ' = ', '')); | ||
cachePath = distPath + '/file-tree.js'; | ||
} | ||
catch (e) { | ||
} | ||
} | ||
catch (e) { | ||
} | ||
@@ -172,3 +174,3 @@ var addTree = function(path, type, contentPath, parentPath, asKey) { | ||
var treePart; | ||
if (cachePath && utils.compareFile(cachePath, jsConfig.root + path) | ||
if (!jsConfig.force && cachePath && utils.compareFile(cachePath, jsConfig.root + path) | ||
&& (content = cacheContent[path]) | ||
@@ -178,3 +180,3 @@ && (treePart = fetchTree(path, cacheTree))) { | ||
else { | ||
// console.log(path + ': should be parsed'); | ||
jsConfig.verbose && console.log(path + ': should be parsed'); | ||
parseResult = treeType === 'src' ? jsDefParser.parseSrcFile(jsConfig.root + path) | ||
@@ -209,3 +211,3 @@ : jsDefParser.parseDocFile(jsConfig.root + path); | ||
*/ | ||
buildSiteMap: function (docFileList, rootPath) { | ||
buildSiteMap: function (docFileList, jsConfig) { | ||
@@ -230,3 +232,3 @@ if (!docFileList.length || !docFileList[0]) { | ||
var sitemap = utils.readFile(rootPath + docFolder + '/sitemap.md'); | ||
var sitemap = utils.readFile(jsConfig.root + docFolder + '/sitemap.md'); | ||
sitemap.split('\n').forEach(function(item) { | ||
@@ -237,3 +239,3 @@ var parts = item.trim().split(/\s+/); | ||
var replacement; | ||
if (~findIndex(parts[0], fileList)) { | ||
if (~findIndex(parts[0], fileList) && jsConfig.verbose) { | ||
console.warn('duplicate file path: ' + parts[0]); | ||
@@ -245,3 +247,3 @@ } | ||
} | ||
else if (!parts[1]) { | ||
else if (!parts[1] && jsConfig.verbose) { | ||
console.warn('removed file path: ' + parts[0]); | ||
@@ -305,3 +307,2 @@ } | ||
distPath + '/output-src.js', | ||
// utils.j('src', 'ui', 'asset', 'mock', 'output-src.js'), | ||
'var outputSrc = ' + JSON.stringify(ret.contentMap, null, 3) | ||
@@ -312,5 +313,12 @@ ); | ||
} | ||
else { | ||
utils.writeFile( | ||
distPath + '/output-src.js', | ||
'var outputSrc = {};' | ||
); | ||
} | ||
if (docFileList && docFileList.length) { | ||
var sitemap = fileTreeBuilder.buildSiteMap(docFileList, jsDefConfig.root); | ||
var sitemap = fileTreeBuilder.buildSiteMap(docFileList, jsDefConfig); | ||
ret = fileTreeBuilder.buildTree(sitemap.fileList, 'doc', jsDefConfig, sitemap.replaceMap); | ||
@@ -321,3 +329,2 @@ files = files.concat(ret.tree); | ||
distPath + '/output-doc.js', | ||
// utils.j('src', 'ui', 'asset', 'mock', 'output-doc.js'), | ||
'var outputDoc = ' + JSON.stringify(ret.contentMap, null, 3) | ||
@@ -328,2 +335,8 @@ ); | ||
} | ||
else { | ||
utils.writeFile( | ||
distPath + '/output-doc.js', | ||
'var outputDoc = {};' | ||
); | ||
} | ||
@@ -330,0 +343,0 @@ utils.writeFile( |
@@ -100,2 +100,7 @@ var npath = require('path'); | ||
// 忽略node_modules文件夹 | ||
if (/^node_modules/.test(fileEntry)) { | ||
return; | ||
} | ||
// 如果是文件, 直接插入 result 集合 | ||
@@ -102,0 +107,0 @@ if (fs.statSync(baseDir + '/' + fileEntry).isFile()) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
480106
3539