Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Integrated miniglob, started speccing out default assets

  • Loading branch information...
commit ead7eae58d30a77ea89373e6164c2f388a5b26c1 1 parent 2244dde
@DamonOehlman authored
View
1  assets/docs/conf.py
@@ -0,0 +1 @@
+blah
View
1  docs/conf.py
@@ -0,0 +1 @@
+blah
View
28 lib/actions/create.js
@@ -1,7 +1,29 @@
-var docstar = require('../docstar');
+var docstar = require('../docstar'),
+ mkdirp = require('mkdirp'),
+ path = require('path');
module.exports = function(opts, callback) {
- docstar.init(opts, function() {
-
+ var scaffolder = this;
+
+ docstar.init(opts, function(err, instance) {
+ if (err) {
+ scaffolder.out(err);
+ }
+ else {
+ path.exists(path.join(instance.path, 'conf.py'), function(exists) {
+ if (! exists) {
+ scaffolder.copyAssets(
+ 'docs',
+ function() {
+ callback(instance);
+ },
+ instance.path
+ );
+ }
+ else {
+ callback(instance);
+ }
+ });
+ }
});
};
View
62 lib/docstar.js
@@ -1,45 +1,35 @@
var fs = require('fs'),
path = require('path'),
- fstream = require('fstream');
+ debug = require('debug')('docstar'),
+ miniglob = require('miniglob');
-function _findFile(targetPath, filename, callback) {
-
- var found = false;
+function DocStar(docpath, opts) {
+ console.log(docpath);
+ this.path = path.join(opts.targetPath, docpath || 'docs');
+ debug('docpath set to ' + this.path);
+};
+
+exports.init = function(opts, callback) {
+ var pattern = '**/conf.py';
- function find(childPath, parent) {
- var reader = fstream.Reader({
- path: childPath,
- filter: function() {
- return !this.basename.match(/^\./) && !this.basename.match(/^node_modules$/);
- }
+ miniglob(pattern, { cwd: opts.targetPath }, function(err, matches) {
+ // splice the pattern out while miniglob returns it in the matches
+ var matchIndex = matches.indexOf(pattern);
+ if (matchIndex >= 0) {
+ matches.splice(matchIndex, 1);
+ }
+
+ // iterate through the matches and filter out those in the node_modules
+ // and assets directories
+ matches = matches.filter(function(matchPath) {
+ return !matchPath.match(/^assets/) && !matchPath.match(/^node_modules/);
});
- reader.on('entry', function(data) {
- if (!found && data.type === 'File' && data.basename === filename) {
- found = true;
- callback(data.path);
- }
- else if (!found && data.type === 'Directory') {
- find(data.path, reader);
- }
- });
-
- if (! parent) {
- reader.on('end', function() {
- if (! found) {
- callback();
- }
- });
+ if (matches.length <= 1) {
+ callback(null, new DocStar(matches[0] ? path.dirname(matches[0]) : '', opts));
+ }
+ else {
+ callback('Too many possible documentation directories, please review');
}
- } // childPath
-
- find(targetPath);
-};
-
-exports.init = function(opts, callback) {
- // look for a directory under the target path with a directory that
- // contains a conf.py as per the readthedocs.org check
- _findFile(opts.targetPath, 'conf.py', function(folderPath) {
- console.log(folderPath);
});
};
View
3  package.json
@@ -16,9 +16,10 @@
"node": ">= 0.4.x < 0.7.0"
},
"dependencies": {
+ "debug": "*",
"scaffolder": "*",
"attachmate": "0.1.x",
- "fstream": "0.1.x"
+ "miniglob": "*"
},
"devDependencies": {
},
Please sign in to comment.
Something went wrong with that request. Please try again.