pear-build 0.0.2 → 0.1.1
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 +1 -1
- package/bin.js +48 -0
- package/index.js +75 -61
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ npm install -g pear-build
|
|
|
10
10
|
|
|
11
11
|
Create a build dir outside the project root.
|
|
12
12
|
|
|
13
|
-
```
|
|
13
|
+
```bash
|
|
14
14
|
pear-build --package=./my-app/package.json --darwin-arm64-app ./my-app/dist/macos/Keet.app --linux-x64-app=./my-linux-build/Keet.AppImage --target=./my-build
|
|
15
15
|
```
|
|
16
16
|
|
package/bin.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { command, flag, summary } = require('paparam')
|
|
3
|
+
const pkg = require('./package')
|
|
4
|
+
const build = require('.')
|
|
5
|
+
|
|
6
|
+
const cmd = command(
|
|
7
|
+
pkg.name,
|
|
8
|
+
summary(pkg.description),
|
|
9
|
+
flag('--version|-v', 'Print the current version'),
|
|
10
|
+
flag('--package [path]', 'Path to project package.json'),
|
|
11
|
+
flag('--target [path]', 'Target build dir'),
|
|
12
|
+
flag('--darwin-arm64-app [path]', 'Path to Mac ARM64 app'),
|
|
13
|
+
flag('--darwin-x64-app [path]', 'Path to Mac x64 app'),
|
|
14
|
+
flag('--linux-arm64-app [path]', 'Path to Linux ARM64 app'),
|
|
15
|
+
flag('--linux-x64-app [path]', 'Path to Linux x64 app'),
|
|
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
|
+
}
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
cmd.parse()
|
package/index.js
CHANGED
|
@@ -1,72 +1,86 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
const path = require('path')
|
|
3
2
|
const fs = require('fs')
|
|
4
3
|
const Localdrive = require('localdrive')
|
|
5
|
-
const { command, flag, bail } = require('paparam')
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
: null
|
|
29
|
-
const linuxX64App = cmd.flags.linuxX64App
|
|
30
|
-
? ['linux-x64', path.resolve(cmd.flags.linuxX64App)]
|
|
31
|
-
: null
|
|
32
|
-
const win32X64App = cmd.flags.win32X64App
|
|
33
|
-
? ['window-x64', path.resolve(cmd.flags.win32X64App)]
|
|
34
|
-
: null
|
|
5
|
+
module.exports = async function build(dir, opts = {}) {
|
|
6
|
+
const pkgPath = path.resolve(dir)
|
|
7
|
+
const pkg = require(pkgPath)
|
|
8
|
+
const { target = path.resolve(pkg.name + '-' + pkg.version) } = opts
|
|
9
|
+
const darwinArm64App = opts.darwinArm64App
|
|
10
|
+
? ['darwin-arm64', path.resolve(opts.darwinArm64App)]
|
|
11
|
+
: null
|
|
12
|
+
const darwinX64App = opts.darwinX64App ? ['darwin-x64', path.resolve(opts.darwinX64App)] : null
|
|
13
|
+
const linuxArm64App = opts.linuxArm64App
|
|
14
|
+
? ['linux-arm64', path.resolve(opts.linuxArm64App)]
|
|
15
|
+
: null
|
|
16
|
+
const linuxX64App = opts.linuxX64App ? ['linux-x64', path.resolve(opts.linuxX64App)] : null
|
|
17
|
+
const win32X64App = opts.win32X64App ? ['win32-x64', path.resolve(opts.win32X64App)] : null
|
|
18
|
+
const iosArm64 = opts.iosArm64 ? ['ios-arm64', path.resolve(opts.iosArm64)] : null
|
|
19
|
+
const iosArm64Sim = opts.iosArm64Simulator
|
|
20
|
+
? ['ios-arm64-simulator', path.resolve(opts.iosArm64Simulator)]
|
|
21
|
+
: null
|
|
22
|
+
const iosx64Sim = opts.iosX64Simulator
|
|
23
|
+
? ['ios-x64-simulator', path.resolve(opts.iosX64Simulator)]
|
|
24
|
+
: null
|
|
25
|
+
const androidArm64 = opts.androidArm64 ? ['android-arm64', path.resolve(opts.androidArm64)] : null
|
|
35
26
|
|
|
36
|
-
|
|
27
|
+
const byArch = path.join(target, 'by-arch')
|
|
37
28
|
|
|
38
|
-
|
|
29
|
+
await fs.promises.mkdir(byArch, { recursive: true })
|
|
39
30
|
|
|
40
|
-
|
|
31
|
+
await fs.promises.writeFile(
|
|
32
|
+
path.join(target, 'package.json'),
|
|
33
|
+
await fs.promises.readFile(pkgPath)
|
|
34
|
+
)
|
|
41
35
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
36
|
+
const apps = [
|
|
37
|
+
darwinArm64App,
|
|
38
|
+
darwinX64App,
|
|
39
|
+
linuxArm64App,
|
|
40
|
+
linuxX64App,
|
|
41
|
+
win32X64App,
|
|
42
|
+
iosArm64,
|
|
43
|
+
iosArm64Sim,
|
|
44
|
+
iosx64Sim,
|
|
45
|
+
androidArm64
|
|
46
|
+
].filter(Boolean)
|
|
47
|
+
|
|
48
|
+
const noop = () => {}
|
|
49
|
+
const promises = []
|
|
50
|
+
for (const [arch, app] of apps) {
|
|
51
|
+
const isMobile = arch.startsWith('ios') || arch.startsWith('android')
|
|
52
|
+
const appName = isMobile ? (pkg.productName ?? pkg.name) : path.basename(app)
|
|
53
|
+
if (typeof appName !== 'string') {
|
|
54
|
+
throw new Error('package.json productName or name is a required field string')
|
|
55
|
+
}
|
|
56
|
+
const archApp = path.join(byArch, arch, 'app')
|
|
57
|
+
await fs.promises.mkdir(archApp, { recursive: true })
|
|
58
|
+
|
|
59
|
+
const stat = await fs.promises.stat(app)
|
|
60
|
+
let src, dst, mirror
|
|
61
|
+
if (stat.isDirectory()) {
|
|
62
|
+
const appDir = path.join(archApp, appName)
|
|
63
|
+
await fs.promises.mkdir(appDir, { recursive: true })
|
|
64
|
+
src = new Localdrive(app)
|
|
65
|
+
dst = new Localdrive(appDir)
|
|
66
|
+
mirror = src.mirror(dst)
|
|
67
|
+
} else {
|
|
68
|
+
src = new Localdrive(path.dirname(app))
|
|
69
|
+
dst = new Localdrive(archApp)
|
|
70
|
+
mirror = src.mirror(dst, { prefix: '/' + path.basename(app) })
|
|
63
71
|
}
|
|
64
72
|
|
|
65
|
-
await
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
)
|
|
73
|
+
await src.ready()
|
|
74
|
+
await dst.ready()
|
|
75
|
+
console.log(app, 'mirroring to', archApp)
|
|
76
|
+
const promise = mirror.done()
|
|
77
|
+
promises.push(promise)
|
|
78
|
+
promise.then(() => {
|
|
79
|
+
console.log(app, 'mirrored to', archApp)
|
|
80
|
+
}, noop)
|
|
81
|
+
await src.close()
|
|
82
|
+
await dst.close()
|
|
83
|
+
}
|
|
71
84
|
|
|
72
|
-
|
|
85
|
+
await Promise.all(promises)
|
|
86
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pear-build",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
|
-
"bin": "
|
|
6
|
+
"bin": "bin.js",
|
|
7
7
|
"description": "Build appling for a Pear application",
|
|
8
8
|
"author": "Holepunch Inc",
|
|
9
9
|
"license": "Apache-2.0",
|
|
10
|
-
"files": [
|
|
10
|
+
"files": [
|
|
11
|
+
"index.js",
|
|
12
|
+
"bin.js"
|
|
13
|
+
],
|
|
11
14
|
"imports": {
|
|
12
15
|
"path": {
|
|
13
16
|
"bare": "bare-path",
|
|
@@ -20,21 +23,18 @@
|
|
|
20
23
|
},
|
|
21
24
|
"scripts": {
|
|
22
25
|
"format": "prettier --write .",
|
|
23
|
-
"lint": "prettier --check ."
|
|
26
|
+
"lint": "prettier --check . && lunte",
|
|
27
|
+
"test": "brittle-node test/all.js"
|
|
24
28
|
},
|
|
25
29
|
"dependencies": {
|
|
26
|
-
"bare-build": "^0.4.1",
|
|
27
30
|
"bare-fs": "^4.5.3",
|
|
28
31
|
"bare-path": "^3.0.0",
|
|
29
|
-
"hypercore-id-encoding": "^1.3.0",
|
|
30
32
|
"localdrive": "^2.2.0",
|
|
31
|
-
"
|
|
32
|
-
"pear-opstream": "^1.0.1",
|
|
33
|
-
"pear-opwait": "^1.0.0",
|
|
34
|
-
"pear-terminal": "^1.1.3",
|
|
35
|
-
"which-runtime": "^1.3.2"
|
|
33
|
+
"paparam": "^1.10.0"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
36
|
+
"brittle": "^3.19.1",
|
|
37
|
+
"lunte": "^1.6.0",
|
|
38
38
|
"prettier": "^3.7.4",
|
|
39
39
|
"prettier-config-holepunch": "^2.0.0"
|
|
40
40
|
}
|