Skip to content

Commit

Permalink
feat(hariko): replace parser logic, and remove old codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rymizuki committed Apr 28, 2019
1 parent bdf05cf commit 653f646
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 477 deletions.
2 changes: 1 addition & 1 deletion lib/hariko/resource.js
@@ -1,7 +1,7 @@
var fs = require('fs'),
_ = require('lodash'),
gaze = require('gaze');
var parser = require('./resource/parser'),
var parser = require('../hariko-parser'),
external = require('./resource/external'),
logger = require('../logger');
var Entries = require('./entries');
Expand Down
19 changes: 0 additions & 19 deletions lib/hariko/resource/external.js
Expand Up @@ -34,24 +34,5 @@ function read (dest, entry) {
return JSON.parse(raw);
}

function filename (method, uri) {
var path_fragments = uri.path.replace(/:/g, '').split(/\//);
var queries = [];
for (var i = 0; i < uri.queries.length; i++) {
var query = uri.queries[i];
if ('string' === typeof query) {
queries.push(query);
} else {
queries.push(query.name + '=' + encodeURIComponent(query.value));
}
}
var basename = (path_fragments.pop() || 'index') + (queries.length > 0 ? '?' + queries.join('&') : '') + '-' + method + '.json',
dirname = path.join.apply(path, path_fragments);
logger.debug('dirname :', dirname);
logger.debug('basename:', basename);
return path.join(dirname, basename);
}

exports.save = save;
exports.read = read;
exports.filename = filename;
190 changes: 0 additions & 190 deletions lib/hariko/resource/parser.js

This file was deleted.

32 changes: 0 additions & 32 deletions test/hariko/resource/external.js
Expand Up @@ -11,38 +11,6 @@ describe('resource/external', function () {
afterEach(function () {
subvert.cleanUp();
});
describe('.filename(method, uriObject)', function () {
describe('when give `GET /api/path/{to}{?page}`', function () {
it('should be `api/path/to?page-GET.json`', function () {
var filename = external.filename('GET', {
template: '/api/path/{to}{?page}',
path: '/api/path/:to',
queries: ['page']
});
expect(filename).to.be.eql('api/path/to?page-GET.json')
})
});
describe('when give `POST /api/path/`', function () {
it('should be `api/path/index-POST.json`', function () {
var filename = external.filename('POST', {
template: '/api/path/',
path: '/api/path/',
queries: []
});
expect(filename).to.be.eql('api/path/index-POST.json');
});
});
describe('when give `POST /api/path/to?page=1`', function () {
it('should be `/api/path/to?page=1`', function () {
var filename = external.filename('GET', {
template: '/api/path/{to}{?page}',
path: '/api/path/to',
queries: [{name: 'page', value: 1}]
});
expect(filename).to.be.eql('api/path/to?page=1-GET.json')
});
});
});

describe('.save(destribution, entries)', function () {
it('should be write json files', function () {
Expand Down

0 comments on commit 653f646

Please sign in to comment.