diff --git a/.gitignore b/.gitignore index 00aab34cd..805970a2a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ t.* coverage node_modules +package-lock.json \ No newline at end of file diff --git a/README.md b/README.md index 409e8c48a..e263c936e 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/index.ls b/index.ls new file mode 100644 index 000000000..2795a9cd5 --- /dev/null +++ b/index.ls @@ -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 diff --git a/package.json b/package.json index 0850036cc..45c733faf 100644 --- a/package.json +++ b/package.json @@ -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, @@ -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" } } diff --git a/package.json.ls b/package.json.ls index ec14e243f..1f6b72b60 100644 --- a/package.json.ls +++ b/package.json.ls @@ -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 @@ -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' \ No newline at end of file diff --git a/scripts/preroll b/scripts/preroll deleted file mode 100755 index 1bf90cc81..000000000 --- a/scripts/preroll +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env node - -var version = require("..").VERSION; -console.log("// Generated by LiveScript " + version - + "\n" - + "\n// LiveScript " + version - + "\n// Copyright (c) Jeremy Ashkenas, Satoshi Murakami, George Zahariev" - + "\n// Released under the MIT License" - + "\n// https://raw.githubusercontent.com/gkz/LiveScript/master/LICENSE");