Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Livefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
option \option \o \Boolean 'an option'

task 'valid', 'validating the Livefile', !->
console.log 'this is a Livefile!'
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ browser/livescript.js: $(LIB) browser scripts/preroll
browser/livescript-min.js: browser/livescript.js
$(UGLIFYJS) browser/livescript.js --mangle --comments "all" > browser/livescript-min.js

live: bin/live
./scripts/build-live

package.json: package.json.ls
$(LSC) --compile package.json.ls

Expand Down
43 changes: 43 additions & 0 deletions bin-src/live.ls
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require! {
fs, optionator, path
'prelude-ls': { List, Obj }
}

lspath = path.join path.dirname(__filename), '../lib'
ls = require lspath

options = [{ option: \help, alias: \h, type: \Boolean, description: '' }]
option = (option, alias, type, description) ->
options.push { option, alias, type, description }

tasks = {}
task = (name, desc, fn) -> tasks[name] = { desc, fn }

global.option = option
global.task = task

try
fs.readFileSync \Livefile \utf-8 |> ls.run
prepend = 'Usage: live [options]\n\nOptions:'
mlgth = Obj.keys tasks |> List.maximum-by (.length) |> (.length)
filler = (str) -> ' ' * (mlgth - str.length)
line = (acc, elt) -> "#{acc}#{elt.0}#{filler elt.0} #{elt.1.desc}\n"
append = Obj.obj-to-pairs tasks |> List.fold line, 'Commands:\n\n'
find-lsc = List.find-index ((elt) -> elt == /lsc$/), process.argv
args =
if find-lsc? then List.drop (1 + find-lsc), process.argv
else process.argv
args = List.reject ((elt) -> elt == /live.ls$/), process.argv
op = optionator { append, options, prepend }
opts = op.parseArgv args
switch
| opts.help => console.log op.generateHelp!
| opts._.length is 0 => console.log 'ERROR: no task to run!'
| opts._.length > 1 => console.log 'ERROR: too many tasks selected!'
| opts._.0 not in Obj.keys tasks
console.log "ERROR: task does not exist (#{opts._.0})!"
| _ => tasks[opts._.0].fn opts
catch e
switch e.code
| \ENOENT => console.log 'There is no Livefile at this package root'
| otherwise => console.log e
102 changes: 102 additions & 0 deletions bin/live
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env node

// Generated by LiveScript 1.6.1
var fs, optionator, path, ref$, List, Obj, lspath, ls, options, option, tasks, task, prepend, mlgth, filler, line, append, findLsc, args, op, opts, e;
fs = require('fs');
optionator = require('optionator');
path = require('path');
ref$ = require('prelude-ls'), List = ref$.List, Obj = ref$.Obj;
lspath = path.join(path.dirname(__filename), '../lib');
ls = require(lspath);
options = [{
option: 'help',
alias: 'h',
type: 'Boolean',
description: ''
}];
option = function(option, alias, type, description){
return options.push({
option: option,
alias: alias,
type: type,
description: description
});
};
tasks = {};
task = function(name, desc, fn){
return tasks[name] = {
desc: desc,
fn: fn
};
};
global.option = option;
global.task = task;
try {
ls.run(
fs.readFileSync('Livefile', 'utf-8'));
prepend = 'Usage: live [options]\n\nOptions:';
mlgth = function(it){
return it.length;
}(
List.maximumBy(function(it){
return it.length;
})(
Obj.keys(tasks)));
filler = function(str){
return repeatString$(' ', mlgth - str.length);
};
line = function(acc, elt){
return acc + "" + elt[0] + filler(elt[0]) + " " + elt[1].desc + "\n";
};
append = List.fold(line, 'Commands:\n\n')(
Obj.objToPairs(tasks));
findLsc = List.findIndex(function(elt){
return /lsc$/.exec(elt);
}, process.argv);
args = findLsc != null
? List.drop(1 + findLsc, process.argv)
: process.argv;
args = List.reject(function(elt){
return /live.ls$/.exec(elt);
}, process.argv);
op = optionator({
append: append,
options: options,
prepend: prepend
});
opts = op.parseArgv(args);
switch (false) {
case !opts.help:
console.log(op.generateHelp());
break;
case opts._.length !== 0:
console.log('ERROR: no task to run!');
break;
case !(opts._.length > 1):
console.log('ERROR: too many tasks selected!');
break;
case in$(opts._[0], Obj.keys(tasks)):
console.log("ERROR: task does not exist (" + opts._[0] + ")!");
break;
default:
tasks[opts._[0]].fn(opts);
}
} catch (e$) {
e = e$;
switch (e.code) {
case 'ENOENT':
console.log('There is no Livefile at this package root');
break;
default:
console.log(e);
}
}
function repeatString$(str, n){
for (var r = ''; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;
return r;
}
function in$(x, xs){
var i = -1, l = xs.length >>> 0;
while (++i < l) if (x === xs[i]) return true;
return false;
}
15 changes: 15 additions & 0 deletions scripts/build-live
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node

var fs = require("fs");
var path = require("path");

var realpath = path.dirname(fs.realpathSync(__filename));
var lib = path.join(realpath, "../lib");
var target = path.resolve(realpath, "../bin-src/live.ls");
var output = path.resolve(realpath, "../bin/live");

var ls = require(lib);

code = fs.readFileSync(target, "utf-8");
res = ls.compile(code, {bare: true});
fs.writeFileSync(output, "#!/usr/bin/env node\n\n" + res);