pear-build 1.1.1 → 1.2.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.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/index.js +41 -3
  3. package/package.json +4 -2
package/README.md CHANGED
@@ -41,6 +41,7 @@ node bin.js \
41
41
  --ios-arm64-simulator ./test/fixtures/hello-pear-react-native/ota/ios/HelloPear \
42
42
  --ios-x64-simulator ./test/fixtures/hello-pear-react-native/ota/ios/HelloPear \
43
43
  --android-arm64 ./test/fixtures/hello-pear-react-native/ota/android/HelloPear \
44
+ --config ./test/fixtures/hello-pear-react-native/pear.json \
44
45
  --target ./my-build
45
46
  ```
46
47
 
@@ -84,6 +85,7 @@ my-build
84
85
  │   └── app
85
86
  │   └── HelloPear.msix
86
87
  └── package.json
88
+ └── pear.json
87
89
  ```
88
90
 
89
91
  ## License
package/index.js CHANGED
@@ -3,6 +3,7 @@ const path = require('path')
3
3
  const fs = require('fs')
4
4
  const { EventEmitter } = require('events')
5
5
  const Localdrive = require('localdrive')
6
+ const { ERR_NOT_FOUND, ERR_INVALID_INPUT, ERR_INVALID_APP_NAME } = require('pear-errors')
6
7
 
7
8
  class Build extends EventEmitter {
8
9
  constructor(opts) {
@@ -12,9 +13,15 @@ class Build extends EventEmitter {
12
13
  }
13
14
 
14
15
  async run(opts) {
16
+ if (!opts.package) throw ERR_INVALID_INPUT('package.json path must be specified.')
15
17
  const pkgPath = path.resolve(opts.package)
16
- const pkgFile = await fs.promises.readFile(pkgPath, 'utf-8')
17
- const pkg = JSON.parse(pkgFile)
18
+ const pkg = await getParsedJSON('package.json', pkgPath)
19
+
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))
24
+
18
25
  const { target = path.resolve(pkg.name + '-' + pkg.version) } = opts
19
26
  const darwinArm64App = opts.darwinArm64App
20
27
  ? ['darwin-arm64', path.resolve(opts.darwinArm64App)]
@@ -48,6 +55,13 @@ class Build extends EventEmitter {
48
55
  await fs.promises.readFile(pkgPath)
49
56
  )
50
57
 
58
+ if (config) {
59
+ await fs.promises.writeFile(
60
+ path.join(target, 'pear.json'),
61
+ await fs.promises.readFile(configPath)
62
+ )
63
+ }
64
+
51
65
  const apps = [
52
66
  darwinArm64App,
53
67
  darwinX64App,
@@ -66,8 +80,14 @@ class Build extends EventEmitter {
66
80
  const noop = () => {}
67
81
  const promises = []
68
82
  for (const [arch, app] of apps) {
83
+ if (!fs.existsSync(app)) {
84
+ throw new Error(`${app} does not exists`)
85
+ }
69
86
  if (path.basename(app, path.extname(app)) !== appName) {
70
- throw new Error(`expected directory ${appName} but got ${path.basename(app)} for ${arch}`)
87
+ throw ERR_INVALID_APP_NAME(
88
+ `expected directory ${appName} but got ${path.basename(app)} for ${arch}`,
89
+ { arch, app }
90
+ )
71
91
  }
72
92
  const archApp = path.join(byArch, arch, 'app')
73
93
  await fs.promises.mkdir(archApp, { recursive: true })
@@ -97,6 +117,24 @@ class Build extends EventEmitter {
97
117
  }
98
118
  }
99
119
 
120
+ async function getParsedJSON(name, path) {
121
+ const file = await fs.promises.readFile(path, 'utf8').catch((err) => {
122
+ if (err.code === 'ENOENT') {
123
+ throw ERR_NOT_FOUND(name + ' not found', { path, cause: err })
124
+ }
125
+ if (err.code === 'EISDIR') {
126
+ throw ERR_INVALID_INPUT(name + ' must be a file', { path, cause: err })
127
+ }
128
+ throw err
129
+ })
130
+
131
+ try {
132
+ return JSON.parse(file)
133
+ } catch (err) {
134
+ throw ERR_INVALID_INPUT(name + ' is not a valid JSON', { path, cause: err })
135
+ }
136
+ }
137
+
100
138
  module.exports = function build(opts) {
101
139
  return new Build(opts)
102
140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pear-build",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "main": "index.js",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -17,6 +17,7 @@
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 --config [path]": "Path to project pear.json (mandatory for mobile)",
20
21
  "flag --darwin-arm64-app [path]": "Path to Mac ARM64 app",
21
22
  "flag --darwin-x64-app [path]": "Path to Mac x64 app",
22
23
  "flag --linux-arm64-app [path]": "Path to Linux ARM64 app",
@@ -56,7 +57,8 @@
56
57
  "bare-fs": "^4.5.3",
57
58
  "bare-path": "^3.0.0",
58
59
  "localdrive": "^2.2.0",
59
- "paparam": "^1.10.0"
60
+ "paparam": "^1.10.0",
61
+ "pear-errors": "^1.0.1"
60
62
  },
61
63
  "devDependencies": {
62
64
  "brittle": "^4.0.0",