UNPKG

2.27 kBtext/coffeescriptView Raw
1_ = require("lodash")
2os = require("os")
3fs = require("fs-extra")
4path = require("path")
5Promise = require("bluebird")
6pkg = require("../package.json")
7paths = require("./paths")
8
9fs = Promise.promisifyAll(fs)
10
11## ensure we have an electronVersion set in package.json
12if not electronVersion = pkg.electronVersion
13 throw new Error("Missing 'electronVersion' in ./package.json")
14
15module.exports = {
16 checkCurrentVersion: ->
17 pathToVersion = paths.getPathToVersion()
18
19 ## read in the version file
20 fs.readFileAsync(pathToVersion, "utf8")
21 .then (str) ->
22 version = str.replace("v", "")
23
24 ## and if it doesn't match the electron version
25 ## throw an error
26 if version isnt electronVersion
27 throw new Error("Currently installed version: '#{version}' does not match electronVersion: '#{electronVersion}")
28 else
29 process.exit()
30
31 checkExecExistence: ->
32 fs.statAsync(paths.getPathToExec())
33
34 move: (src, dest) ->
35 ## src is ./tmp/Cypress-darwin-x64
36 ## dest is ./dist/Cypress
37 fs.moveAsync(src, dest, {clobber: true})
38 .then ->
39 ## remove the tmp folder now
40 fs.removeAsync(path.dirname(src))
41
42 removeEmptyApp: ->
43 ## nuke the temporary blank /app
44 fs.removeAsync(paths.getPathToResources("app"))
45
46 packageAndExit: ->
47 @package()
48 .then =>
49 @removeEmptyApp()
50 .then ->
51 process.exit()
52
53 package: (options = {}) ->
54 pkgr = require("electron-packager")
55 icons = require("@cypress/core-icons")
56
57 pkgr = Promise.promisify(pkgr)
58
59 _.defaults(options, {
60 dist: paths.getPathToDist()
61 dir: "app"
62 out: "tmp"
63 name: "Cypress"
64 platform: os.platform()
65 arch: "x64"
66 asar: false
67 prune: true
68 overwrite: true
69 version: electronVersion
70 icon: icons.getPathToIcon("cypress.icns")
71 })
72
73 pkgr(options)
74 .then (appPaths) ->
75 appPaths[0]
76 .then (appPath) =>
77 ## and now move the tmp into dist
78 @move(appPath, options.dist)
79
80 .catch (err) ->
81 console.log(err.stack)
82 process.exit(1)
83
84 ensure: ->
85 Promise.join(
86 @checkCurrentVersion()
87 @checkExecExistence()
88 )
89
90 check: ->
91 @ensure()
92 .bind(@)
93 .catch(@packageAndExit)
94}
\No newline at end of file