Skip to content

Commit

Permalink
#168 GitHub checker for folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
s0b0lev committed Feb 11, 2019
1 parent 103e092 commit f7835ee
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ jobs:
command: |
cd scripts/ && npm install && npm run yaml-content-validate
swc-yaml-config-content:
<<: *defaults
steps:
- checkout
- run:
name: Check folder structure
shell: /bin/sh
command: |
cd scripts/ && npm install && npm run validate-dirs
deploy-gh-pages:
<<: *defaults
steps:
Expand Down
35 changes: 35 additions & 0 deletions scripts/dir_structure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const fs = require('fs');
const path = require('path');

const walkSync = (dir, filelist=[]) => {
fs.readdirSync(dir).forEach((file) => {
if(fs.statSync(path.join(dir, file)).isDirectory()) {
filelist = walkSync(path.join(dir, file), filelist)
} else {
filelist = filelist.concat(path.join(dir, file));
}
});
return filelist;
};

let hasError = false;

const files = walkSync('../test_cases');

files.map(file => {
const splitedPath = file.split('/');

const [filepath, folder, ...rest] = splitedPath.reverse();
const [filename, ...restels] = filepath.split('.');

if (folder !== filename) {
hasError = true;
console.log(`Path is wrong: ${file}`);
}
});

if (hasError) {
process.exit(1);
} else {
process.exit(0);
}
3 changes: 2 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"yaml-schema-lint": "node yaml_schema_validate.js",
"yaml-content-validate": "node yaml_validate.js",
"markdown-validate": "node update_swc.js markdown-validate",
"update-swc": "node update_swc.js > ../export/swc-definition.json"
"update-swc": "node update_swc.js > ../export/swc-definition.json",
"validate-dirs": "node dir_structure.js"
},
"author": "",
"license": "ISC"
Expand Down

0 comments on commit f7835ee

Please sign in to comment.