Skip to content

Commit

Permalink
Merge pull request #58 from conversation/18363-upgrade-shelljs
Browse files Browse the repository at this point in the history
Upgrade shelljs
  • Loading branch information
nickbrowne authored Nov 15, 2024
2 parents cfb44a9 + 6de884d commit a7733ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
32 changes: 15 additions & 17 deletions Cakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'shelljs/global'
config.fatal = true

fs = require 'fs'
path = require 'path'
os = require 'os'
shell = require 'shelljs'

shell.config.fatal = true

# Gain access through PATH to all binaries added by `npm install`
# Rewrite when https://github.com/arturadib/shelljs/issues/32 is fixed
Expand All @@ -16,24 +16,22 @@ option '', '--verbose', 'Show nodeunit-output for test-task'
task 'test', 'Run all tests', (options) ->
console.log 'Running tests... (is your webclient up-to-date and nodeunit installed?)'

config.silent = true unless options['verbose']
exec 'nodeunit tests.coffee', (status, stdout, stderr) ->
shell.config.silent = true unless options['verbose']
shell.exec 'nodeunit tests.coffee', (status, stdout, stderr) ->
if status == 0
console.log 'All tests succeeded!'
else
console.log "Some tests failed (error: #{status}). Try --verbose."
process.exit(1) if status isnt 0
config.silent = false
shell.config.silent = false

# This is only needed to be able to refer to the line numbers of crashes
task 'build', 'Build the .js files', ->
console.log 'Compiling Coffee from src to lib'
exec "coffee --compile --bare --output lib/ src/"
shell.exec "coffee --compile --bare --output lib/ src/"

makeUgly = (infile, outfile) ->
# Uglify compile the JS
source = cat infile

UglifyJS = require 'uglify-js'

unminifiedCode = fs.readFileSync(infile, "utf8")
Expand All @@ -49,9 +47,9 @@ makeUgly = (infile, outfile) ->

code = result.code

smaller = Math.round((1 - (code.length / source.length)) * 100)
smaller = Math.round((1 - (code.length / unminifiedCode.length)) * 100)

code.to outfile
fs.writeFileSync(outfile, code, "utf8")

console.log "Uglified: #{smaller}% smaller (#{code.length} bytes} written to #{outfile}"

Expand All @@ -60,14 +58,14 @@ expandNames = (names) -> ("src/#{c}.coffee" for c in names).join ' '
compile = (filenames, dest) ->
filenames = expandNames filenames
# I would really rather do this in pure JS.
exec "coffee -j #{dest}.uncompressed.js -c #{filenames}"
shell.exec "coffee -j #{dest}.uncompressed.js -c #{filenames}"
console.log "Uglifying #{dest}"
makeUgly "#{dest}.uncompressed.js", "#{dest}.js"

buildtype = (name) ->
filenames = ['types/web-prelude', "types/#{name}"]

if ls "src/types/#{name}-api.coffee"
if shell.ls "src/types/#{name}-api.coffee"
filenames.push "types/#{name}-api"

compile filenames, "webclient/#{name}"
Expand Down Expand Up @@ -99,7 +97,7 @@ task 'webclient', 'Build the web client into one file', ->

# TODO: This should also be closure compiled.
extrafiles = expandNames extras
exec "coffee --compile --output webclient/ #{extrafiles}"
shell.exec "coffee --compile --output webclient/ #{extrafiles}"

option '-V', '--version [version]', 'The new patch version'
task 'bump', 'Increase the patch level of the version, -V is optional', (options) ->
Expand All @@ -117,14 +115,14 @@ task 'bump', 'Increase the patch level of the version, -V is optional', (options
console.log "New version is #{version}"

throw new Error "Needs git" if not which "git"
if exec("git status --porcelain").output.match /^ M /m
if shell.exec("git status --porcelain").output.match /^ M /m
throw new Error "git status must be clean"

for file in ["package.json", "src/index.js", "src/client/web-prelude.coffee"]
sed '-i', oldVersion, version, file
shell.sed '-i', oldVersion, version, file

invoke "webclient"
exec "git commit -a -m 'Bump to #{version}'"
shell.exec "git commit -a -m 'Bump to #{version}'"

#task 'lightwave', ->
# buildclosure ['client/web-prelude', 'client/microevent', 'types/text-tp2'], 'lightwave'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"devDependencies": {
"optimist": ">= 0.2.4",
"nodeunit": "0.9.0",
"shelljs": "0.1.4",
"shelljs": "0.8.5",
"uglify-js": "3.19.3",
"websocket": "~1"
},
Expand Down

0 comments on commit a7733ae

Please sign in to comment.