This repository has been archived by the owner on Jun 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Cakefile
100 lines (83 loc) · 2.77 KB
/
Cakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{exec} = require 'child_process'
run = (command, callback) ->
exec command, (err, stdout, stderr) ->
console.warn stderr if stderr
callback?() unless err
build = (callback) ->
run 'coffee -co lib src', callback
bundle = (callback) ->
run 'npm install', callback
task "build", "Build lib/ from src/", ->
build()
task "test", "Run tests", ->
build ->
{reporters} = require 'nodeunit'
reporters.default.run ['test']
task "fixtures", "Generate .coffee fixtures from .eco fixtures", ->
fs = require "fs"
path = require "path"
dir = "#{__dirname}/test/fixtures"
for filename in fs.readdirSync dir
if path.extname(filename) is ".eco"
eco = require "eco"
{preprocess} = require "eco/preprocessor"
basename = path.basename filename, ".eco"
source = fs.readFileSync "#{dir}/#{filename}", "utf-8"
fs.writeFileSync "#{dir}/#{basename}.coffee", preprocess source
task "dist", "Generate dist/eco.js", ->
build -> bundle ->
fs = require("fs")
coffee = require("coffee-script").compile
uglify = require("uglify-js")
read = (filename) ->
fs.readFileSync "#{__dirname}/#{filename}", "utf-8"
stub = (identifier) -> """
if (typeof #{identifier} !== 'undefined' && #{identifier} != null) {
module.exports = #{identifier};
} else {
throw 'Cannot require \\'' + module.id + '\\': #{identifier} not found';
}
"""
version = JSON.parse(read "package.json").version
modules =
"eco": read "lib/index.js"
"./compiler": read "lib/compiler.js"
"./preprocessor": read "lib/preprocessor.js"
"./scanner": read "lib/scanner.js"
"./util": read "lib/util.js"
"strscan": read "node_modules/strscan/lib/strscan.js"
"coffee-script": stub "CoffeeScript"
package = for name, source of modules
"""
'#{name}': function(module, require, exports) {
#{source}
}
"""
header = """
/**
* Eco Compiler v#{version}
* http://github.com/sstephenson/eco
*
* Copyright (c) 2011 Sam Stephenson
* Released under the MIT License
*/
"""
source = uglify """
this.eco = (function(modules) {
return function require(name) {
var fn, module = {id: name, exports: {}};
if (fn = modules[name]) {
fn(module, require, module.exports);
return module.exports;
} else {
throw 'Cannot find module \\'' + name + '\\'';
}
};
})({
#{package.join ',\n'}
})('eco');
"""
try
fs.mkdirSync "#{__dirname}/dist", 0755
catch err
fs.writeFileSync "#{__dirname}/dist/eco.js", "#{header}\n#{source}"