Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

v0.2.1: fix nested directories, closes #5. add npmignore, closes #4.

  • Loading branch information...
commit 77ee92c85bfb8bf001080b4e1dcf0f64c06e45c7 1 parent 69c81c6
@millermedeiros authored
View
2  .npmignore
@@ -0,0 +1,2 @@
+node_modules/
+test/
View
5 package.json
@@ -1,6 +1,6 @@
{
"name": "nodefy",
- "version": "0.2.0",
+ "version": "0.2.1",
"description": "convert AMD modules into a node.js compatible format",
"main": "index.js",
"directories": {
@@ -22,7 +22,8 @@
"esprima" : ">= 1.0 <1.2",
"glob" : "~3.1.14",
"async" : "~0.1.22",
- "commander" : "~1.1.0"
+ "commander" : "~1.1.0",
+ "mkdirp" : "~0.3.4"
},
"devDependencies" : {
"jasmine-node" : "~1.0.26"
View
3  src/converter.js
@@ -3,6 +3,7 @@ var _path = require('path');
var _glob = require('glob');
var _async = require('async');
+var _mkdirp = require('mkdirp');
var _parser = require('./parser');
@@ -52,7 +53,7 @@ exports.convert = function(inputPath, outputPath, callback){
function safeCreateDir(filePath, callback){
var dir = _path.dirname(filePath);
if (! _fs.existsSync(dir) ) {
- _fs.mkdir(dir, callback);
+ _mkdirp(dir, callback);
} else {
callback(null);
}
View
16 test/convert.spec.js
@@ -61,17 +61,30 @@ describe('convert', function () {
});
- it('should throw error if it can\'t find file', function () {
+ it('should throw error if it can\'t find file', function (done) {
var inPath = _path.join(INPUT_DIR, 'missing_file.js');
var outPath = _path.join(TEMP_DIR, 'missing_file.js');
nodefy.convert(inPath, outPath, function(err, result){
expect(err).not.toBe(null);
expect( result ).toBeUndefined();
expect( function(){ readFile(outPath); }).toThrow();
+ done();
});
});
+ it('should work with deep nested folders', function (done) {
+ var inPath = _path.join(INPUT_DIR, 'nested/deep/plugin-in.js');
+ var outPath = _path.join(TEMP_DIR, 'nested/deep/plugin-out.js');
+ nodefy.convert(inPath, outPath, function(err, result){
+ expect(err).toBe(null);
+ expect( readFile(outPath) ).toEqual( readOut('nested/deep/plugin') );
+ done();
+ });
+ });
+
+
+
// ---
@@ -97,6 +110,7 @@ describe('convert', function () {
expect( readFile(BATCH_DIR + '/simplified_cjs-in.js') ).toEqual( readOut('simplified_cjs') );
expect( readFile(BATCH_DIR + '/named_mixed-in.js') ).toEqual( readOut('named_mixed') );
expect( readFile(BATCH_DIR + '/nested/magic_remaped-in.js') ).toEqual( readOut('nested/magic_remaped') );
+ expect( readFile(BATCH_DIR + '/nested/deep/plugin-in.js') ).toEqual( readOut('nested/deep/plugin') );
done();
});
View
5 test/files/nested/deep/plugin-in.js
@@ -0,0 +1,5 @@
+// nodefy doesn't handle plugins, it will convert it into a simple require
+// this test also ensures nested folders works as expected
+define(['foo!bar'], function(bar){
+ return bar.baz;
+});
View
5 test/files/nested/deep/plugin-out.js
@@ -0,0 +1,5 @@
+// nodefy doesn't handle plugins, it will convert it into a simple require
+// this test also ensures nested folders works as expected
+var bar = require('foo!bar');
+ module.exports = bar.baz;
+
View
6 test/parse.spec.js
@@ -47,5 +47,11 @@ describe('parse', function () {
expect( output ).toEqual( readOut('nested/magic_remaped') );
});
+ it('should do simple conversion if dependency uses an AMD plugin', function () {
+ var output = nodefy.parse( readIn('nested/deep/plugin') );
+ expect( output ).toMatch( /require\(['"]\w+!\w+['"]\)/ );
+ expect( output ).toEqual( readOut('nested/deep/plugin') );
+ });
+
});
Please sign in to comment.
Something went wrong with that request. Please try again.