Skip to content

Commit

Permalink
Fixing read file
Browse files Browse the repository at this point in the history
  • Loading branch information
sebryu committed Sep 25, 2023
1 parent 99e431e commit f3f5910
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions .github/actions/javascript/authorChecklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ const items = [
];

function detectReactComponent(code) {
if (!code) {
return;
}
const ast = parse(code, {
sourceType: 'module',
plugins: ['jsx'] // enable jsx plugin
Expand All @@ -244,14 +247,19 @@ function detectReactComponent(code) {
return isReactComponent;
};

function relativePath(filename) {
return filename.replace(`${CONST.APP_NAME}/`, '');
function readFile(filename) {
const path = `./${filename}`;
try {
return fs.readFileSync(path, 'utf-8');
} catch (error) {
console.error(`Error reading ${path}`, error);
}
}

function detectFunction(changedFiles) {
console.log('detectFunction', process.cwd());
const filteredFiles = _.filter((changedFiles), ({ filename }) => filename.endsWith('.js') || filename.endsWith('.jsx') || filename.endsWith('.ts') || filename.endsWith('.tsx'));
return _.some(filteredFiles, ({ filename }) => detectReactComponent(fs.readFileSync(relativePath(filename), 'utf-8')));
return _.some(filteredFiles, ({ filename }) => detectReactComponent(readFile(filename)));
}

module.exports = {
Expand Down
14 changes: 11 additions & 3 deletions .github/actions/javascript/authorChecklist/newComponentCategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const items = [
];

function detectReactComponent(code) {
if (!code) {
return;
}
const ast = parse(code, {
sourceType: 'module',
plugins: ['jsx'] // enable jsx plugin
Expand All @@ -44,14 +47,19 @@ function detectReactComponent(code) {
return isReactComponent;
};

function relativePath(filename) {
return filename.replace(`${CONST.APP_NAME}/`, '');
function readFile(filename) {
const path = `./${filename}`;
try {
return fs.readFileSync(path, 'utf-8');
} catch (error) {
console.error(`Error reading ${path}`, error);
}
}

function detectFunction(changedFiles) {
console.log('detectFunction', process.cwd());
const filteredFiles = _.filter((changedFiles), ({ filename }) => filename.endsWith('.js') || filename.endsWith('.jsx') || filename.endsWith('.ts') || filename.endsWith('.tsx'));
return _.some(filteredFiles, ({ filename }) => detectReactComponent(fs.readFileSync(relativePath(filename), 'utf-8')));
return _.some(filteredFiles, ({ filename }) => detectReactComponent(readFile(filename)));
}

module.exports = {
Expand Down

0 comments on commit f3f5910

Please sign in to comment.