Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full npm instead of a makefile #1128

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
t.*
coverage
node_modules
package-lock.json
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ Have Node.js installed. `sudo npm install -g livescript`

After, run `lsc -h` for more information.

### Compilation, Livefile, Live and npm usage

To compile, you can use the `npm run`. The command will look like this:

`npm run [options]`

Here the options:

- `browser`: compile the lib into 2 files, `livescript.js` and `livescript.min.js`. You need to run `lib` before to be sure the lib is correctly build before.
- `clean`: remove the following directories: browser, lib and coverage.
- `coverage`: run istanbul to get the package coverage.
- `lib`: compile the lib itself, creating the lib directory and filling it up with all the js files composing the livescript lib.
- `package`: (re)generating the `package.json` from the `package.json.ls`.
- `test`: launch the test script. You need to compile the lib before if you want to test your last modifications.

### Source
[git://github.com/gkz/LiveScript.git](git://github.com/gkz/LiveScript.git)
Expand Down
160 changes: 160 additions & 0 deletions index.ls
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# REQUIRES ########################

require! {
bach
fs
optionator
'prelude-ls': { each, map }
}

# VARS ############################

options =
* option: \browser
alias: \b
type: \Boolean
description: 'Compile livescript.js and livescript.min.js'
* option: \clean
alias: \c
type: \Boolean
description: 'Remove lib, coverage and browser directories'
* option: \coverage
alias: \i
type: \Boolean
description: 'Run the coverage (with istanbul)'
* option: \lib
alias: \l
type: \Boolean
description: 'Compile the lib'
* option: \package
alias: \p
type: \Boolean
description: 'Generate the package.json'

# FUNCTIONS #######################

create-dir = (dir, cb) !-->
console.log "creating the directory [ #dir ]"
er <-! fs.mkdir dir
if er? and er.code isnt \EEXIST then cb e, void
else
if er? and er.code is \EEXIST
console.log "Directory [ #dir ] already exists"
else console.log "Directory [ #dir ] CREATED"
cb void 2

generic-cb = (err, ok) !-> if err? then console.log err

preroll = ->
require! './package': {version}
"""// Generated by LiveScript #version\n
// LiveScript #version
// Copyright (c) Jeremy Ashkenas, Satoshi Murakami, George Zahariev
// Released under the MIT License
// https://raw.githubusercontent.com/gkz/LiveScript/master/LICENSE\n
"""

# CORE ############################

try
op = optionator {options}
opts = op.parseArgv process.argv
switch
# compiling into browser directory #########################################
| opts.browser
require! {browserify, 'uglify-js':{minify}}
# function to compile into livescript.js
compile-ls = (cb) !->
console.log 'Compiling for livescript.js ...'
b = browserify \./lib/browser.js, {require: \./lib/browser.js}
(err, buf) <- b.bundle!
if err? then cb e, void
else
try
fs.writeFileSync \./browser/livescript.js, (preroll! ++ buf)
console.log '==> livescript.js COMPILED'
cb void 3
catch
cb e, void
# uglifying livescript.js into livescript.min.js
uglifying = (cb) !->
console.log 'Uglifying into livescript-min.js...'
try
code = fs.readFileSync \./browser/livescript.js, \utf-8
res = minify code, output: {comments: yes}
if res.error? then cb e, void
else
if res.warnings?
console.log '====> UGLIFY WARNINGS <====='
JSON.stringify res.warnings |> console.log
fs.writeFileSync \./browser/livescript-min.js, res.code
console.log '==> livescript-min.js UGLIFIED'
cb void 4
catch
cb e, void
# list of all actions done to compile into browser
actions =
create-dir \browser
compile-ls
uglifying
# compiling and uglifying
(bach.series actions) generic-cb
# cleaning the repository (removing coverage, lib and browser) #############
| opts.clean
rmd = (dir) -> (cb) !->
console.log "removing `#dir`"
fs.rm dir, {force: yes, recursive: yes}, cb
args = <[browser lib coverage]> |> map rmd
(bach.series args) (err, ok) !->
console.log if err? then err else 'dirs removed'
# Executing istanbul #######################################################
| opts.coverage
require! { child_process: {spawn} }
istanbul =
if process.platform is \win32 then 'node_modules\\.bin\\istanbul.cmd'
else 'node_modules/.bin/istanbul'
opts = stdio: [process.stdin, process.stdout, process.stderr]
spawn istanbul, ['cover', './scripts/test'], opts
# compiling the lib ########################################################
| opts.lib
# generating the parser
generate-grammar = (cb) !->
console.log 'Generating parser...'
require! { path: {resolve, dirname}, '.': {compile}, './lib/grammar' }
target = resolve dirname(module.filename), \./lib/parser.js
try
parser = grammar.generate!
fs.writeFileSync target, parser ++ '\n'
console.log '==> parser GENERATED'
cb void 2
catch
cb e, void
# compiling files from src to lib
compile-lib = (cb) !->
require! '.': {compile}
try
mapper = (file) !->
console.log "compiling '#file'..."
code = fs.readFileSync "./src/#file", \utf-8
res = compile code, {bare: yes}
fs.writeFileSync "./lib/#{file.split \. .0}.js", res
fs.readdirSync \./src |> each mapper
catch
cb e, void
# doing all actions relative to lib
actions =
create-dir \lib
generate-grammar
compile-lib
(bach.series actions) generic-cb
# generating the package.json ##############################################
| opts.package
require! '.': {compile}
pkg = fs.readFileSync \./package.json.ls, \utf-8
res = compile pkg, json: yes
fs.writeFileSync \./package.json, res
console.log 'package.json (re)generated'
# Help #####################################################################
| otherwise => console.log op.generateHelp!
catch
console.log e
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@
"lsc": "./bin/lsc"
},
"scripts": {
"pretest": "make force && make force",
"test": "make test",
"browser": "node bin/lsc index.ls --browser",
"clean": "node bin/lsc index.ls --clean",
"coverage": "node bin/lsc index.ls --coverage",
"lib": "node bin/lsc index.ls --lib",
"package": "node bin/lsc index.ls --package",
"test": "node script/test",
"posttest": "git checkout -- lib"
},
"preferGlobal": true,
Expand All @@ -43,15 +47,16 @@
"url": "git://github.com/gkz/LiveScript.git"
},
"dependencies": {
"prelude-ls": "~1.2.1",
"optionator": "~0.9.1",
"prelude-ls": "~1.2.1",
"source-map": "=0.6.1",
"source-map-support": "=0.5.6"
},
"devDependencies": {
"jison": "0.4.18",
"uglify-js": "~2.6.4",
"bach": "^2.0.1",
"browserify": "^13.3.0",
"istanbul": "~0.4.3",
"browserify": "^13.3.0"
"jison": "0.4.18",
"uglify-js": "~3.17.4"
}
}
17 changes: 11 additions & 6 deletions package.json.ls
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ bin:
lsc: './bin/lsc'

scripts:
pretest: 'make force && make force'
test: 'make test'
browser: 'node bin/lsc index.ls --browser'
clean: 'node bin/lsc index.ls --clean'
coverage: 'node bin/lsc index.ls --coverage'
lib: 'node bin/lsc index.ls --lib'
'package': 'node bin/lsc index.ls --package'
test: 'node script/test'
posttest: 'git checkout -- lib'

prefer-global: true
Expand All @@ -44,13 +48,14 @@ repository:
url: 'git://github.com/gkz/LiveScript.git'

dependencies:
'prelude-ls': '~1.2.1'
optionator: '~0.9.1'
'prelude-ls': '~1.2.1'
'source-map': '=0.6.1'
'source-map-support': '=0.5.6'

dev-dependencies:
jison: '0.4.18'
'uglify-js': '~2.6.4'
istanbul: '~0.4.3'
bach: '^2.0.1'
browserify: '^13.3.0'
istanbul: '~0.4.3'
jison: '0.4.18'
'uglify-js': '~3.17.4'
9 changes: 0 additions & 9 deletions scripts/preroll

This file was deleted.