cybertk / ramlev

Validate/Verify examples in RAML
Other
30 stars 5 forks source link

enable to require ramlev as normal npm module #33

Closed umezo closed 8 years ago

umezo commented 8 years ago

this change makes ramlev enabled to be required like normal npm module.

after installing ramlev into some project locally, ramlev can be required from other .js files like following code.

npm install --save-dev ramlev
var Ramlev = require('ramlev');
var ramlev = new Ramlev( config );
ramlev.run(function(.......){
  ......
});
cybertk commented 8 years ago

Can we import a coffee module directly(without converting to js)?

umezo commented 8 years ago

I think yes.

I created tiny coffee project and checked it. https://gist.github.com/umezo/51669e6344b032caf97c

# index.coffee
Ramlev = require 'ramlev'
console.log( new Ramlev ) # -> Ramlev { configuration: undefined, tests: [] }

and ran this script with following command

coffee index.coffee (actually npm start)

cybertk commented 8 years ago

Then do we still need this PR?

umezo commented 8 years ago

sure! yes please!

I need this PR in work that dont(cant?) use coffee script.

cybertk commented 8 years ago

@umezo I mean ramlev already has coffee-script in deps of package.json, so it's was expected to work with normal javascript code, as the converting from coffee to js is in runtime.

umezo commented 8 years ago

Current ramlev module can't be found by runtime I checked that with following gist https://gist.github.com/umezo/76f0acf76c241a40d876

//index.js
var ramlev = require('ramlev')
module.js:341
    throw err;
    ^

Error: Cannot find module 'ramlev'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/............../ramlev-test-require/index.js:1:76)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)

my node version is v5.5.0

cybertk commented 8 years ago

@umezo I have some code update against this PR. Could you have a try with npm install git://github.com/cybertk/ramlev.git#as-lib.

umezo commented 8 years ago

@cybertk I tried same code with as-lib branch and it works !

umezo commented 8 years ago

thx!