Skip to content

Commit ce76096

Browse files
committed
chore(ui): script enhancements
1 parent 0343390 commit ce76096

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

ui/build/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { green, blue } = require('chalk')
88

99
console.log()
1010

11+
require('./script.app-ext.js').syncAppExt()
1112
require('./script.clean.js')
1213

1314
console.log(` 📦 Building ${green('v' + require('../package.json').version)}...${parallel ? blue(' [multi-threaded]') : ''}\n`)

ui/build/script.app-ext.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const
2+
fs = require('fs'),
3+
path = require('path'),
4+
root = path.resolve(__dirname, '../..'),
5+
resolvePath = file => path.resolve(root, file),
6+
{ blue } = require('chalk')
7+
8+
const writeJson = function (file, json) {
9+
return fs.writeFileSync(file, JSON.stringify(json, null, 2) + '\n', 'utf-8')
10+
}
11+
12+
module.exports.syncAppExt = function (both = true) {
13+
// make sure this project has an app-extension project
14+
const appExtDir = resolvePath('app-extension')
15+
if (!fs.existsSync(appExtDir)) {
16+
return
17+
}
18+
19+
// make sure this project has an ui project
20+
const uiDir = resolvePath('ui')
21+
if (!fs.existsSync(uiDir)) {
22+
return
23+
}
24+
25+
// get version and name from ui package.json
26+
const { name, version } = require(resolvePath(resolvePath('ui/package.json')))
27+
28+
// read app-ext package.json
29+
const appExtFile = resolvePath('app-extension/package.json')
30+
let appExtJson = require(appExtFile),
31+
finished = false
32+
33+
// sync version numbers
34+
if (both === true) {
35+
appExtJson.version = version
36+
}
37+
38+
// check dependencies
39+
if (appExtJson.dependencies !== void 0) {
40+
if (appExtJson.dependencies[name] !== void 0) {
41+
appExtJson.dependencies[name] = '^' + version
42+
finished = true
43+
}
44+
}
45+
// check devDependencies, if not finished
46+
if (finished === false && appExtJson.devDependencies !== void 0) {
47+
if (appExtJson.devDependencies[name] !== void 0) {
48+
appExtJson.devDependencies[name] = '^' + version
49+
finished = true
50+
}
51+
}
52+
53+
if (finished === true) {
54+
writeJson(appExtFile, appExtJson)
55+
console.log(` ⭐️ App Extension ${blue(appExtJson.name)} synced.\n`)
56+
return
57+
}
58+
59+
console.error(` App Extension version and dependency NOT synced.\n`)
60+
}

0 commit comments

Comments
 (0)