Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eries Trisnadi committed Dec 24, 2017
2 parents a07c73f + abc66c5 commit a06eb88
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 21 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@
},
"scripts": {
"build": "run-s format build:*",
"build:dist": "run-s clean:dist bundle",
"build:dist": "run-s clean:dist bundle format:dist",
"build:docs": "run-s clean:docs mustache",
"bundle": "run-s bundle:*",
"bundle:cjs": "run-s \"rollup -c tools/build-cjs.js\"",
"bundle:es": "run-s \"rollup -c tools/build-es.js\"",
"format": "run-s \"lint --fix\"",
"format:dist": "prettier --write \"dist/**/{jaysn.es.js,jaysn.js}\"",
"clean:dist": "run-s \"rm -rf dist\"",
"clean:docs": "run-s \"rm -rf docs\" \"mkdir docs\"",
"coverage": "nyc report --reporter=text-lcov | coveralls",
Expand Down
13 changes: 8 additions & 5 deletions src/jaysn.js → src/DB.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { existsSync } from 'fs';
import { struct } from 'superstruct';
import Immutable from 'immutable';
import { cwd } from 'process';
import { join } from 'path';
import { File } from './adapters/File';
import { LocalStorage } from './adapters/LocalStorage';

export const JAYSN_PATH = join(cwd(), '.jaysn');
export const JAYSN_PATH = '.jaysn';

const IMMUTABLE_TYPE = [
'List',
Expand Down Expand Up @@ -39,7 +37,7 @@ const IMMUTABLE_WRITE = [
'updateIn',
];

export class Jaysn {
export class DB {
constructor(schema, options = {}) {
const defaultOpts = {
use: 'File',
Expand Down Expand Up @@ -100,7 +98,8 @@ export class Jaysn {
Immutable[K].prototype.write = () => {
const data = this.getState().toJS();

adapter.write(data);
this._state.push(Immutable.fromJS(adapter.write(data)));
this._stateId += 1;
return this.getState();
};
}
Expand All @@ -117,6 +116,8 @@ export class Jaysn {
IMMUTABLE_READ.forEach(method => {
this[method] = (...args) => {
const state = this.getState();
this._state.push(Immutable.fromJS(adapter.read()));
this._stateId += 1;

return state[method](...args);
};
Expand Down Expand Up @@ -167,3 +168,5 @@ export class Jaysn {
return this._state[this._stateId];
}
}

export default DB;
4 changes: 4 additions & 0 deletions src/Jaysn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { DB } from './DB';

export const jaysn = (...args) => new DB(...args);
export default jaysn;
7 changes: 0 additions & 7 deletions src/index.js

This file was deleted.

4 changes: 2 additions & 2 deletions test/Jaysn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { assert } from 'chai';
import { existsSync, unlinkSync } from 'fs';
import { fromJS } from 'immutable';
import { Jaysn } from '../src/index';
import { jaysn } from '../src/Jaysn';

const opts = {
source: 'db.json',
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('new Jaysn()', () => {
if (existsSync(opts.source)) {
unlinkSync(opts.source);
}
DB = new Jaysn(schema, opts);
DB = jaysn(schema, opts);
});

describe('.set(key, data).write()', () => {
Expand Down
12 changes: 7 additions & 5 deletions tools/build-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import json from 'rollup-plugin-json';
import saveLicense from 'uglify-save-license';
import stripBanner from 'rollup-plugin-strip-banner';
import nodeResolve from 'rollup-plugin-node-resolve';
import { capitalize } from './utils';
import pkg from '../package.json';

const copyright = readFileSync(join('tools', 'COPYRIGHT'), 'utf-8');
Expand All @@ -21,16 +22,17 @@ export default {
.replace('{pkg.homepage}', pkg.homepage)
.replace('{pkg.author}', pkg.author)
.replace('{pkg.license}', pkg.license),
name: pkg.name,
input: join(SRC_DIR, 'index.js'),
name: 'Jaysn',
input: join(SRC_DIR, `${capitalize(pkg.name)}.js`),
external: ['fs', 'process', 'util', ...Object.keys(pkg.dependencies)],
globals: {
immutable: 'immutable',
superstruct: 'Superstruct',
immutable: 'Immutable',
},
output: {
exports: 'named',
export: 'named',
file: join(DIST_DIR, `${pkg.name}.js`),
format: 'cjs',
format: 'umd',
},
plugins: [
nodeResolve(),
Expand Down
3 changes: 2 additions & 1 deletion tools/build-es.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import buble from 'rollup-plugin-buble';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import stripBanner from 'rollup-plugin-strip-banner';
import { capitalize } from './utils';
import pkg from '../package.json';

const copyright = readFileSync(join('tools', 'COPYRIGHT'), 'utf-8');
Expand All @@ -19,7 +20,7 @@ export default {
.replace('{pkg.author}', pkg.author)
.replace('{pkg.license}', pkg.license),
name: pkg.name,
input: join(SRC_DIR, 'index.js'),
input: join(SRC_DIR, `${capitalize(pkg.name)}.js`),
external: ['fs', 'process', 'util', ...Object.keys(pkg.dependencies)],
output: {
file: join(DIST_DIR, `${pkg.name}.es.js`),
Expand Down
5 changes: 5 additions & 0 deletions tools/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}

export default capitalize;

0 comments on commit a06eb88

Please sign in to comment.