pear-build 1.1.2 → 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 +33 -16
  3. package/package.json +2 -1
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
@@ -15,23 +15,12 @@ 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 pkgFile = await fs.promises.readFile(pkgPath, 'utf8').catch((err) => {
20
- if (err.code === 'ENOENT') {
21
- throw ERR_NOT_FOUND('package.json not found', { path: pkgPath, cause: err })
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
26
  const darwinArm64App = opts.darwinArm64App
@@ -66,6 +55,13 @@ class Build extends EventEmitter {
66
55
  await fs.promises.readFile(pkgPath)
67
56
  )
68
57
 
58
+ if (config) {
59
+ await fs.promises.writeFile(
60
+ path.join(target, 'pear.json'),
61
+ await fs.promises.readFile(configPath)
62
+ )
63
+ }
64
+
69
65
  const apps = [
70
66
  darwinArm64App,
71
67
  darwinX64App,
@@ -84,6 +80,9 @@ class Build extends EventEmitter {
84
80
  const noop = () => {}
85
81
  const promises = []
86
82
  for (const [arch, app] of apps) {
83
+ if (!fs.existsSync(app)) {
84
+ throw new Error(`${app} does not exists`)
85
+ }
87
86
  if (path.basename(app, path.extname(app)) !== appName) {
88
87
  throw ERR_INVALID_APP_NAME(
89
88
  `expected directory ${appName} but got ${path.basename(app)} for ${arch}`,
@@ -118,6 +117,24 @@ class Build extends EventEmitter {
118
117
  }
119
118
  }
120
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
+
121
138
  module.exports = function build(opts) {
122
139
  return new Build(opts)
123
140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pear-build",
3
- "version": "1.1.2",
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",