Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Windows Support #181

Merged
merged 11 commits into from

3 participants

@neocotic

This is an alternative to PR jashkenas/docco#155 which supports Windows by replacing shell commands within the program.

This does not touch upon Cakefile which will remain unix-only, at least for now. Basically, Windows users can use docco, but not develop it... yet.


On a side note; can cake install simply be replaced with npm link or npm install -g?

@keithamus
Collaborator

async seems to be an unnecessary dependency to me. Is it actually required to make Windows work?

@neocotic

@keithamus I've removed the async dependency. I prefer using it for asynchronous activities while it also provides good functionality (parallel processing) and don't think dependencies are a bad thing... But I've removed it all the same.

Hopefully this can be included in the next minor release (fingers crossed will be soon).

@keithamus
Collaborator

I appreciate the async functionality, but I think in the context of this PR I'm not sure it's relevant. Thanks for removing it.

As for the rest, it looks good to me, but I'm leaving this one to @jashkenas as he might have an opinion on the extra dependencies.

@neocotic

@jashkenas You'll also be happy to know that I actually reduced the LoC this time (albeit only by 1) :smile:. In docco.litcoffee at least...

@neocotic

@keithamus Fair enough, the fs-extra package (which I only recently discovered) is a fantastic module that acts as a drop-in replacement for node's fs module, while providing it's own functionality and borrowing some from others. In this case, I'm using fs.mkdirs and fs.copy which reflect mkdirp and ncp respectively. Both of which are extremely popular fs-related modules (and rightly so).

I tried to keep the changes as simple as possible while supporting Windows and I hope @jashkenas can appreciate that. I understand why he's keen on keeping the code minimal and readable, and I believe this PR maintains that while adding support for more developers out there.

@neocotic neocotic referenced this pull request
Merged

More languages #187

@neocotic

I've found a bug causing an error during some final testing and pushed a fix for it. This runs perfectly fine now and hopefully it can be merged into master now.

@neocotic

Just ran this on another version of Windows on my VM and found odd behaviour with file paths. It didn't like the slashes (though I thought node handled these), so I've replaced paths like:

"#{dir}/docco.jst"

With:

path.join dir, 'docco.jst'

Final fix... honest :wink: It works great on different versions of Windows with different versions of node now.

@jashkenas jashkenas merged commit eb11637 into from
@neocotic neocotic referenced this pull request
Merged

Fresh configuration #168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 45 additions and 34 deletions.
  1. +24 −15 docco.js
  2. +20 −19 docco.litcoffee
  3. +1 −0  package.json
View
39 docco.js
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.6.2
(function() {
- var Docco, commander, config, configure, document, exec, ext, format, fs, getLanguage, highlight, l, languages, marked, parse, path, run, spawn, version, write, _, _ref,
+ var Docco, commander, config, configure, document, ext, format, fs, getLanguage, highlight, l, languages, marked, parse, path, run, version, write, _,
__slice = [].slice;
document = function(options, callback) {
@@ -8,16 +8,27 @@
options = {};
}
configure(options);
- return exec("mkdir -p " + config.output, function() {
- var complete, files, nextFile;
+ return fs.mkdirs(config.output, function() {
+ var complete, copyAsset, files, nextFile;
callback || (callback = function(error) {
if (error) {
throw error;
}
});
+ copyAsset = function(file, callback) {
+ return fs.copy(file, path.join(config.output, path.basename(file)), callback);
+ };
complete = function() {
- return exec(["cp -f " + config.css + " " + config.output, fs.existsSync(config["public"]) ? "cp -fR " + config["public"] + " " + config.output : void 0].join(' && '), callback);
+ return copyAsset(config.css, function(error) {
+ if (error) {
+ return callback(error);
+ } else if (fs.existsSync(config["public"])) {
+ return copyAsset(config["public"], callback);
+ } else {
+ return callback();
+ }
+ });
};
files = config.sources.slice();
nextFile = function() {
@@ -125,7 +136,7 @@
config = {
layout: 'parallel',
- output: 'docs/',
+ output: 'docs',
template: null,
css: null,
extension: null
@@ -138,12 +149,12 @@
if (options.template) {
config.layout = null;
} else {
- dir = config.layout = "" + __dirname + "/resources/" + config.layout;
- if (fs.existsSync("" + dir + "/public")) {
- config["public"] = "" + dir + "/public";
+ dir = config.layout = path.join(__dirname, 'resources', config.layout);
+ if (fs.existsSync(path.join(dir, 'public'))) {
+ config["public"] = path.join(dir, 'public');
}
- config.template = "" + dir + "/docco.jst";
- config.css = options.css || ("" + dir + "/docco.css");
+ config.template = path.join(dir, 'docco.jst');
+ config.css = options.css || path.join(dir, 'docco.css');
}
config.template = _.template(fs.readFileSync(config.template).toString());
return config.sources = options.args.filter(function(source) {
@@ -159,7 +170,7 @@
_ = require('underscore');
- fs = require('fs');
+ fs = require('fs-extra');
path = require('path');
@@ -169,9 +180,7 @@
highlight = require('highlight.js').highlight;
- _ref = require('child_process'), spawn = _ref.spawn, exec = _ref.exec;
-
- languages = JSON.parse(fs.readFileSync("" + __dirname + "/resources/languages.json"));
+ languages = JSON.parse(fs.readFileSync(path.join(__dirname, 'resources', 'languages.json')));
for (ext in languages) {
l = languages[ext];
@@ -195,7 +204,7 @@
return lang;
};
- version = JSON.parse(fs.readFileSync("" + __dirname + "/package.json")).version;
+ version = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'))).version;
run = function(args) {
var c;
View
39 docco.litcoffee
@@ -80,14 +80,16 @@ out in an HTML template.
document = (options = {}, callback) ->
configure options
- exec "mkdir -p #{config.output}", ->
+ fs.mkdirs config.output, ->
callback or= (error) -> throw error if error
+ copyAsset = (file, callback) ->
+ fs.copy file, path.join(config.output, path.basename(file)), callback
complete = ->
- exec [
- "cp -f #{config.css} #{config.output}"
- "cp -fR #{config.public} #{config.output}" if fs.existsSync config.public
- ].join(' && '), callback
+ copyAsset config.css, (error) ->
+ if error then callback error
+ else if fs.existsSync config.public then copyAsset config.public, callback
+ else callback()
files = config.sources.slice()
@@ -190,7 +192,7 @@ options.
config =
layout: 'parallel'
- output: 'docs/'
+ output: 'docs'
template: null
css: null
extension: null
@@ -205,10 +207,10 @@ source files for languages for which we have definitions.
if options.template
config.layout = null
else
- dir = config.layout = "#{__dirname}/resources/#{config.layout}"
- config.public = "#{dir}/public" if fs.existsSync "#{dir}/public"
- config.template = "#{dir}/docco.jst"
- config.css = options.css or "#{dir}/docco.css"
+ dir = config.layout = path.join __dirname, 'resources', config.layout
+ config.public = path.join dir, 'public' if fs.existsSync path.join dir, 'public'
+ config.template = path.join dir, 'docco.jst'
+ config.css = options.css or path.join dir, 'docco.css'
config.template = _.template fs.readFileSync(config.template).toString()
config.sources = options.args.filter((source) ->
@@ -223,20 +225,19 @@ Helpers & Initial Setup
Require our external dependencies.
- _ = require 'underscore'
- fs = require 'fs'
- path = require 'path'
- marked = require 'marked'
- commander = require 'commander'
- {highlight} = require 'highlight.js'
- {spawn, exec} = require 'child_process'
+ _ = require 'underscore'
+ fs = require 'fs-extra'
+ path = require 'path'
+ marked = require 'marked'
+ commander = require 'commander'
+ {highlight} = require 'highlight.js'
Languages are stored in JSON in the file `resources/languages.json`.
Each item maps the file extension to the name of the language and the
`symbol` that indicates a line comment. To add support for a new programming
language to Docco, just add it to the file.
- languages = JSON.parse fs.readFileSync("#{__dirname}/resources/languages.json")
+ languages = JSON.parse fs.readFileSync(path.join(__dirname, 'resources', 'languages.json'))
Build out the appropriate matchers and delimiters for each language.
@@ -264,7 +265,7 @@ file extension. Detect and tag "literate" `.ext.md` variants.
Keep it DRY. Extract the docco **version** from `package.json`
- version = JSON.parse(fs.readFileSync("#{__dirname}/package.json")).version
+ version = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'))).version
Command Line Interface
View
1  package.json
@@ -14,6 +14,7 @@
"dependencies": {
"commander": ">= 0.5.2",
"marked": ">= 0.2.7",
+ "fs-extra": ">= 0.6.0",
"underscore": ">= 1.0.0",
"highlight.js": ">= 7.3.0"
},
Something went wrong with that request. Please try again.