Jean-Yves Didier

component repository generator

......@@ -99,4 +99,24 @@ Sum.signal("sum");
// keys are factory names, value are actual constructors modified by
// ARCS.Component.create
export default {Loop: Loop, DisplayInt: DisplayInt, Sum: Sum};
export default {
Loop,
DisplayInt,
Sum,
__arcs__ : {
components : {
Loop: {
keywords : ["loop", "iteration", "repeat"],
description : "Iterates for a given number of times"
},
DisplayInt : {
keywords : ["display", "integer", "number"],
description : "DisplayInt will display an integer received on its display slot."
},
Sum : {
keywords : ["sum", "add", "integer"],
description : "Sum is a component summing integers passed to its slot 'add' and the result is sent back by signal 'sum'."
}
}
}
};
......
......@@ -13,17 +13,17 @@ import path from 'node:path';
* - "-h" or "--help" displays usage
*/
let outputFile = "repos.json";
let outputFile = "repository.json";
let inputDir = ".";
const usage = function(idx) {
console.log(path.basename(process.argv[1])," [-o output_file] [-d component_dir] [-h]");
console.log("\toutput_file is the generated repository json file (by default 'repos.json')");
console.log("\tcomponent_dir is the directory storing components (by default '.')");
process.exit(0);
return 0;
};
const helpers = {
'-h' : usage,
'--help': usage,
......@@ -60,24 +60,54 @@ const getFiles = function(dir, filter, files_) {
return files_;
};
const files = getFiles(path.resolve(inputDir),'.js');
const list= {};
const libraries= {};
let components = {};
files.forEach(async (element) => {
for(const element of files) {
const cmp = {};
try {
const components = await import(path.resolve(element));
if (components.__arcs__ !== undefined) {
console.log(`${element} contains a description`);
Object.assign(list, components.__arcs__);
const exportDefault = await import(path.resolve(element));
const exportModule = exportDefault.default;
for (let c in exportModule) {
if (c === '__arcs__') {
let metaCmp = exportModule[c].components;
for(let d in metaCmp) {
if (cmp[d] === undefined) {
cmp[d] = metaCmp[d];
} else {
Object.assign(cmp[d], metaCmp[d]);
}
}
let metaLib = exportModule[c].dependencies;
if (metaLib !== undefined) {
libraries[path.relative(inputDir,element)] = metaLib;
}
} else {
if (exportModule[c] !== undefined) {
cmp[c] = { library: path.relative(inputDir,element) };
} else {
cmp[c]['library'] = path.relative(inputDir,element);
}
}
}
} catch (e) {
console.log(`${element} is not a valid component library`);
}
for (let c in cmp) {
console.log(c);
if (components[c] === undefined) {
console.log(
`adding component ${c} from ${cmp[c].library}`
)
components[c] = cmp[c];
} else {
console.log(`${element} does not contain a description`);
components[c] = [ components[c], cmp[c] ];
}
} catch (e) {
console.log(`${element} is not a valid component`);
}
});
};
console.log(list);
const result = { components, libraries };
fs.writeFileSync(outputFile, JSON.stringify(result, null, 2));
......
/**
* This tool is intended to build a description of a repository of components
*/
import process from 'node:process';
import * as fs from 'node:fs';
import path from 'node:path';
/**
* possible arguments:
* - "-o" with output file
* - "-d" with input directory
* - "-h" or "--help" displays usage
*/
let outputFile = "repos.json";
let inputDir = ".";
const usage = function(idx) {
console.log(path.basename(process.argv[1])," [-o output_file] [-d component_dir] [-h]");
console.log("\toutput_file is the generated repository json file (by default 'repos.json')");
console.log("\tcomponent_dir is the directory storing components (by default '.')");
return 0;
};
const helpers = {
'-h' : usage,
'--help': usage,
'-o' : function(idx) {
outputFile = process.argv[idx+1];
return 1;
},
'-d' : function(idx) {
outputFile = process.argv[idx+1];
return 1;
}
};
for (let i=2; i<process.argv.length; i++) {
if (helpers.hasOwnProperty(process.argv[i])) {
let shift = helpers[process.argv[i]](i);
i+=shift;
}
}
/**
*
*
*
*/
const list= {};