Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nodecaf

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodecaf - npm Package Compare versions

Comparing version 0.7.2 to 0.7.3

lib/codegen/api.ejs

28

bin/nodecaf.js
#!node
const fs = require('fs');
const path = require('path');
const Eclipt = require('eclipt');
if(process.argv[2] == '-h')
process.argv[2] = 'help';
else if(process.argv[2] == '-v')
process.argv[2] = 'version';
const cli = new Eclipt('nodecaf', {}, {
requireCommand: true,
noArgs: true,
getVersion: () => 'v' + require(__dirname + '/../package.json').version
});
let cf = path.resolve(__dirname, '../lib/cli', process.argv[2] + '.js');
if(fs.existsSync(cf)){
let cmd = require(cf);
try{
cmd();
}
catch(e){
console.error(e.message);
}
cli.requireCommands(__dirname + '/../lib/cli');
try{
cli.execute();
}
catch(e){
console.error(e.message);
}

@@ -8,2 +8,11 @@ # Nodecaf Changelog

## [v0.7.3] - 2019-07-16
### Changed
- minor details in cli outputs due to internal library changes (eclipt, ejs)
### Removed
- deprecated `conf` param from the `main.js` generated by `nodecaf init`
- `-o, --outfile` option of `nodecaf openapi` in favor of a positional argument
## [v0.7.2] - 2019-07-09

@@ -164,2 +173,3 @@

[v0.7.1]: https://gitlab.com/GCSBOSS/nodecaf/-/tags/v0.7.1
[v0.7.1]: https://gitlab.com/GCSBOSS/nodecaf/-/tags/v0.7.2
[v0.7.2]: https://gitlab.com/GCSBOSS/nodecaf/-/tags/v0.7.2
[v0.7.3]: https://gitlab.com/GCSBOSS/nodecaf/-/tags/v0.7.3
const path = require('path');
const ejs = require('ejs');
const fs = require('fs');
const cli = require('cli');
const template = name => fs.readFileSync(
path.resolve(__dirname, '../codegen', name + '.ejs'),
'utf-8'
);

@@ -28,16 +32,3 @@ const getConfFile = {

function generateMainFile(projDir){
let src = `
const { AppServer } = require('nodecaf');
const api = require('./api');\n
module.exports = function init(conf){
let app = new AppServer(conf);\n
let shared = {};
app.expose(shared);\n
app.onRouteError = function(input, err, send){\n\n };\n
app.beforeStart = async function(){\n\n };\n
app.afterStop = async function(){\n\n };\n
app.api(api);\n
return app;
}\n`;
let src = ejs.render(template('main'), {}, {});
fs.mkdirSync(projDir + '/lib');

@@ -49,4 +40,3 @@ fs.writeFileSync(projDir + '/lib/main.js', src);

function generateAPIFile(projDir){
let src = `
module.exports = function({ post, get, del, head, patch, put }){\n\n}\n`;
let src = ejs.render(template('api'), {}, {});
fs.writeFileSync(projDir + '/lib/api.js', src);

@@ -56,9 +46,4 @@ }

// Create BIN folder and the run binary.
function generateRunFile({ confPath, confType }, projDir, projName){
let cps = confPath ? `,\n confPath: '${confPath}'` : '';
let cts = confType ? `,\n confType: '${confType}'` : '';
let src = `#!node\n
const { run } = require('nodecaf');
run({\n init: require('../lib/main')${cps}${cts}\n});\n`;
function generateRunFile(data, projDir, projName){
let src = ejs.render(template('run'), data, {});
fs.mkdirSync(projDir + '/bin/');

@@ -68,41 +53,44 @@ fs.writeFileSync(projDir + '/bin/' + projName + '.js', src);

module.exports = function init(input){
input = input || cli.parse({
path: [ 'p', 'Project root directory (defaults to working dir)', 'file', undefined ],
confPath: [ 'c', 'Conf file path', 'file', undefined ],
confType: [ false, 'Conf file extension', 'string', 'toml' ],
name: [ 'n', 'A name/title for the app', 'string', undefined ]
});
module.exports = {
let projDir = path.resolve(process.cwd(), input.path || '.');
let pkgJSONPath = path.resolve(projDir, 'package.json');
summary: 'Generates a skelleton Nodecaf project file structure in the current directory',
options: {
path: [ 'p', 'Project root directory (defaults to working dir)', 'path' ],
confPath: [ 'c', 'Conf file path', 'file' ],
confType: [ false, 'Conf file extension', 'type', 'toml' ],
name: [ 'n', 'Name/title for the app (defaults to package.json\'s)', 'string' ]
},
// Check for package.json
if(!fs.existsSync(pkgJSONPath))
throw new Error('package.json not found in: ' + pkgJSONPath);
callback(input){
let pkgInfo = require(pkgJSONPath);
let projName = input.name || pkgInfo.name || 'my-app';
let projDir = path.resolve(process.cwd(), input.path || '.');
let pkgJSONPath = path.resolve(projDir, 'package.json');
if(fs.existsSync(projDir + '/lib'))
throw new Error('The \'lib\' directory already exists');
// Check for package.json
if(!fs.existsSync(pkgJSONPath))
throw new Error('package.json not found in: ' + pkgJSONPath);
if(fs.existsSync(projDir + '/bin'))
throw new Error('The \'bin\' directory already exists');
let pkgInfo = require(pkgJSONPath);
let projName = input.name || pkgInfo.name || 'my-app';
input.confType = generateConfFile(input);
generateRunFile(input, projDir, projName);
generateMainFile(projDir);
generateAPIFile(projDir);
if(fs.existsSync(projDir + '/lib'))
throw new Error('The \'lib\' directory already exists');
// Add binary to package.json.
pkgInfo.bin = { [projName]: 'bin/' + projName + '.js' };
fs.writeFileSync(pkgJSONPath, JSON.stringify(pkgInfo));
if(fs.existsSync(projDir + '/bin'))
throw new Error('The \'bin\' directory already exists');
if(!('nodecaf' in (pkgInfo.dependencies || [])))
console.log('Install nodecaf localy with:\n npm i --no-optional nodecaf');
console.log('Install your app run binary with:\n npm link');
input.confType = generateConfFile(input);
generateRunFile(input, projDir, projName);
generateMainFile(projDir);
generateAPIFile(projDir);
// Add binary to package.json.
pkgInfo.bin = { [projName]: 'bin/' + projName + '.js' };
fs.writeFileSync(pkgJSONPath, JSON.stringify(pkgInfo));
if(!('nodecaf' in (pkgInfo.dependencies || [])))
console.log('Install nodecaf localy with:\n npm i --no-optional nodecaf');
console.log('Install your app run binary with:\n npm link');
}
};
module.exports.description = 'Generates a skelleton Nodecaf project file ' +
'structure in the current directory';
const path = require('path');
const fs = require('fs');
const cli = require('cli');
const YAML = require('yaml');

@@ -15,38 +14,37 @@

module.exports = function openapi(input){
input = input || cli.parse({
path: [ 'p', 'Project root directory (defaults to working dir)', 'file', undefined ],
module.exports = {
summary: 'Generates an Open API compliant document of a given Nodecaf API',
options: {
path: [ 'p', 'Project root directory (defaults to working dir)', 'path' ],
apiPath: [ false, 'The path to your API file (defaults to ./lib/api.js)', 'file', './lib/api.js' ],
type: [ 't', 'A type of output file [yaml || json] (defaults to json)', 'string', 'yaml' ],
confPath: [ 'c', 'Conf file path', 'file', undefined ],
confType: [ false, 'Conf file extension', 'string', 'toml' ],
outFile: [ 'o', 'Output file (required)', 'file', undefined ]
});
type: [ 't', 'A type of output file [yaml || json] (defaults to json)', 'type', 'yaml' ],
confPath: [ 'c', 'Conf file path', 'file' ],
confType: [ false, 'Conf file extension', 'type', 'toml' ]
},
expectedArgs: [ 'OUTFILE' ],
callback(input, outfile){
let projDir = path.resolve(process.cwd(), input.path || '.');
let pkgJSONPath = path.resolve(projDir, 'package.json');
let projDir = path.resolve(process.cwd(), input.path || '.');
let pkgJSONPath = path.resolve(projDir, 'package.json');
// Check for package.json
if(!fs.existsSync(pkgJSONPath))
throw new Error('package.json not found in: ' + pkgJSONPath);
// Check for package.json
if(!fs.existsSync(pkgJSONPath))
throw new Error('package.json not found in: ' + pkgJSONPath);
let apiPath = path.resolve(projDir, input.apiPath || 'none.none');
if(!fs.existsSync(apiPath))
throw new Error('api.js not found in: ' + apiPath);
if(input.confPath)
var settings = loadConf(input.confPath, input.confType);
let apiPath = path.resolve(projDir, input.apiPath);
if(!fs.existsSync(apiPath))
throw new Error('api.js not found in: ' + apiPath);
let doc = new APIDoc(settings);
doc.api(require(apiPath));
let specObject = doc.spec();
if(input.confPath)
var settings = loadConf(input.confPath, input.confType);
let type = input.type || 'json';
let output = stringify[type](specObject);
outfile = path.resolve(projDir, outfile || './output.' + type);
let doc = new APIDoc(settings);
doc.api(require(apiPath));
let specObject = doc.spec();
let type = input.type || 'json';
let output = stringify[type](specObject);
let outFile = path.resolve(projDir, input.outFile || './output.' + type);
fs.writeFileSync(outFile, output);
fs.writeFileSync(outfile, output);
}
};
module.exports.description = 'Generates an Open API compliant document of a ' +
'given Nodecaf API';
{
"name": "nodecaf",
"version": "0.7.2",
"version": "0.7.3",
"description": "Nodecaf is an Express framework for developing REST APIs in a quick and convenient manner.",

@@ -40,4 +40,5 @@ "main": "lib/main.js",

"bunyan": "^1.8.12",
"cli": "^1.0.1",
"compression": "^1.7.4",
"eclipt": "^0.1.2",
"ejs": "^2.6.2",
"express": "^4.17.1",

@@ -44,0 +45,0 @@ "express-fileupload": "^1.1.5",

@@ -507,3 +507,2 @@ # [Nodecaf](https://gitlab.com/GCSBOSS/nodecaf)

- `-o --outFile file`: A file path to save the generated document (required)
- `-p --path directory`: Project root directory (defaults to working dir)

@@ -514,1 +513,4 @@ - `--apiPath file`: A path to your project's API file (defaults to `lib/api.js`)

- `--confType (yaml | toml)`: The type of the given config file
**Arguments**
- `outFile`: A file path to save the generated document (required)

@@ -22,3 +22,3 @@ //const wtf = require('wtfnode');

describe('nodecaf init', () => {
const init = require('../lib/cli/init');
const { callback: init } = require('../lib/cli/init');

@@ -61,5 +61,3 @@ afterEach(function(){

tmp.addFile('res/nmless-package.json', './foo/package.json');
const cli = require('cli');
cli.setArgv(['thing', '-p', './foo']);
init();
init({ path: './foo' });
let pkgInfo = require(tmp.dir + '/foo/package.json');

@@ -90,3 +88,3 @@ assert.equal(pkgInfo.bin['my-app'], 'bin/my-app.js');

describe('nodecaf openapi', () => {
const openapi = require('../lib/cli/openapi');
const { callback: openapi } = require('../lib/cli/openapi');
const SwaggerParser = require('swagger-parser');

@@ -104,6 +102,3 @@

tmp.addFile('res/test-package.json', './package.json');
const cli = require('cli');
cli.setArgv(['thing']);
assert.throws( () =>
openapi(), /api.js not found/g );
assert.throws( () => openapi({}), /api.js not found/g );
});

@@ -125,3 +120,3 @@

openapi({ apiPath: './api.js', outFile: './outfile.yml' });
openapi({ apiPath: './api.js' }, './outfile.yml');

@@ -133,18 +128,2 @@ SwaggerParser.validate('./outfile.yml', done);

describe('nodecaf -h', () => {
const help = require('../lib/cli/help');
it('Should output the top-level CLI help', () => {
let text = help();
assert(/Commands\:/.test(text));
assert(text.length > 100);
});
});
describe('nodecaf -v', () => {
const version = require('../lib/cli/version');
it('Should output a proper version number', () => {
assert(/^v\d+\.\d+\.\d+$/.test(version()));
});
});
});

@@ -151,0 +130,0 @@

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