Toggle navigation
Toggle navigation
This project
Loading...
Sign in
arcs
/
arcs.js
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
3
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jean-Yves Didier
2023-04-21 00:25:16 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
bcc67f18a55a30dc00c91761902f348ad37a65d1
bcc67f18
1 parent
18d88cce
component repository generator
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
70 deletions
example/loop.js
tools/arcsrepos.js
tools/arcsrepos.mjs
example/loop.js
View file @
bcc67f1
...
...
@@ -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'."
}
}
}
};
...
...
tools/arcsrepos.js
View file @
bcc67f1
...
...
@@ -13,17 +13,17 @@ import path from 'node:path';
* - "-h" or "--help" displays usage
*/
let
outputFile
=
"repos.json"
;
let
outputFile
=
"repos
itory
.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
{
co
nsole
.
log
(
`
${
element
}
does not contain a description`
)
;
co
mponents
[
c
]
=
[
components
[
c
],
cmp
[
c
]
]
;
}
}
catch
(
e
)
{
console
.
log
(
`
${
element
}
is not a valid component`
);
}
}
)
;
};
cons
ole
.
log
(
list
)
;
cons
t
result
=
{
components
,
libraries
}
;
fs
.
writeFileSync
(
outputFile
,
JSON
.
stringify
(
result
,
null
,
2
));
...
...
tools/arcsrepos.mjs
deleted
100644 → 0
View file @
18d88cc
/**
* 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= {};
Please
register
or
login
to post a comment