Skip to content

Commit

Permalink
Merge pull request #79 from vusion/fix-github_action-commit-hanshijie…
Browse files Browse the repository at this point in the history
…-240320

fix: 更新library地址寻找的方式。
  • Loading branch information
ncqwer authored Mar 20, 2024
2 parents 75d8660 + 84a4a8b commit 205d657
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scripts/utils/getBranchInfo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { execCommand } = require('./execCommand');

const branchReg =
/^task(?:\(([a-zA-Z\-\_\d]+)\))?\-([a-zA-Z\_\d]+)\-([a-zA-Z\_\d]+)\-/i;
/^task(?:\(([a-zA-Z\-\_\d]+)\))?\-([a-zA-Z\_\d]+)\-([a-zA-Z\_\d]+)\-?/i;

module.exports.getBranchInfo = async () => {
const branchName = await execCommand('git branch --show-current');
Expand Down
37 changes: 32 additions & 5 deletions scripts/utils/isPackageExist.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,51 @@
const fsp = require('fs').promises;
const fs = require('fs');
const fsp = fs.promises;
const path = require('path');

const LIBRARY_INFO = {
...getAllSubdirectories('./packages/cw'),
...getAllSubdirectories('./packages/lcap'),
};

const isPackageExist = async (libraryName) => {
if (LIBRARY_INFO[libraryName]) return LIBRARY_INFO[libraryName];

console.warn('leagacy mode, should not be here');
const [prefix] = libraryName.split(/[\-\_]/);

let targetPackagesDir = path.join('.', 'packages', prefix.length === libraryName.length ? '' : prefix, libraryName);
let targetPackagesDir = path.join(
'.',
'packages',
prefix.length === libraryName.length ? '' : prefix,
libraryName
);
try {
await fsp.access(targetPackagesDir, fsp.constants.R_OK | fsp.constants.W_OK);
await fsp.access(
targetPackagesDir,
fsp.constants.R_OK | fsp.constants.W_OK
);
return targetPackagesDir;
} catch {
try {
targetPackagesDir = path.join('.', libraryName);
await fsp.access(targetPackagesDir, fsp.constants.R_OK | fsp.constants.W_OK);
await fsp.access(
targetPackagesDir,
fsp.constants.R_OK | fsp.constants.W_OK
);
return targetPackagesDir;
} catch {
return null;
}
}
};

function getAllSubdirectories(directoryPath) {
const files = fs.readdirSync(directoryPath);
return Object.fromEntries(
files.map((file) => [file, path.resolve(directoryPath, file)])
);
}

module.exports.isPackageExist = isPackageExist;

// isPackageExist('noexist_library').then((v) => console.log(v));
// console.log('🚀 ~ file: isPackageExist.js:6 ~ LIBRARY_INFO:', LIBRARY_INFO);

0 comments on commit 205d657

Please sign in to comment.