Skip to content

Commit

Permalink
Concat utility
Browse files Browse the repository at this point in the history
Signed-off-by: Mehmet Baker <[email protected]>
  • Loading branch information
mehmetb committed Apr 10, 2018
1 parent 6478d78 commit f703e02
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 1 deletion.
15 changes: 15 additions & 0 deletions builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const path = require('path');
const concat = require('./lib/concat');

concat([
path.join(__dirname, 'node_modules/webix/webix.js'),
path.join(__dirname, 'node_modules/webix/webix.js'),
path.join(__dirname, 'node_modules/webix/webix.js'),
path.join(__dirname, 'node_modules/webix/webix.js'),
path.join(__dirname, 'node_modules/webix/webix5.js'),
path.join(__dirname, 'node_modules/webix/webix.js'),
path.join(__dirname, 'node_modules/webix/webix.js'),
path.join(__dirname, 'node_modules/webix/webix.js'),
path.join(__dirname, 'node_modules/webix/webix.js')
],
path.join(__dirname, 'node_modules/vendors.js'));
39 changes: 39 additions & 0 deletions lib/concat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const fs = require('fs');
const path = require('path');
const {promisify} = require('util');
const readFile = promisify(fs.readFile);
const appendFile = promisify(fs.appendFile);

function spaces(str, maxLength) {
let ret = str;

for (let i = str.length; i < maxLength; ++i) {
ret += " ";
}

return ret;
}

async function concat(sources, target, dirname = path.join(__dirname, '../')) {
const maxLength = sources.reduce((max, cur) => {
if (cur.replace(dirname, '').length > max) return cur.replace(dirname, '').length;

return max;
}, 0);

console.log('Maxlength is', maxLength);

for (let i = 0; i < sources.length; ++i) {
console.log(`${spaces(sources[i].replace(dirname, ''), maxLength)} >> ${target.replace(dirname, '')}`);

const file = await readFile(sources[i]);
await appendFile(target, file);
}
}

module.exports = (sources, target) => {
concat(sources, target).catch((err) => {
console.trace(err);
process.exit(1);
});
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"css": "^2.2.1",
"vlq": "^1.0.0"
"vlq": "^1.0.0",
"webix": "^5.2.1"
}
}
49 changes: 49 additions & 0 deletions test/public/Datatable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import './webix/webix.js';

export default class Datatable {
constructor() {
this.init();
}

init() {
const div = document.createElement('div');

div.id = 'testA';
div.style.width = '500px';
div.style.height = '500px';

document.body.appendChild(div);
webix.ready(() => {
const grid = webix.ui({
container:"testA",
view:"datatable",
columns:[
{ id:"rank", header:"", css:"rank", width:50},
{ id:"title", header:"Film title",width:200},
{ id:"year", header:"Released" , width:80},
{ id:"votes", header:"Votes", width:100}
],
select:"row",
autoheight:true,
autowidth:true,
multiselect:true,

on:{
onSelectChange:function(){
var text = "Selected: "+grid.getSelectedId(true).join();
document.getElementById('testB').innerHTML = text;
}
},

data:[
{ id:1, title:"The Shawshank Redemption", year:1994, votes:678790, rating:9.2, rank:1, category:"Thriller"},
{ id:2, title:"The Godfather", year:1972, votes:511495, rating:9.2, rank:2, category:"Crime"},
{ id:3, title:"The Godfather: Part II", year:1974, votes:319352, rating:9.0, rank:3, category:"Crime"},
{ id:4, title:"The Good, the Bad and the Ugly", year:1966, votes:213030, rating:8.9, rank:4, category:"Western"},
{ id:5, title:"Pulp fiction", year:1994, votes:533848, rating:8.9, rank:5, category:"Crime"},
{ id:6, title:"12 Angry Men", year:1957, votes:164558, rating:8.9, rank:6, category:"Western"}
]
});
});
}
}
1 change: 1 addition & 0 deletions test/public/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link type="text/css" rel="stylesheet" href='webix/webix.css' />
</head>
<body>
<script src="index.js" type="module"></script>
Expand Down
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('path');
const app = express();

const staticPath = path.join(__dirname, './public');
app.use(express.static('../node_modules'));
app.use(cssServer(staticPath));
app.use(express.static(staticPath));

Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,7 @@ vary@~1.1.2:
vlq@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/vlq/-/vlq-1.0.0.tgz#8101be90843422954c2b13eb27f2f3122bdcc806"

webix@^5.2.1:
version "5.2.1"
resolved "https://registry.yarnpkg.com/webix/-/webix-5.2.1.tgz#9d9ffbc21276011c1d2c5f645119df5db0290f54"

0 comments on commit f703e02

Please sign in to comment.