From 6fecd4b717dfd573473530f3627fb411f8004532 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 22 Aug 2022 11:47:17 +0800 Subject: [PATCH] fix(gui-v2): upgradeNocodbSdk -> upgradeNocodbSdk2 --- .github/workflows/release-gui-v2.yml | 2 +- scripts/upgradeNocodbSdk.js | 6 +-- scripts/upgradeNocodbSdk2.js | 76 ++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 scripts/upgradeNocodbSdk2.js diff --git a/.github/workflows/release-gui-v2.yml b/.github/workflows/release-gui-v2.yml index 70895a9680..c151f07aa0 100644 --- a/.github/workflows/release-gui-v2.yml +++ b/.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 && diff --git a/scripts/upgradeNocodbSdk.js b/scripts/upgradeNocodbSdk.js index 4d9d8aca58..0e839def48 100644 --- a/scripts/upgradeNocodbSdk.js +++ b/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 => { diff --git a/scripts/upgradeNocodbSdk2.js b/scripts/upgradeNocodbSdk2.js new file mode 100644 index 0000000000..4d9d8aca58 --- /dev/null +++ b/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() +}