Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New changes to the example menu #506

Merged
merged 6 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions packages/web-new/external-scripts/generate-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ const initialPath = "../../examples";
//path to the get the raw files from the github
const rawFilePath = "https://raw.githubusercontent.com/eclipse-thingweb/playground/master/examples"

async function getExamples(){
async function getExamples() {
const files = await fs.readdir(initialPath)

const examplesPaths = {}

for(const file of files){
for (const file of files) {
examplesPaths[file] = {}

const categories = await fs.readdir(path.join(initialPath, file))

//sorting them by the first number in their name
categories.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }))

for(const category of categories){
for (const category of categories) {

const examples = await fs.readdir(path.join(initialPath, file, category))

Expand All @@ -49,17 +49,16 @@ async function getExamples(){
"examples": {}
}

for(const example of examples){
if(path.extname(example) == ".txt"){
for (const example of examples) {

if (path.extname(example) == ".txt") {
try {
const categoryDescription = await fs.readFile(path.join(initialPath, file, category, example), 'utf8')
examplesPaths[file][category]["description"] = categoryDescription
} catch (err) {
console.error("Failed to read file: ", err);
}
}

if(path.extname(example) == ".jsonld"){
} else if (path.extname(example) == ".jsonld" || path.extname(example) == ".json") {
const exampleData = JSON.parse(await fs.readFile(path.join(initialPath, file, category, example), 'utf8'))
const exampleTitle = exampleData["$title"]
const exampleDescription = exampleData["$description"]
Expand All @@ -68,6 +67,8 @@ async function getExamples(){
"description": exampleDescription,
"path": `${rawFilePath}/${file}/${category}/${example}`
}
} else {
//Do nothing
}
}
}
Expand All @@ -76,15 +77,15 @@ async function getExamples(){
return examplesPaths
}

async function writeExamplesToFile(){
async function writeExamplesToFile() {
const examplesData = await getExamples()

try {
const jsonData = JSON.stringify(examplesData, null, 2)
const filePath = "./src/examples-paths/examples-paths.json"
await fs.writeFile(filePath, jsonData, 'utf-8')
console.log("File created succesfully")

} catch (err) {
console.error("Failed to wirte JSON file: ", err)
}
Expand Down
20 changes: 10 additions & 10 deletions packages/web-new/src/examples-paths/examples-paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
"description": "A simple Thing Description using CoAP. The target resource is specified in the Thing Description by the href member of a form and the request method (e.g., GET, PUT, POST, or DELETE) is specified using the cov:method member of a form.",
"path": "https://raw.githubusercontent.com/eclipse-thingweb/playground/master/examples/td/5-protocols/CoAP-simple-td-no-defaults.td.jsonld"
},
"extended-forms-multiple-op.td.jsonld": {
"title": "Extended Forms Multiple op",
"description": "In the case of a forms entry that has multiple op values the usage of the htv:methodName is not permitted. A TD Processor will extend the multiple op values to separate forms entries and associates a single operation with the default assumption.",
"path": "https://raw.githubusercontent.com/eclipse-thingweb/playground/master/examples/td/5-protocols/extended-forms-multiple-op.td.jsonld"
},
"HTTP-readproperty.td.jsonld": {
"title": "HTTP readproperty",
"description": "This example shows the binding of the readproperty operation for the HTTP.",
Expand All @@ -143,11 +148,6 @@
"description": "This example shows the minimal set of terms to configure a single coil reading using Modbus. Notice that the unitID is contained in the href as the first element of the path.",
"path": "https://raw.githubusercontent.com/eclipse-thingweb/playground/master/examples/td/5-protocols/Modbus-single-coil.td.jsonld"
},
"extended-forms-multiple-op.td.jsonld": {
"title": "Extended Forms Multiple op",
"description": "In the case of a forms entry that has multiple op values the usage of the htv:methodName is not permitted. A TD Processor will extend the multiple op values to separate forms entries and associates a single operation with the default assumption.",
"path": "https://raw.githubusercontent.com/eclipse-thingweb/playground/master/examples/td/5-protocols/extended-forms-multiple-op.td.jsonld"
},
"subprotocol-longpoll.td.jsonld": {
"title": "Subprotocol Longpoll",
"description": "protocols may have defined Subprotocols that can be used for some interaction types. For example, to receive asynchronous notifications using HTTP, some servers may support long polling.",
Expand All @@ -158,11 +158,6 @@
"6-security-schemas": {
"description": "This category contains various examples concerning the different types of security schemas that could/should be used for a Thing Description, as well as the different ways to combine multiple security schemes.",
"examples": {
"OAuth2-scopes.td.jsonld": {
"title": "OAuth2 Scopes",
"description": "OAuth 2.0 makes use of scopes. These are identifiers that may appear in tokens and must match with corresponding identifiers in a resource to allow access to that resource.",
"path": "https://raw.githubusercontent.com/eclipse-thingweb/playground/master/examples/td/6-security-schemas/OAuth2-scopes.td.jsonld"
},
"apikey-in-body-simplified.td.jsonld": {
"title": "Apikey In Body Simplified",
"description": "It is possbile to simplify how security parameters are included in the payload by using the feature that the location referenced by a JSON pointer in a body location will be automatically inserted if it does not exist.",
Expand Down Expand Up @@ -212,6 +207,11 @@
"title": "noSec Security",
"description": "Security configuration in the TD is mandatory, therefore the nosec security scheme is provided for the case that no security is needed.",
"path": "https://raw.githubusercontent.com/eclipse-thingweb/playground/master/examples/td/6-security-schemas/noSec-security.td.jsonld"
},
"OAuth2-scopes.td.jsonld": {
"title": "OAuth2 Scopes",
"description": "OAuth 2.0 makes use of scopes. These are identifiers that may appear in tokens and must match with corresponding identifiers in a resource to allow access to that resource.",
"path": "https://raw.githubusercontent.com/eclipse-thingweb/playground/master/examples/td/6-security-schemas/OAuth2-scopes.td.jsonld"
}
}
},
Expand Down
Loading
Loading