-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
107 lines (90 loc) · 2.95 KB
/
Cakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{spawn} = require 'child_process'
{ncp} = require 'ncp'
mkdirp = require 'mkdirp'
fs = require 'fs'
#
# Change the following lines
#
# The file where your importer is
file = 'CharlesJSONImporter.coffee'
# Your importer identifier
# Should be same with the `identifier` property of your importer class
identifier = 'PawExtensions.CharlesJSONImporter'
#
# End
#
extensions_dir = "#{ process.env.HOME }/Library/Containers/com.luckymarmot.Paw/Data/Library/Application Support/com.luckymarmot.Paw/Extensions/"
build_root_dir = "build"
build_dir = "#{ build_root_dir }/#{ identifier }"
# compile CoffeeScript
build_coffee = (callback) ->
coffee = spawn 'coffee', ['-c', '-o', build_dir, file]
coffee.stderr.on 'data', (data) ->
process.stderr.write data.toString()
coffee.stdout.on 'data', (data) ->
process.stdout.write data.toString()
coffee.on 'exit', (code) ->
if code is 0
callback?()
else
console.error "Build failed with error: #{ code }"
# copy files to build directory
build_copy = () ->
fs.writeFileSync "#{ build_dir }/README.md", fs.readFileSync("./README.md")
fs.writeFileSync "#{ build_dir }/LICENSE", fs.readFileSync("./LICENSE")
# build: build CoffeeScript and copy files to build directory
build = (callback) ->
# mkdir build dir
mkdirp build_dir, (err) ->
if err
console.error err
else
build_coffee () ->
build_copy()
callback?()
# install: copy files to Extensions directory
install = (callback) ->
ncp build_dir, "#{ extensions_dir }/#{ identifier }", (err) ->
if err
console.error err
else
callback?()
# archive: create a zip archive from the build
archive = (callback) ->
zip_file = "#{ identifier.split('.').pop() }.zip"
# go to build dir
process.chdir "#{ build_root_dir }/"
# delete any previous zip
if fs.existsSync zip_file
fs.unlinkSync zip_file
# zip
zip = spawn 'zip', ["-r", zip_file, "#{ identifier }/"]
zip.stderr.on 'data', (data) ->
process.stderr.write data.toString()
zip.stdout.on 'data', (data) ->
process.stdout.write data.toString()
zip.on 'exit', (code) ->
if code is 0
callback?()
else
console.error "zip returned with error code: #{ code }"
task 'build', ->
build()
task 'test', ->
build () ->
# no test to run
task 'install', ->
build () ->
install()
task 'archive', ->
build () ->
archive()
task 'watch', ->
# find all files in directory
for filename in fs.readdirSync '.'
# only watch non-hidden files
if not filename.match(/^\./) and fs.lstatSync("./#{ filename }").isFile()
fs.watchFile "./#{ filename }", {persistent:true, interval:500}, (_event, _filename) ->
# when a file is changed, build and install
build () ->
install()