Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dir-generate

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dir-generate - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

bin/dir-generate.js

2

index.js

@@ -1,1 +0,1 @@

module.exports = require('./lib/dir-generate.js');
module.exports = require('./lib/dir-generate.js').run();

@@ -20,56 +20,58 @@ #!/usr/bin/env node

commander
.option('-d, --dir [source_dir] ',
'set target dir path. defaults to ./',
'./')
.option('-f, --file [source_file]',
'set config file path. defaults to ./index.md',
'./index.md');
exports.run = function () {
commander
.option('-d, --dir [source_dir] ',
'set target dir path. defaults to ./',
'./')
.option('-f, --file [source_file]',
'set config file path. defaults to ./index.md',
'./index.md');
commander.parse(process.argv);
commander.parse(process.argv);
var filePath = commander.file;
var dirPath = commander.dir;
var filePath = commander.file;
var dirPath = commander.dir;
fse.readFile(filePath, 'utf8', function (err, data) {
if (err) {
throw new Error('Failed to open file.');
}
fse.readFile(filePath, 'utf8', function (err, data) {
if (err) {
throw new Error('Failed to open file.');
}
var json = md.parse(data);
if (json.shift() !== 'markdown') {
throw new Error('Markdown init wrong.');
}
initDir(json.shift(), dirPath);
console.log('dir-generate finish.');
});
var json = md.parse(data);
if (json.shift() !== 'markdown') {
throw new Error('Markdown init wrong.');
}
initDir(json.shift(), dirPath);
console.log('dir-generate finish.');
});
function initDir (json, dirPath) {
if(json.length === 0) {
return;
}
var type = json.shift();
if (type === 'bulletlist') {
json.forEach(function (item) {
initDir(item, dirPath);
});
} else if(type === 'listitem') {
var data = json.shift();
if(!data) {
throw new Error('Wrong parse.');
function initDir (json, dirPath) {
if(json.length === 0) {
return;
}
var outputPath = path.join(dirPath, data);
if (/\b\w*\.\w+$/.test(data)) {
fse.outputFile(outputPath, '');
var type = json.shift();
if (type === 'bulletlist') {
json.forEach(function (item) {
initDir(item, dirPath);
});
} else if(type === 'listitem') {
var data = json.shift();
if(!data) {
throw new Error('Wrong parse.');
}
var outputPath = path.join(dirPath, data);
if (/\b\w*\.\w+$/.test(data)) {
fse.outputFile(outputPath, '');
} else {
fse.ensureDir(outputPath);
var next = json.shift();
if(next) {
initDir(next, outputPath);
}
}
} else {
fse.ensureDir(outputPath);
var next = json.shift();
if(next) {
initDir(next, outputPath);
}
throw new Error('Wrong input.');
}
} else {
throw new Error('Wrong input.');
}
}
};
{
"name": "dir-generate",
"version": "0.0.2",
"version": "0.0.3",
"description": "a easy tool to make dir with markdown",
"bin": {
"dir-generate": "./lib/dir-generate"
"dir-generate": "./bin/dir-generate"
},

@@ -8,0 +8,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc