From c5a7c1bd7756d0fdcff397a4ef9b20bf173ed2e5 Mon Sep 17 00:00:00 2001 From: othelarian Date: Sun, 3 Mar 2024 23:53:19 +0100 Subject: [PATCH 1/3] First step, finding test issue, keeping this in commit while moving to test MR --- .gitignore | 1 + Livefile | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 15 ++++++++---- package.json.ls | 56 ------------------------------------------ 4 files changed, 76 insertions(+), 61 deletions(-) create mode 100644 Livefile delete mode 100644 package.json.ls 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/Livefile b/Livefile new file mode 100644 index 000000000..fe0f10cd7 --- /dev/null +++ b/Livefile @@ -0,0 +1,65 @@ +# REQUIRES ######################## + +require! { + fs + bach + browserify + 'uglify-js': uglify +} + +# HELPERS & FUNCTIONS ############# + +create-dir = (dir-name, cb) !-> + # + # TODO + # + void + # + +# TASKS ########################### + +task 'tt', '', !-> + # + # + try + require! {'.': ls, fs} + filename = \test/data/runtime-error.ls + code = fs.readFileSync filename, \utf-8 + ls.run(code, {filename: filename, map: \embedded, warn: no}) + catch e + console.log \######################## + console.log e + # + +#task 'build' +#task 'build-browser' + +task 'browser', '', !-> + args = + fs.mkdir 'browser' + # + # TODO: crea + # + # + (bach.series) + # + +task 'coverage', '', !-> + # + # TODO: calling istanbul to check the coverage + # + void + # + +task 'clean', '', !-> + # + # TODO + # + console.log 'clean call' + # + # browser, lib, coverage + # + void + # + +# browser: diff --git a/package.json b/package.json index 0850036cc..d382a3694 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,12 @@ "lsc": "./bin/lsc" }, "scripts": { + "browser": "live browser", + "clean": "live clean", + "lib": "live lib", "pretest": "make force && make force", "test": "make test", - "posttest": "git checkout -- lib" + "test2": "node scripts/test" }, "preferGlobal": true, "repository": { @@ -43,15 +46,17 @@ "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", + "@othelarian/livefile": "^1.0.0", + "bach": "^2.0.1", + "browserify": "^13.3.0", "istanbul": "~0.4.3", - "browserify": "^13.3.0" + "jison": "0.4.18", + "uglify-js": "~2.6.4" } } diff --git a/package.json.ls b/package.json.ls deleted file mode 100644 index ec14e243f..000000000 --- a/package.json.ls +++ /dev/null @@ -1,56 +0,0 @@ -name: 'livescript' -version: '1.6.1' - -description: 'LiveScript is a language which compiles to JavaScript. It has a straightforward mapping to JavaScript and allows you to write expressive code devoid of repetitive boilerplate. While LiveScript adds many features to assist in functional style programming, it also has many improvements for object oriented and imperative programming.' - -keywords: - 'language' - 'compiler' - 'coffeescript' - 'coco' - 'javascript' - 'functional' - -author: 'George Zahariev ' -homepage: 'http://livescript.net' -bugs: 'https://github.com/gkz/LiveScript/issues' -license: 'MIT' - -engines: - node: '>= 0.8.0' -directories: - lib: './lib' - bin: './bin' -files: - 'lib' - 'bin' - 'README.md' - 'LICENSE' - -main: './lib/' -browser: './lib/browser.js' -bin: - lsc: './bin/lsc' - -scripts: - pretest: 'make force && make force' - test: 'make test' - posttest: 'git checkout -- lib' - -prefer-global: true - -repository: - type: 'git' - url: 'git://github.com/gkz/LiveScript.git' - -dependencies: - 'prelude-ls': '~1.2.1' - optionator: '~0.9.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' - browserify: '^13.3.0' From 47d9faa558c360f07b23d9e9f521306e30c2e353 Mon Sep 17 00:00:00 2001 From: othelarian Date: Mon, 4 Mar 2024 23:44:18 +0100 Subject: [PATCH 2/3] Only building the lib directory is missing, everything else is ready --- Livefile | 65 ---------------------- README.md | 14 +++++ index.ls | 143 ++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 16 +++--- package.json.ls | 61 +++++++++++++++++++++ scripts/preroll | 9 --- 6 files changed, 226 insertions(+), 82 deletions(-) delete mode 100644 Livefile create mode 100644 index.ls create mode 100644 package.json.ls delete mode 100755 scripts/preroll diff --git a/Livefile b/Livefile deleted file mode 100644 index fe0f10cd7..000000000 --- a/Livefile +++ /dev/null @@ -1,65 +0,0 @@ -# REQUIRES ######################## - -require! { - fs - bach - browserify - 'uglify-js': uglify -} - -# HELPERS & FUNCTIONS ############# - -create-dir = (dir-name, cb) !-> - # - # TODO - # - void - # - -# TASKS ########################### - -task 'tt', '', !-> - # - # - try - require! {'.': ls, fs} - filename = \test/data/runtime-error.ls - code = fs.readFileSync filename, \utf-8 - ls.run(code, {filename: filename, map: \embedded, warn: no}) - catch e - console.log \######################## - console.log e - # - -#task 'build' -#task 'build-browser' - -task 'browser', '', !-> - args = - fs.mkdir 'browser' - # - # TODO: crea - # - # - (bach.series) - # - -task 'coverage', '', !-> - # - # TODO: calling istanbul to check the coverage - # - void - # - -task 'clean', '', !-> - # - # TODO - # - console.log 'clean call' - # - # browser, lib, coverage - # - void - # - -# browser: 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..7482c308a --- /dev/null +++ b/index.ls @@ -0,0 +1,143 @@ +# REQUIRES ######################## + +require! { + bach + fs + optionator + 'prelude-ls': { 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 + # + # TODO: changing browser_2 and lib_2 for real names + # + args = <[browser lib_2 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 + # + # TODO + # + actions = + create-dir \lib_2 + # + # + # + console.log \lib + # + # 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 d382a3694..45c733faf 100644 --- a/package.json +++ b/package.json @@ -33,12 +33,13 @@ "lsc": "./bin/lsc" }, "scripts": { - "browser": "live browser", - "clean": "live clean", - "lib": "live lib", - "pretest": "make force && make force", - "test": "make test", - "test2": "node scripts/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, "repository": { @@ -52,11 +53,10 @@ "source-map-support": "=0.5.6" }, "devDependencies": { - "@othelarian/livefile": "^1.0.0", "bach": "^2.0.1", "browserify": "^13.3.0", "istanbul": "~0.4.3", "jison": "0.4.18", - "uglify-js": "~2.6.4" + "uglify-js": "~3.17.4" } } diff --git a/package.json.ls b/package.json.ls new file mode 100644 index 000000000..1f6b72b60 --- /dev/null +++ b/package.json.ls @@ -0,0 +1,61 @@ +name: 'livescript' +version: '1.6.1' + +description: 'LiveScript is a language which compiles to JavaScript. It has a straightforward mapping to JavaScript and allows you to write expressive code devoid of repetitive boilerplate. While LiveScript adds many features to assist in functional style programming, it also has many improvements for object oriented and imperative programming.' + +keywords: + 'language' + 'compiler' + 'coffeescript' + 'coco' + 'javascript' + 'functional' + +author: 'George Zahariev ' +homepage: 'http://livescript.net' +bugs: 'https://github.com/gkz/LiveScript/issues' +license: 'MIT' + +engines: + node: '>= 0.8.0' +directories: + lib: './lib' + bin: './bin' +files: + 'lib' + 'bin' + 'README.md' + 'LICENSE' + +main: './lib/' +browser: './lib/browser.js' +bin: + lsc: './bin/lsc' + +scripts: + 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 + +repository: + type: 'git' + url: 'git://github.com/gkz/LiveScript.git' + +dependencies: + optionator: '~0.9.1' + 'prelude-ls': '~1.2.1' + 'source-map': '=0.6.1' + 'source-map-support': '=0.5.6' + +dev-dependencies: + 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"); From 57db0c6898e4314b30465d3c1d86728a18ef88c0 Mon Sep 17 00:00:00 2001 From: othelarian Date: Tue, 5 Mar 2024 12:08:09 +0100 Subject: [PATCH 3/3] Finalizing the index.ls, ready to fully replace the makefile --- index.ls | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/index.ls b/index.ls index 7482c308a..2795a9cd5 100644 --- a/index.ls +++ b/index.ls @@ -4,7 +4,7 @@ require! { bach fs optionator - 'prelude-ls': { map } + 'prelude-ls': { each, map } } # VARS ############################ @@ -104,10 +104,7 @@ try rmd = (dir) -> (cb) !-> console.log "removing `#dir`" fs.rm dir, {force: yes, recursive: yes}, cb - # - # TODO: changing browser_2 and lib_2 for real names - # - args = <[browser lib_2 coverage]> |> map rmd + args = <[browser lib coverage]> |> map rmd (bach.series args) (err, ok) !-> console.log if err? then err else 'dirs removed' # Executing istanbul ####################################################### @@ -120,16 +117,36 @@ try spawn istanbul, ['cover', './scripts/test'], opts # compiling the lib ######################################################## | opts.lib - # - # TODO - # + # 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_2 - # - # - # - console.log \lib - # + create-dir \lib + generate-grammar + compile-lib + (bach.series actions) generic-cb # generating the package.json ############################################## | opts.package require! '.': {compile}