Browse Source

fix(gui-v2): upgradeNocodbSdk -> upgradeNocodbSdk2

pull/3273/head
Wing-Kam Wong 2 years ago
parent
commit
6fecd4b717
  1. 2
      .github/workflows/release-gui-v2.yml
  2. 6
      scripts/upgradeNocodbSdk.js
  3. 76
      scripts/upgradeNocodbSdk2.js

2
.github/workflows/release-gui-v2.yml

@ -30,7 +30,7 @@ jobs:
npm install && npm run build && npm publish &&
cd ../.. &&
sleep 30 &&
targetEnv=${{ github.event.inputs.targetEnv || inputs.targetEnv }} node scripts/upgradeNocodbSdk.js &&
targetEnv=${{ github.event.inputs.targetEnv || inputs.targetEnv }} node scripts/upgradeNocodbSdk2.js &&
cd packages/nc-gui-v2 &&
npm install &&
targetEnv=${{ github.event.inputs.targetEnv || inputs.targetEnv }} targetVersion=${{ github.event.inputs.tag || inputs.tag }} npm run build:copy:publish &&

6
scripts/upgradeNocodbSdk.js

@ -21,8 +21,8 @@ const replacePackageName = (filePath) => {
const bumbVersionAndSave = () => {
// upgrade nocodb-sdk version in nocodb
execSync(`cd packages/nocodb && npm install --save --save-exact ${nocodbSdkPackage.name}@${nocodbSdkPackage.version}`, {});
// upgrade nocodb-sdk version in nc-gui-v2
execSync(`cd packages/nc-gui-v2 && npm install --save --save-exact ${nocodbSdkPackage.name}@${nocodbSdkPackage.version}`, {});
// upgrade nocodb-sdk version in nc-gui
execSync(`cd packages/nc-gui && npm install --save --save-exact ${nocodbSdkPackage.name}@${nocodbSdkPackage.version}`, {});
}
const dfs = function(dir) {
@ -48,7 +48,7 @@ const searchAndReplace = (target) => {
let list = dfs(dirPath)
list = [
...list,
path.join(__dirname, '..', 'packages', 'nc-gui-v2', 'package.json'),
path.join(__dirname, '..', 'packages', 'nc-gui', 'package.json'),
path.join(__dirname, '..', 'packages', 'nocodb', 'package.json')
]
return Promise.all(list.map(d => {

76
scripts/upgradeNocodbSdk2.js

@ -0,0 +1,76 @@
const fs = require('fs')
const path = require('path');
const execSync = require('child_process').execSync;
// extract latest version from package.json
const nocodbSdkPackage = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'packages', 'nocodb-sdk', 'package.json'), 'utf8'))
const replacePackageName = (filePath) => {
return new Promise((resolve, reject) => {
return fs.readFile(filePath, 'utf8', function (err, data) {
if (err) return reject(err)
var result = data.replace(/nocodb-sdk/g, nocodbSdkPackage.name);
return fs.writeFile(filePath, result, 'utf8', function (err) {
if (err) return reject(err)
return resolve()
});
});
})
}
const bumbVersionAndSave = () => {
// upgrade nocodb-sdk version in nocodb
execSync(`cd packages/nocodb && npm install --save --save-exact ${nocodbSdkPackage.name}@${nocodbSdkPackage.version}`, {});
// upgrade nocodb-sdk version in nc-gui-v2
execSync(`cd packages/nc-gui-v2 && npm install --save --save-exact ${nocodbSdkPackage.name}@${nocodbSdkPackage.version}`, {});
}
const dfs = function(dir) {
var res = [];
var list = fs.readdirSync(dir);
list.forEach(function(file) {
file = dir + '/' + file;
var stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
res = res.concat(dfs(file));
} else {
const ext = path.extname(file).toLowerCase()
if (ext == '.vue' || ext == '.ts' || ext == '.js') {
res.push(file);
}
}
})
return res;
}
const searchAndReplace = (target) => {
const dirPath = path.resolve(path.join(__dirname, '..', 'packages'))
let list = dfs(dirPath)
list = [
...list,
path.join(__dirname, '..', 'packages', 'nc-gui-v2', 'package.json'),
path.join(__dirname, '..', 'packages', 'nocodb', 'package.json')
]
return Promise.all(list.map(d => {
return new Promise((resolve, reject) => {
fs.readFile(d, function(err, content) {
if (err) reject(err)
if (content.indexOf(target) > -1) {
resolve(replacePackageName(d))
} else {
resolve()
}
})
})
}))
}
if (process.env.targetEnv === 'DEV') {
// replace nocodb-sdk by nocodb-sdk-daily if it is nightly build / pr build
searchAndReplace('nocodb-sdk')
.then(() => {
bumbVersionAndSave()
})
} else {
bumbVersionAndSave()
}
Loading…
Cancel
Save