Skip to content

Commit 7422244

Browse files
Actually publish the browser compilers to NPM (#5186)
* Actually publish the browser compilers to NPM * Transpile and minify modern browser compiler; add to lib/ folder; update docs
1 parent d23919c commit 7422244

File tree

17 files changed

+59
-11252
lines changed

17 files changed

+59
-11252
lines changed

Cakefile

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ header = """
2121
* CoffeeScript Compiler v#{CoffeeScript.VERSION}
2222
* https://coffeescript.org
2323
*
24-
* Copyright 2011, Jeremy Ashkenas
24+
* Copyright 2011-#{new Date().getFullYear()}, Jeremy Ashkenas
2525
* Released under the MIT License
2626
*/
2727
"""
@@ -67,19 +67,20 @@ build = (callback) ->
6767
buildExceptParser callback
6868

6969
transpile = (code, options = {}) ->
70-
options.minify = process.env.MINIFY isnt 'false'
71-
options.transform = process.env.TRANSFORM isnt 'false'
70+
options.minify = process.env.MINIFY isnt 'false'
71+
options.transform = process.env.TRANSFORM isnt 'false'
72+
options.sourceType ?= 'script'
7273
babel = require '@babel/core'
7374
presets = []
7475
# Exclude the `modules` plugin in order to not break the `}(this));`
7576
# at the end of the `build:browser` code block.
7677
presets.push ['@babel/env', {modules: no}] if options.transform
7778
presets.push ['minify', {mangle: no, evaluate: no, removeUndefined: no}] if options.minify
7879
babelOptions =
80+
presets: presets
7981
compact: not options.minify
8082
comments: not options.minify
81-
presets: presets
82-
sourceType: 'script'
83+
sourceType: options.sourceType
8384
{ code } = babel.transform code, babelOptions unless presets.length is 0
8485
code
8586

@@ -163,19 +164,24 @@ task 'build:browser', 'merge the built scripts into a single file for use in a b
163164
}
164165
}(this));
165166
"""
166-
moduleCode = """
167+
moduleCode = transpile """
167168
#{code}
168169
169170
export default CoffeeScript;
170171
const { VERSION, compile, eval: evaluate, load, run, runScripts } = CoffeeScript;
171172
export { VERSION, compile, evaluate as eval, load, run, runScripts };
172-
"""
173-
for folder in ['browser-compiler', 'browser-compiler-modern']
174-
outputFolder = "docs/v#{majorVersion}/#{folder}"
173+
""", {sourceType: 'module'}
174+
outputFolders = [
175+
"docs/v#{majorVersion}/browser-compiler-legacy"
176+
"docs/v#{majorVersion}/browser-compiler-modern"
177+
"lib/coffeescript-browser-compiler-legacy"
178+
"lib/coffeescript-browser-compiler-modern"
179+
]
180+
for outputFolder in outputFolders
175181
fs.mkdirSync outputFolder unless fs.existsSync outputFolder
176182
fs.writeFileSync "#{outputFolder}/coffeescript.js", """
177183
#{header}
178-
#{if folder is 'browser-compiler' then scriptCode else moduleCode}
184+
#{if outputFolder.includes('legacy') then scriptCode else moduleCode}
179185
"""
180186

181187
task 'build:browser:full', 'merge the built scripts into a single file for use in a browser, and test it', ->
@@ -487,7 +493,7 @@ task 'test', 'run the CoffeeScript language test suite', ->
487493

488494

489495
task 'test:browser', 'run the test suite against the merged browser script', ->
490-
source = fs.readFileSync "docs/v#{majorVersion}/browser-compiler/coffeescript.js", 'utf-8'
496+
source = fs.readFileSync "lib/coffeescript-browser-compiler-legacy/coffeescript.js", 'utf-8'
491497
result = {}
492498
global.testingBrowser = yes
493499
(-> eval source).call result

docs/browser-compiler

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2/browser-compiler
1+
v2/browser-compiler-legacy

docs/browser-compiler-legacy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v2/browser-compiler-legacy

docs/v2/browser-compiler-legacy/coffeescript.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)