Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 更新library地址寻找的方式。 #79

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Loading