pear-build 1.1.2 → 1.3.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 +18 -6
- package/index.js +55 -52
- package/package.json +38 -7
package/README.md
CHANGED
|
@@ -26,21 +26,32 @@ pear-build \
|
|
|
26
26
|
--target=./my-build
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
Each `*-app` flag can be passed more than once to place several artifacts under the same architecture. Every artifact must be named after `productName` (or `name`), or after one of the `bin` names when `bin` is an object:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pear-build \
|
|
33
|
+
--package=./my-app/package.json \
|
|
34
|
+
--darwin-arm64-app ./my-app/MyApp-darwin-arm64/MyApp.app \
|
|
35
|
+
--darwin-arm64-app ./my-app/MyApp-darwin-arm64/my-app \
|
|
36
|
+
--target=./my-build
|
|
37
|
+
```
|
|
38
|
+
|
|
29
39
|
## Example
|
|
30
40
|
|
|
31
41
|
```bash
|
|
32
42
|
node bin.js \
|
|
33
43
|
--package ./test/fixtures/hello-pear-electron/package.json \
|
|
34
|
-
--darwin-arm64-app ./test/fixtures/hello-pear-electron/
|
|
35
|
-
--darwin-x64-app ./test/fixtures/hello-pear-electron/
|
|
36
|
-
--linux-arm64-app ./test/fixtures/hello-pear-electron/
|
|
37
|
-
--linux-x64-app ./test/fixtures/hello-pear-electron/
|
|
38
|
-
--win32-x64-app ./test/fixtures/hello-pear-electron/
|
|
39
|
-
--win32-arm64-app ./test/fixtures/hello-pear-electron/
|
|
44
|
+
--darwin-arm64-app ./test/fixtures/hello-pear-electron/by-arch/HelloPear-darwin-arm64/HelloPear.app \
|
|
45
|
+
--darwin-x64-app ./test/fixtures/hello-pear-electron/by-arch/HelloPear-darwin-x64/HelloPear.app \
|
|
46
|
+
--linux-arm64-app ./test/fixtures/hello-pear-electron/by-arch/HelloPear-linux-arm64/HelloPear.AppImage \
|
|
47
|
+
--linux-x64-app ./test/fixtures/hello-pear-electron/by-arch/HelloPear-linux-x64/HelloPear.AppImage \
|
|
48
|
+
--win32-x64-app ./test/fixtures/hello-pear-electron/by-arch/HelloPear-win32-x64/HelloPear.msix \
|
|
49
|
+
--win32-arm64-app ./test/fixtures/hello-pear-electron/by-arch/HelloPear-win32-arm64/HelloPear.msix \
|
|
40
50
|
--ios-arm64 ./test/fixtures/hello-pear-react-native/ota/ios/HelloPear \
|
|
41
51
|
--ios-arm64-simulator ./test/fixtures/hello-pear-react-native/ota/ios/HelloPear \
|
|
42
52
|
--ios-x64-simulator ./test/fixtures/hello-pear-react-native/ota/ios/HelloPear \
|
|
43
53
|
--android-arm64 ./test/fixtures/hello-pear-react-native/ota/android/HelloPear \
|
|
54
|
+
--config ./test/fixtures/hello-pear-react-native/pear.json \
|
|
44
55
|
--target ./my-build
|
|
45
56
|
```
|
|
46
57
|
|
|
@@ -84,6 +95,7 @@ my-build
|
|
|
84
95
|
│ └── app
|
|
85
96
|
│ └── HelloPear.msix
|
|
86
97
|
└── package.json
|
|
98
|
+
└── pear.json
|
|
87
99
|
```
|
|
88
100
|
|
|
89
101
|
## License
|
package/index.js
CHANGED
|
@@ -15,47 +15,33 @@ class Build extends EventEmitter {
|
|
|
15
15
|
async run(opts) {
|
|
16
16
|
if (!opts.package) throw ERR_INVALID_INPUT('package.json path must be specified.')
|
|
17
17
|
const pkgPath = path.resolve(opts.package)
|
|
18
|
+
const pkg = await getParsedJSON('package.json', pkgPath)
|
|
18
19
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (err.code === 'EISDIR') {
|
|
24
|
-
throw ERR_INVALID_INPUT('package.json must be a file', { path: pkgPath, cause: err })
|
|
25
|
-
}
|
|
26
|
-
throw err
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
let pkg
|
|
30
|
-
try {
|
|
31
|
-
pkg = JSON.parse(pkgFile)
|
|
32
|
-
} catch (err) {
|
|
33
|
-
throw ERR_INVALID_INPUT('package.json is not a valid JSON', { path: pkgPath })
|
|
34
|
-
}
|
|
20
|
+
const isMobile = !!pkg.dependencies?.['react-native-bare-kit'] // in mobile react-native-bare-kit needs to be listed in project's deps
|
|
21
|
+
if (!opts.config && isMobile) throw ERR_INVALID_INPUT('pear.json path must be specified.')
|
|
22
|
+
const configPath = opts.config && path.resolve(opts.config)
|
|
23
|
+
const config = configPath && (await getParsedJSON('pear.json', configPath))
|
|
35
24
|
|
|
36
25
|
const { target = path.resolve(pkg.name + '-' + pkg.version) } = opts
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const androidArm64 = opts.androidArm64
|
|
57
|
-
? ['android-arm64', path.resolve(opts.androidArm64)]
|
|
58
|
-
: null
|
|
26
|
+
const archs = {
|
|
27
|
+
'darwin-arm64': opts.darwinArm64App,
|
|
28
|
+
'darwin-x64': opts.darwinX64App,
|
|
29
|
+
'linux-arm64': opts.linuxArm64App,
|
|
30
|
+
'linux-x64': opts.linuxX64App,
|
|
31
|
+
'win32-x64': opts.win32X64App,
|
|
32
|
+
'win32-arm64': opts.win32Arm64App,
|
|
33
|
+
'ios-arm64': opts.iosArm64,
|
|
34
|
+
'ios-arm64-simulator': opts.iosArm64Simulator,
|
|
35
|
+
'ios-x64-simulator': opts.iosX64Simulator,
|
|
36
|
+
'android-arm64': opts.androidArm64
|
|
37
|
+
}
|
|
38
|
+
const apps = []
|
|
39
|
+
for (const [arch, app] of Object.entries(archs)) {
|
|
40
|
+
if (!app) continue
|
|
41
|
+
for (const each of Array.isArray(app) ? app : [app]) {
|
|
42
|
+
if (each) apps.push([arch, path.resolve(each)])
|
|
43
|
+
}
|
|
44
|
+
}
|
|
59
45
|
|
|
60
46
|
const byArch = path.join(target, 'by-arch')
|
|
61
47
|
|
|
@@ -66,27 +52,26 @@ class Build extends EventEmitter {
|
|
|
66
52
|
await fs.promises.readFile(pkgPath)
|
|
67
53
|
)
|
|
68
54
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
win32Arm64App,
|
|
76
|
-
iosArm64,
|
|
77
|
-
iosArm64Sim,
|
|
78
|
-
iosx64Sim,
|
|
79
|
-
androidArm64
|
|
80
|
-
].filter(Boolean)
|
|
55
|
+
if (config) {
|
|
56
|
+
await fs.promises.writeFile(
|
|
57
|
+
path.join(target, 'pear.json'),
|
|
58
|
+
await fs.promises.readFile(configPath)
|
|
59
|
+
)
|
|
60
|
+
}
|
|
81
61
|
|
|
82
62
|
const appName = pkg.productName ?? pkg.name
|
|
63
|
+
const binNames = pkg.bin && typeof pkg.bin === 'object' ? Object.keys(pkg.bin) : []
|
|
64
|
+
const appNames = [...new Set([appName, ...binNames])]
|
|
83
65
|
|
|
84
66
|
const noop = () => {}
|
|
85
67
|
const promises = []
|
|
86
68
|
for (const [arch, app] of apps) {
|
|
87
|
-
if (
|
|
69
|
+
if (!fs.existsSync(app)) {
|
|
70
|
+
throw new Error(`${app} does not exists`)
|
|
71
|
+
}
|
|
72
|
+
if (appNames.includes(path.basename(app, path.extname(app))) === false) {
|
|
88
73
|
throw ERR_INVALID_APP_NAME(
|
|
89
|
-
`expected
|
|
74
|
+
`expected ${appNames.join(' or ')} but got ${path.basename(app)} for ${arch}`,
|
|
90
75
|
{ arch, app }
|
|
91
76
|
)
|
|
92
77
|
}
|
|
@@ -118,6 +103,24 @@ class Build extends EventEmitter {
|
|
|
118
103
|
}
|
|
119
104
|
}
|
|
120
105
|
|
|
106
|
+
async function getParsedJSON(name, path) {
|
|
107
|
+
const file = await fs.promises.readFile(path, 'utf8').catch((err) => {
|
|
108
|
+
if (err.code === 'ENOENT') {
|
|
109
|
+
throw ERR_NOT_FOUND(name + ' not found', { path, cause: err })
|
|
110
|
+
}
|
|
111
|
+
if (err.code === 'EISDIR') {
|
|
112
|
+
throw ERR_INVALID_INPUT(name + ' must be a file', { path, cause: err })
|
|
113
|
+
}
|
|
114
|
+
throw err
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
return JSON.parse(file)
|
|
119
|
+
} catch (err) {
|
|
120
|
+
throw ERR_INVALID_INPUT(name + ' is not a valid JSON', { path, cause: err })
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
121
124
|
module.exports = function build(opts) {
|
|
122
125
|
return new Build(opts)
|
|
123
126
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pear-build",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"bin": {
|
|
@@ -17,12 +17,43 @@
|
|
|
17
17
|
"summary": "Create project deployment folder",
|
|
18
18
|
"flag --package [path]": "Path to project package.json",
|
|
19
19
|
"flag --target [path]": "Target build dir",
|
|
20
|
-
"flag --
|
|
21
|
-
"flag --darwin-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
"flag --config [path]": "Path to project pear.json (mandatory for mobile)",
|
|
21
|
+
"flag --darwin-arm64-app [path]": [
|
|
22
|
+
"Path to Mac ARM64 app",
|
|
23
|
+
{
|
|
24
|
+
"multiple": true
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"flag --darwin-x64-app [path]": [
|
|
28
|
+
"Path to Mac x64 app",
|
|
29
|
+
{
|
|
30
|
+
"multiple": true
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"flag --linux-arm64-app [path]": [
|
|
34
|
+
"Path to Linux ARM64 app",
|
|
35
|
+
{
|
|
36
|
+
"multiple": true
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"flag --linux-x64-app [path]": [
|
|
40
|
+
"Path to Linux x64 app",
|
|
41
|
+
{
|
|
42
|
+
"multiple": true
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"flag --win32-x64-app [path]": [
|
|
46
|
+
"Path to Windows x64 app",
|
|
47
|
+
{
|
|
48
|
+
"multiple": true
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"flag --win32-arm64-app [path]": [
|
|
52
|
+
"Path to Windows ARM64 app",
|
|
53
|
+
{
|
|
54
|
+
"multiple": true
|
|
55
|
+
}
|
|
56
|
+
],
|
|
26
57
|
"flag --ios-arm64 [path]": "Path to iOS ARM64 folder (ota bundle and assets)",
|
|
27
58
|
"flag --ios-arm64-simulator [path]": "Path to iOS ARM64-Simulator folder (ota bundle and asset)",
|
|
28
59
|
"flag --ios-x64-simulator [path]": "Path to iOS x64-Simulator folder (ota bundle and assets)",
|