Skip to content

Commit

Permalink
add skip list
Browse files Browse the repository at this point in the history
  • Loading branch information
Caio-Bessa committed Nov 16, 2020
1 parent 0fbb1bb commit 9aa68fc
Show file tree
Hide file tree
Showing 6 changed files with 3,784 additions and 149 deletions.
3 changes: 2 additions & 1 deletion configuration.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"ejbServerComponents" : "/Users/caiobessa/sources/streams/HCR/8000/HCR/EJBServer/components",
"webClientComponents" : "/Users/caiobessa/sources/streams/HCR/8000/HCR/webclient/components"
"webClientComponents" : "/Users/caiobessa/sources/streams/HCR/8000/HCR/webclient/components",
"skipComponents" : ["core","AdvancedEvidenceSharing"]
}
1 change: 1 addition & 0 deletions dist/index.js

Large diffs are not rendered by default.

94 changes: 43 additions & 51 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ const fs = require("fs-extra");
const { DOMParser } = require("xmldom");
const cliProgress = require("cli-progress");

let configurations;

async function getConfigurations() {
const configurations = await fs.readJSON(
path.join(".", "/", "configuration.json")
path.join(".", "configuration.json")
);
return configurations;
}


let progressBar = startProgressBar();
};

// Nice to have - Add a blacklist of components we don't want.

Expand All @@ -23,31 +22,28 @@ const JS_FILES_PATTERN = "/**/*.js";
const EJB_SERVER = "EJBServer";
const WEB_CLIENT = "webclient";

const findAndCopyFiles = async (path, baseDir) => {
const findAndCopyFiles = async (path, baseDir) => {
const files = await glob(path);
await copyFileToResultsDir(files, baseDir);
};

const progressBarCli = startProgressBar();

function startProgressBar() {
return new cliProgress.SingleBar(
{
format:
" |- Searching for artefacts in the components files: {percentage}%" +
" - " +
"|| {bar}||",
fps: 5,
barsize: 30,
},
cliProgress.Presets.shades_classic
);
}
const progressBarCli = createProgressBar();

function createProgressBar() {
return new cliProgress.SingleBar(
{
format:
" |- Searching for artefacts in the components files: {percentage}%" +
" - " +
"|| {bar} ||",
fps: 5,
barsize: 30,
},
cliProgress.Presets.shades_classic
);
}

const copyFileToResultsDir = async function (files, baseDir) {

// TODO - Read in Parallel - https://stackoverflow.com/questions/37576685/using-async-await-with-a-foreach-loop
progressBarCli.setTotal( progressBarCli.getTotal() + files.length);
await Promise.all(
files.map(async (file) => {
const resultsFilePath = path.join(
Expand All @@ -56,16 +52,16 @@ const copyFileToResultsDir = async function (files, baseDir) {
file.substring(file.indexOf(baseDir))
);
await fs.copy(file, resultsFilePath);
progressBarCli.increment();
})
);
};

const copyJavaRenderers = async ({ webClientComponents }) => {

const files = await glob(webClientComponents + "/**/DomainsConfig.xml",{ silent :true});
progressBarCli.setTotal( progressBarCli.getTotal() + files.length);
//TODO - Read in parallel - https://stackoverflow.com/questions/37576685/using-async-await-with-a-foreach-loop
const skipComponents = configurations.skipComponents.join("|");
const files = await glob(
webClientComponents +
`/!(*${skipComponents})/DomainsConfig.xml`
);
return Promise.all(
files.map(async (filePath) => {
const data = await fs.readFile(filePath, "UTF-8");
Expand All @@ -86,38 +82,34 @@ const copyJavaRenderers = async ({ webClientComponents }) => {
}
}
}
progressBarCli.increment();
})
);
};

const run = async () => {
const {
ejbServerComponents,
webClientComponents,
} = await getConfigurations();
configurations = await getConfigurations();
const { ejbServerComponents, webClientComponents } = configurations;
// EjbServer

progressBarCli.start(1, 0);
var start = new Date();



console.log("...Copping files: " + start);

const steps = [
findAndCopyFiles(ejbServerComponents + CSS_FILES_PATTERN, EJB_SERVER),
findAndCopyFiles(ejbServerComponents + JS_FILES_PATTERN, EJB_SERVER),
findAndCopyFiles(webClientComponents + CSS_FILES_PATTERN, WEB_CLIENT),
findAndCopyFiles(webClientComponents + JS_FILES_PATTERN, WEB_CLIENT),
copyJavaRenderers({ webClientComponents }),
].map((e) => e.then(() => progressBarCli.increment()));

await Promise.all(
[findAndCopyFiles(ejbServerComponents + CSS_FILES_PATTERN, EJB_SERVER),
findAndCopyFiles(ejbServerComponents + JS_FILES_PATTERN, EJB_SERVER),
findAndCopyFiles(webClientComponents + CSS_FILES_PATTERN, WEB_CLIENT),
findAndCopyFiles(webClientComponents + JS_FILES_PATTERN, WEB_CLIENT),
copyJavaRenderers({ webClientComponents })
]);
progressBarCli.increment();

var end = new Date();
console.log(`Start ${start}- End: ${end}`);

progressBarCli.stop();
progressBarCli.start(steps.length, 0);

await Promise.all(steps);

var end = new Date();

progressBarCli.stop();
console.log(`Finished`, start, `End:`, end);
};

run();
Loading

0 comments on commit 9aa68fc

Please sign in to comment.