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.6 to 0.1.0

coverage/coverage.json

34

bin/dir-generate.js
#!/usr/bin/env node
require('../lib/dir-generate.js').run();
'use strict';
/**
* Module dependencies.
*/
var commander = require('commander');
var process = require('process');
var md = require( "markdown" ).markdown;
var fse = require('fs-extra');
var path = require('path');
var dg = require('../lib/dir-generate');
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);
var filePath = commander.file;
var dirPath = commander.dir;
dg.runMarkdownFile(filePath, dirPath, function (err, path) {
if(err) {
return err;
}
console.log('dir-generate finish.');
console.log('the target dir path: ' + path);
});

2

index.js
#!/usr/bin/env node
module.exports = require('./lib/dir-generate.js').run();
module.exports = require('./lib/dir-generate');

@@ -12,3 +12,3 @@ /*!

var commander = require('commander');
var debug = require('debug')('dir-generate');
var process = require('process');

@@ -19,58 +19,91 @@ var md = require( "markdown" ).markdown;

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');
exports.runMarkdownFile = function (filePath, dirPath, callback) {
commander.parse(process.argv);
debug('dir-generate begin with: [filePath] %s [dirPath] %s', filePath, dirPath);
var filePath = commander.file;
var dirPath = commander.dir;
callback = callback || function () {};
if(!filePath || !dirPath) {
return callback(new Error('Arguments wrong.'));
}
fse.readFile(filePath, 'utf8', function (err, data) {
if (err) {
throw new Error('Failed to open file.');
return callback(err, null);
}
var json = md.parse(data);
if (json.shift() !== 'markdown') {
throw new Error('Markdown init wrong.');
return callback(new Error('Markdown init wrong.'), null);
}
initDir(json.shift(), dirPath);
console.log('dir-generate finish.');
exports._initMarkdown(json.shift(), dirPath, function (err) {
if(err) {
return callback(err, null);
}
return callback(null, dirPath);
});
});
};
function initDir (json, dirPath) {
if(json.length === 0) {
return;
exports._initMarkdown = function (json, dirPath, callback) {
var num = 0;
callback = callback || function () {};
if(json.length === 0) {
return callback(null);
}
var type = json.shift();
if (type === 'bulletlist') {
json.forEach(function (item) {
num++;
exports._initMarkdown(item, dirPath, function (err) {
if(err) {
return callback(err);
}
check();
});
});
} else if(type === 'listitem') {
var data = json.shift();
if(!data) {
return callback(new Error('Wrong parse.'));
}
var type = json.shift();
if (type === 'bulletlist') {
json.forEach(function (item) {
initDir(item, dirPath);
var outputPath = path.join(dirPath, data);
if (/\b\w*\.\w+$/.test(data)) {
fse.ensureFile(outputPath, function (err) {
return callback(err);
});
} 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);
} else {
fse.ensureDir(outputPath, function (err) {
if(err) {
return callback(err);
}
var next = json.shift();
if(next) {
initDir(next, outputPath);
exports._initMarkdown(next, outputPath, function (err) {
return callback(err);
});
} else {
return callback();
}
}
} else {
throw new Error('Wrong input.');
});
}
} else {
return callback(new Error('Wrong input.'));
}
function check () {
if(!--num) {
return callback();
}
}
};
{
"name": "dir-generate",
"version": "0.0.6",
"version": "0.1.0",
"description": "a easy tool to make dir with markdown",

@@ -14,7 +14,10 @@ "bin": {

"devDependencies": {
"debug": "~2.1.0",
"istanbul": "^0.3.2",
"jshint": "^2.5.1",
"should": "^3.0.0",
"mocha": "^1.12.0",
"thunkify": "^2.0.0",
"request": "^2.36.0"
"mm": "^0.2.1",
"mocha": "^1.21.5",
"request": "^2.36.0",
"should": "^4.0.4",
"thunkify": "^2.0.0"
},

@@ -21,0 +24,0 @@ "main": "index.js",

dir-generate
============
===============

@@ -8,9 +8,29 @@ a easy tool to make dir with markdown

###install
###usage for require
===============
####install
npm install dir-generate
####usage
var dg = require('dir-generate');
dg.runMarkdownFile('/Users/gkuchan/Documents/index.md', '/Users/gkuchan/Documents', function (err) {
if(err) {
console.log('Oh no!');
return;
}
console.log('Everything is ok.')
});
####methods
* runMarkdownFile(filePath, dirPath, callback)
###usage for command-line
===============
####install
npm install -g dir-generate
###help
####help
dir-generate -help
###how to use
####usage
Usage: dir-generate [options]

@@ -21,4 +41,12 @@ Options:

-f, --file [source_file] set config file path. defaults to ./index.md
###usage for dev
###example
* make jshint
* make test
* make cov
* make test-all
###example file
===============
index.md

@@ -39,7 +67,16 @@ --------------------------

--------------------------
dir-generate -d ./ -f ./index.md
###tip
===============
* the folder name cannot have a **Filename Extension**
* the file name must have a **Filename Extension**
* the file name must have a **Filename Extension**
###TODO
===============
* use json to generate dir
###Lincense
===============
MIT

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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