-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70786f7
commit 9f1a90d
Showing
1 changed file
with
22 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,34 @@ | ||
/* eslint no-console: 0 */ | ||
var fs = require('fs'); | ||
var current = require('../completions.json'); | ||
// file paths | ||
var fname_css = 'uikit/dist/css/uikit.css'; | ||
var fname_js = 'uikit/dist/js/uikit.js'; | ||
var outfile = 'completions.json'; | ||
|
||
function remove_duplicates(arr) { | ||
var _set = {}; | ||
arr.forEach(function(el) { _set[el] = true; }); | ||
return Object.keys(_set); | ||
} | ||
|
||
// classes: uk-* from CSS | ||
function css() { | ||
var src = fs.readFileSync(fname_css).toString(); | ||
var classes = src.match(/\.(uk-[a-z\d\-]+)/g); | ||
classes = remove_duplicates(classes).map(function(cls) { return cls.substr(1); }); // remove leading dot | ||
|
||
return classes; | ||
} | ||
// file paths | ||
var css = 'uikit/dist/css/uikit.css'; | ||
var js = 'uikit/dist/js/uikit.js'; | ||
|
||
// attributes: uk-* from JS | ||
function js() { | ||
var src = fs.readFileSync(fname_js).toString(); | ||
var attrs = src.match(/uk-[a-z\d\-]+/g); | ||
return remove_duplicates(attrs); | ||
if (!fs.existsSync(css) || !fs.existsSync(js)) { | ||
console.log('Can\'t locate UIkit files.'); | ||
} | ||
|
||
function atom() { | ||
var _css = css(), | ||
_js = js(), | ||
lst = _css.concat(_js); | ||
var list = merge( | ||
read(css).match(/\.uk-[a-z\d-]+/g).map(cls => cls.substr(1)), | ||
read(js).match(/uk-[a-z\d-]+/g) | ||
); | ||
|
||
lst = remove_duplicates(lst); | ||
list.forEach(item => !~current.indexOf(item) && console.log('added:', item)); | ||
current.forEach(item => !~list.indexOf(item) && console.log('removed:', item)); | ||
|
||
lst = lst.sort((a, b) => a < b ? -1 : 1); | ||
fs.writeFileSync('completions.json', JSON.stringify(list, null, 4)); | ||
console.log('Done.'); | ||
|
||
lst.forEach(cls => { | ||
if (current.indexOf(cls) < 0) { | ||
console.log('added:', cls); | ||
} | ||
}); | ||
current.forEach(cls => { | ||
if (lst.indexOf(cls) < 0) { | ||
console.log('removed:', cls); | ||
} | ||
}); | ||
|
||
fs.writeFileSync(outfile, JSON.stringify(lst, null, 4)); | ||
console.log('Done.'); | ||
function merge(...arr) { | ||
return Array.from( | ||
new Set( | ||
Array.prototype.concat.apply(arr[0], arr.slice(1)) | ||
) | ||
).sort(); | ||
} | ||
|
||
if (fs.existsSync(fname_css) && fs.existsSync(fname_js)) { | ||
atom(); | ||
} else { | ||
console.log("Can't locate UIkit files"); | ||
} | ||
function read(file) { | ||
return fs.readFileSync(file).toString(); | ||
} |