1 | _ = require 'lodash'
|
2 | path = require 'path'
|
3 | Packager = require './src/packager'
|
4 |
|
5 | class CommandBuild
|
6 | parseOptions: =>
|
7 | buildDir = process.cwd()
|
8 | pkg = @getPackageJSON(buildDir)
|
9 |
|
10 | options = {
|
11 | connector: @getConnectorName(pkg),
|
12 | tag: @getVersion(pkg),
|
13 | githubSlug: @getGithubSlug(pkg),
|
14 | ignitionVersion: @getIgnitionVersion(pkg),
|
15 | os: @getOS(),
|
16 | arch: @getArch(),
|
17 | buildDir: buildDir
|
18 | }
|
19 |
|
20 | unless options.os in ['darwin', 'windows', 'linux']
|
21 | return @panic new Error('Invalid OS, must be one of ["darwin", "windows", "linux"]')
|
22 |
|
23 | unless options.arch in ['386', 'amd64']
|
24 | return @panic new Error('Invalid ARCH, must be one of ["386", "amd64"]')
|
25 |
|
26 | return options
|
27 |
|
28 | getPackageJSON: (buildDir) =>
|
29 | try
|
30 | return require(path.join(buildDir, 'package.json'))
|
31 | catch error
|
32 | @panic error
|
33 |
|
34 | getGithubSlug: (pkg) =>
|
35 | { meshbluConnector } = pkg
|
36 | { githubSlug } = meshbluConnector
|
37 | return githubSlug
|
38 |
|
39 | getIgnitionVersion: (pkg) =>
|
40 | { meshbluConnector } = pkg
|
41 | { ignitionVersion } = meshbluConnector
|
42 | return ignitionVersion ? 'v1.0.6'
|
43 |
|
44 | getConnectorName: (pkg) =>
|
45 | { name } = pkg
|
46 | return name.replace('meshblu-connector-', '') if name.indexOf('meshblu-connector-') > -1
|
47 | return name.replace('meshblu-', '') if name.indexOf('meshblu-') > -1
|
48 | return name
|
49 |
|
50 | getVersion: (pkg) =>
|
51 | return "v#{pkg.version}"
|
52 |
|
53 | getOS: =>
|
54 | {platform} = process
|
55 | return 'windows' if platform == 'win32'
|
56 | return platform
|
57 |
|
58 | getArch: =>
|
59 | {arch} = process
|
60 | arch = process.env.PACKAGER_ARCH || arch
|
61 | return '386' if arch == 'ia32'
|
62 | return '386' if arch == 'x86'
|
63 | return '386' if arch == '386'
|
64 | return 'amd64'
|
65 |
|
66 | getFileName: (options) =>
|
67 | {os, arch} = options
|
68 | return "#{os}-#{arch}"
|
69 |
|
70 | getFileNameWithExt: (options) =>
|
71 | {os, fileName} = options
|
72 | ext = "tar.gz"
|
73 | ext = "zip" if os == "windows"
|
74 | return "#{fileName}.#{ext}"
|
75 |
|
76 | getExeExt: (options) =>
|
77 | {os} = options
|
78 | return ".exe" if os == "windows"
|
79 | return ""
|
80 |
|
81 | run: =>
|
82 | options = @parseOptions()
|
83 | options.fileName = @getFileName options
|
84 | options.fileNameWithExt = @getFileNameWithExt options
|
85 | options.exeExt = @getExeExt options
|
86 |
|
87 | console.log "### packaging #{options.connector} #{options.tag} for #{options.os}-#{options.arch}"
|
88 | packager = new Packager options
|
89 | packager.run (error) =>
|
90 | return @panic error if error?
|
91 | console.log '### done!'
|
92 | process.exit 0
|
93 |
|
94 | panic: (error) =>
|
95 | console.error error.stack if error?
|
96 | process.exit 1
|
97 |
|
98 | new CommandBuild().run()
|