pear-build 0.1.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -1
- package/bin.js +13 -42
- package/index.js +83 -56
- package/package.json +32 -7
package/README.md
CHANGED
|
@@ -11,7 +11,67 @@ npm install -g pear-build
|
|
|
11
11
|
Create a build dir outside the project root.
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
pear-build
|
|
14
|
+
pear-build \
|
|
15
|
+
--package=./my-app/package.json \
|
|
16
|
+
--darwin-arm64-app ./my-app/MyApp-darwin-arm64/MyApp.app \
|
|
17
|
+
--linux-x64-app=./my-app/MyApp-linux-x64/MyApp.AppImage \
|
|
18
|
+
--target=./my-build
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
node bin.js \
|
|
25
|
+
--package ./test/fixtures/hello-pear-electron/package.json \
|
|
26
|
+
--darwin-arm64-app ./test/fixtures/hello-pear-electron/out/HelloPear-darwin-arm64/HelloPear.app \
|
|
27
|
+
--darwin-x64-app ./test/fixtures/hello-pear-electron/out/HelloPear-darwin-x64/HelloPear.app \
|
|
28
|
+
--linux-arm64-app ./test/fixtures/hello-pear-electron/out/HelloPear-linux-arm64/HelloPear.AppImage \
|
|
29
|
+
--linux-x64-app ./test/fixtures/hello-pear-electron/out/HelloPear-linux-x64/HelloPear.AppImage \
|
|
30
|
+
--win32-x64-app ./test/fixtures/hello-pear-electron/out/HelloPear-win32-x64/HelloPear.msix \
|
|
31
|
+
--ios-arm64 ./test/fixtures/hello-pear-react-native/ota/ios/HelloPear \
|
|
32
|
+
--ios-arm64-simulator ./test/fixtures/hello-pear-react-native/ota/ios/HelloPear \
|
|
33
|
+
--ios-x64-simulator ./test/fixtures/hello-pear-react-native/ota/ios/HelloPear \
|
|
34
|
+
--android-arm64 ./test/fixtures/hello-pear-react-native/ota/android/HelloPear \
|
|
35
|
+
--target ./my-build
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`$ tree my-build/`
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
my-build
|
|
42
|
+
├── by-arch
|
|
43
|
+
│ ├── android-arm64
|
|
44
|
+
│ │ └── app
|
|
45
|
+
│ │ └── HelloPear
|
|
46
|
+
│ │ └── app.bundle
|
|
47
|
+
│ ├── darwin-arm64
|
|
48
|
+
│ │ └── app
|
|
49
|
+
│ │ └── HelloPear.app
|
|
50
|
+
│ ├── darwin-x64
|
|
51
|
+
│ │ └── app
|
|
52
|
+
│ │ └── HelloPear.app
|
|
53
|
+
│ ├── ios-arm64
|
|
54
|
+
│ │ └── app
|
|
55
|
+
│ │ └── HelloPear
|
|
56
|
+
│ │ └── app.bundle
|
|
57
|
+
│ ├── ios-arm64-simulator
|
|
58
|
+
│ │ └── app
|
|
59
|
+
│ │ └── HelloPear
|
|
60
|
+
│ │ └── app.bundle
|
|
61
|
+
│ ├── ios-x64-simulator
|
|
62
|
+
│ │ └── app
|
|
63
|
+
│ │ └── HelloPear
|
|
64
|
+
│ │ └── app.bundle
|
|
65
|
+
│ ├── linux-arm64
|
|
66
|
+
│ │ └── app
|
|
67
|
+
│ │ └── HelloPear.AppImage
|
|
68
|
+
│ ├── linux-x64
|
|
69
|
+
│ │ └── app
|
|
70
|
+
│ │ └── HelloPear.AppImage
|
|
71
|
+
│ └── win32-x64
|
|
72
|
+
│ └── app
|
|
73
|
+
│ └── HelloPear.msix
|
|
74
|
+
└── package.json
|
|
15
75
|
```
|
|
16
76
|
|
|
17
77
|
## License
|
package/bin.js
CHANGED
|
@@ -1,48 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const { command,
|
|
2
|
+
const { command, argv } = require('paparam')
|
|
3
3
|
const pkg = require('./package')
|
|
4
4
|
const build = require('.')
|
|
5
5
|
|
|
6
|
-
const cmd = command(
|
|
7
|
-
pkg.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
flag('--win32-x64-app [path]', 'Path to Windows x64 app'),
|
|
17
|
-
flag('--ios-arm64 [path]', 'Path to iOS ARM64 folder (ota bundle and assets)'),
|
|
18
|
-
flag(
|
|
19
|
-
'--ios-arm64-simulator [path]',
|
|
20
|
-
'Path to iOS ARM64-Simulator folder (ota bundle and assets)'
|
|
21
|
-
),
|
|
22
|
-
flag('--ios-x64-simulator [path]', 'Path to iOS x64-Simulator folder (ota bundle and assets)'),
|
|
23
|
-
flag('--android-arm64 [path]', 'Path to android ARM64 folder (ota bundle and assets)'),
|
|
24
|
-
async function (cmd) {
|
|
25
|
-
if (cmd.flags.version) return console.log(`v${pkg.version}`)
|
|
26
|
-
const dir = cmd.flags.package
|
|
27
|
-
const opts = {
|
|
28
|
-
target: cmd.flags.target,
|
|
29
|
-
darwinArm64App: cmd.flags.darwinArm64App,
|
|
30
|
-
darwinX64App: cmd.flags.darwinX64App,
|
|
31
|
-
linuxArm64App: cmd.flags.linuxArm64App,
|
|
32
|
-
linuxX64App: cmd.flags.linuxX64App,
|
|
33
|
-
win32X64App: cmd.flags.win32X64App,
|
|
34
|
-
iosArm64: cmd.flags.iosArm64,
|
|
35
|
-
iosArm64Simulator: cmd.flags.iosArm64Simulator,
|
|
36
|
-
iosX64Simulator: cmd.flags.iosX64Simulator,
|
|
37
|
-
androidArm64: cmd.flags.androidArm64
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
await build(dir, opts)
|
|
41
|
-
} catch (err) {
|
|
42
|
-
if (err) console.error(err)
|
|
43
|
-
if (typeof process !== 'undefined') process.exitCode = 1
|
|
44
|
-
}
|
|
6
|
+
const cmd = command(pkg.name, pkg.command, async function (cmd) {
|
|
7
|
+
if (cmd.flags.version) return console.log(`v${pkg.version}`)
|
|
8
|
+
try {
|
|
9
|
+
const runner = build(cmd.flags)
|
|
10
|
+
runner.on('mirrored', (data) => console.log(data.from, data.message, data.to))
|
|
11
|
+
runner.on('error', (err) => console.error(err))
|
|
12
|
+
await runner.done()
|
|
13
|
+
} catch (err) {
|
|
14
|
+
if (typeof Bare !== 'undefined') Bare.exitCode = 1
|
|
15
|
+
else if (typeof process !== 'undefined') process.exitCode = 1
|
|
45
16
|
}
|
|
46
|
-
)
|
|
17
|
+
})
|
|
47
18
|
|
|
48
|
-
cmd.parse()
|
|
19
|
+
cmd.parse(argv().length === 0 ? ['--help'] : argv())
|
package/index.js
CHANGED
|
@@ -1,70 +1,97 @@
|
|
|
1
|
+
'use strict'
|
|
1
2
|
const path = require('path')
|
|
2
3
|
const fs = require('fs')
|
|
4
|
+
const { EventEmitter } = require('events')
|
|
3
5
|
const Localdrive = require('localdrive')
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
? ['
|
|
24
|
-
: null
|
|
25
|
-
|
|
7
|
+
class Build extends EventEmitter {
|
|
8
|
+
constructor(opts) {
|
|
9
|
+
super()
|
|
10
|
+
this._running = this.run(opts)
|
|
11
|
+
this._running.catch((err) => this.emit('error', err))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async run(opts) {
|
|
15
|
+
const pkgPath = path.resolve(opts.package)
|
|
16
|
+
const pkg = require(pkgPath)
|
|
17
|
+
const { target = path.resolve(pkg.name + '-' + pkg.version) } = opts
|
|
18
|
+
const darwinArm64App = opts.darwinArm64App
|
|
19
|
+
? ['darwin-arm64', path.resolve(opts.darwinArm64App)]
|
|
20
|
+
: null
|
|
21
|
+
const darwinX64App = opts.darwinX64App ? ['darwin-x64', path.resolve(opts.darwinX64App)] : null
|
|
22
|
+
const linuxArm64App = opts.linuxArm64App
|
|
23
|
+
? ['linux-arm64', path.resolve(opts.linuxArm64App)]
|
|
24
|
+
: null
|
|
25
|
+
const linuxX64App = opts.linuxX64App ? ['linux-x64', path.resolve(opts.linuxX64App)] : null
|
|
26
|
+
const win32X64App = opts.win32X64App ? ['win32-x64', path.resolve(opts.win32X64App)] : null
|
|
27
|
+
const iosArm64 = opts.iosArm64 ? ['ios-arm64', path.resolve(opts.iosArm64)] : null
|
|
28
|
+
const iosArm64Sim = opts.iosArm64Simulator
|
|
29
|
+
? ['ios-arm64-simulator', path.resolve(opts.iosArm64Simulator)]
|
|
30
|
+
: null
|
|
31
|
+
const iosx64Sim = opts.iosX64Simulator
|
|
32
|
+
? ['ios-x64-simulator', path.resolve(opts.iosX64Simulator)]
|
|
33
|
+
: null
|
|
34
|
+
const androidArm64 = opts.androidArm64
|
|
35
|
+
? ['android-arm64', path.resolve(opts.androidArm64)]
|
|
36
|
+
: null
|
|
37
|
+
|
|
38
|
+
const byArch = path.join(target, 'by-arch')
|
|
39
|
+
|
|
40
|
+
await fs.promises.mkdir(byArch, { recursive: true })
|
|
26
41
|
|
|
27
|
-
|
|
42
|
+
await fs.promises.writeFile(
|
|
43
|
+
path.join(target, 'package.json'),
|
|
44
|
+
await fs.promises.readFile(pkgPath)
|
|
45
|
+
)
|
|
28
46
|
|
|
29
|
-
|
|
47
|
+
const apps = [
|
|
48
|
+
darwinArm64App,
|
|
49
|
+
darwinX64App,
|
|
50
|
+
linuxArm64App,
|
|
51
|
+
linuxX64App,
|
|
52
|
+
win32X64App,
|
|
53
|
+
iosArm64,
|
|
54
|
+
iosArm64Sim,
|
|
55
|
+
iosx64Sim,
|
|
56
|
+
androidArm64
|
|
57
|
+
].filter(Boolean)
|
|
30
58
|
|
|
31
|
-
|
|
32
|
-
path.join(target, 'package.json'),
|
|
33
|
-
await fs.promises.readFile(pkgPath)
|
|
34
|
-
)
|
|
59
|
+
const appName = pkg.productName ?? pkg.name
|
|
35
60
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
iosx64Sim,
|
|
45
|
-
androidArm64
|
|
46
|
-
].filter(Boolean)
|
|
61
|
+
const noop = () => {}
|
|
62
|
+
const promises = []
|
|
63
|
+
for (const [arch, app] of apps) {
|
|
64
|
+
if (path.basename(app, path.extname(app)) !== appName) {
|
|
65
|
+
throw new Error(`expected directory ${appName} but got ${path.basename(app)} for ${arch}`)
|
|
66
|
+
}
|
|
67
|
+
const archApp = path.join(byArch, arch, 'app')
|
|
68
|
+
await fs.promises.mkdir(archApp, { recursive: true })
|
|
47
69
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const appName = path.basename(app)
|
|
52
|
-
const archApp = path.join(byArch, arch, 'app')
|
|
53
|
-
await fs.promises.mkdir(archApp, { recursive: true })
|
|
70
|
+
const src = new Localdrive(path.dirname(app))
|
|
71
|
+
const dst = new Localdrive(archApp)
|
|
72
|
+
const mirror = src.mirror(dst, { prefix: '/' + path.basename(app) })
|
|
54
73
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
74
|
+
await src.ready()
|
|
75
|
+
await dst.ready()
|
|
76
|
+
this.emit('mirroring', { message: 'mirroring to', from: app, to: archApp })
|
|
77
|
+
const promise = mirror.done()
|
|
78
|
+
promises.push(promise)
|
|
79
|
+
promise.then(
|
|
80
|
+
() => this.emit('mirrored', { message: 'mirrored to', from: app, to: archApp }),
|
|
81
|
+
noop
|
|
82
|
+
)
|
|
83
|
+
await src.close()
|
|
84
|
+
await dst.close()
|
|
85
|
+
}
|
|
58
86
|
|
|
59
|
-
await
|
|
60
|
-
await dst.ready()
|
|
61
|
-
console.log(app, 'mirroring to', archApp)
|
|
62
|
-
const promise = mirror.done()
|
|
63
|
-
promises.push(promise)
|
|
64
|
-
promise.then(() => console.log(app, 'mirrored to', archApp), noop)
|
|
65
|
-
await src.close()
|
|
66
|
-
await dst.close()
|
|
87
|
+
await Promise.all(promises)
|
|
67
88
|
}
|
|
68
89
|
|
|
69
|
-
|
|
90
|
+
async done() {
|
|
91
|
+
return await this._running
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = function build(opts) {
|
|
96
|
+
return new Build(opts)
|
|
70
97
|
}
|
package/package.json
CHANGED
|
@@ -1,41 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pear-build",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"bin": "bin.js",
|
|
7
|
-
"description": "
|
|
7
|
+
"description": "Create project deployment folder",
|
|
8
8
|
"author": "Holepunch Inc",
|
|
9
9
|
"license": "Apache-2.0",
|
|
10
10
|
"files": [
|
|
11
11
|
"index.js",
|
|
12
12
|
"bin.js"
|
|
13
13
|
],
|
|
14
|
+
"command": {
|
|
15
|
+
"summary": "Create project deployment folder",
|
|
16
|
+
"flag --package [path]": "Path to project package.json",
|
|
17
|
+
"flag --target [path]": "Target build dir",
|
|
18
|
+
"flag --darwin-arm64-app [path]": "Path to Mac ARM64 app",
|
|
19
|
+
"flag --darwin-x64-app [path]": "Path to Mac x64 app",
|
|
20
|
+
"flag --linux-arm64-app [path]": "Path to Linux ARM64 app",
|
|
21
|
+
"flag --linux-x64-app [path]": "Path to Linux x64 app",
|
|
22
|
+
"flag --win32-x64-app [path]": "Path to Windows x64 app",
|
|
23
|
+
"flag --ios-arm64 [path]": "Path to iOS ARM64 folder (ota bundle and assets)",
|
|
24
|
+
"flag --ios-arm64-simulator [path]": "Path to iOS ARM64-Simulator folder (ota bundle and asset)",
|
|
25
|
+
"flag --ios-x64-simulator [path]": "Path to iOS x64-Simulator folder (ota bundle and assets)",
|
|
26
|
+
"flag --android-arm64 [path]": "Path to Android ARM64 folder (ota bundle and assets)",
|
|
27
|
+
"flag --json": "Newline delimited JSON output"
|
|
28
|
+
},
|
|
14
29
|
"imports": {
|
|
15
|
-
"
|
|
16
|
-
"bare": "bare-
|
|
17
|
-
"default": "
|
|
30
|
+
"events": {
|
|
31
|
+
"bare": "bare-events",
|
|
32
|
+
"default": "events"
|
|
18
33
|
},
|
|
19
34
|
"fs": {
|
|
20
35
|
"bare": "bare-fs",
|
|
21
36
|
"default": "fs"
|
|
37
|
+
},
|
|
38
|
+
"path": {
|
|
39
|
+
"bare": "bare-path",
|
|
40
|
+
"default": "path"
|
|
22
41
|
}
|
|
23
42
|
},
|
|
24
43
|
"scripts": {
|
|
25
44
|
"format": "prettier --write .",
|
|
26
45
|
"lint": "prettier --check . && lunte",
|
|
27
|
-
"test": "
|
|
46
|
+
"test": "npm run test:node && npm run test:bare",
|
|
47
|
+
"test:bare": "brittle-bare --coverage test/all.js",
|
|
48
|
+
"test:node": "brittle-node --coverage test/all.js"
|
|
28
49
|
},
|
|
29
50
|
"dependencies": {
|
|
51
|
+
"bare-events": "^2.8.2",
|
|
30
52
|
"bare-fs": "^4.5.3",
|
|
31
53
|
"bare-path": "^3.0.0",
|
|
32
54
|
"localdrive": "^2.2.0",
|
|
33
55
|
"paparam": "^1.10.0"
|
|
34
56
|
},
|
|
35
57
|
"devDependencies": {
|
|
58
|
+
"bare-fs": "^4.5.3",
|
|
36
59
|
"brittle": "^3.19.1",
|
|
37
60
|
"lunte": "^1.6.0",
|
|
61
|
+
"mirror-drive": "^1.13.0",
|
|
38
62
|
"prettier": "^3.7.4",
|
|
39
|
-
"prettier-config-holepunch": "^2.0.0"
|
|
63
|
+
"prettier-config-holepunch": "^2.0.0",
|
|
64
|
+
"test-tmp": "^1.4.0"
|
|
40
65
|
}
|
|
41
66
|
}
|