Commit 4f29ff1f authored by Jerome Cambon's avatar Jerome Cambon
Browse files

Test envirionment setup + first test + License in source files

parent a2fb21f8
......@@ -90,7 +90,7 @@ This is done with 'custom tags', which are JSDoc-like tags, and use the '-@tag'
The builder is using https://github.com/runem/web-component-analyzer.
See the section "How to document your components using JSDoc" from its documentation
for more details about adding information on the component (@element) and on its properties (@prop).
for more details about adding information on the component (@element), on its properties (@prop) and events (@fires).
<br><br>
#### Examples of property tags
......
This diff is collapsed.
......@@ -4,13 +4,29 @@
"description": "",
"author": "poc-widget-builder",
"license": "GPLv2",
"type": "module",
"scripts": {},
"scripts": {
"typescript-compile": "tsc --build tsconfig.json",
"test": "jest 2>&1",
"test:dev": "jest --watch"
},
"dependencies": {
"@types/node": "^14.14.35",
"jdenticon": "^3.1.0",
"jsdoc": "^3.6.6",
"typescript": "^4.1.3",
"web-component-analyzer": "^1.1.6"
},
"devDependencies": {
"@types/jest": "^26.0.22",
"jest": "^26.6.3",
"ts-jest": "^26.5.4"
},
"jest": {
"verbose": true,
"roots": [
"./test/"
],
"preset": "ts-jest",
"testEnvironment": "node"
}
}
import {PropertyConstraint} from "./PropertyConstraint.js";
/*
* Copyright © 2021 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {PropertyConstraint} from "./PropertyConstraint";
export class CustomTagHandler {
......
/*
* Copyright © 2021 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {analyzeText, AnalyzeTextResult, transformAnalyzerResult} from "web-component-analyzer";
import fs from "fs";
import {PropertiesInfo} from "./PropertiesInfo.js";
import {Property} from "./Property.js";
import jdenticon from "jdenticon/standalone";
import {CustomTagHandler} from "./CustomTagHandler.js";
import {PropertiesInfo} from "./PropertiesInfo";
import {Property} from "./Property";
import {CustomTagHandler} from "./CustomTagHandler";
import * as fs from "fs";
import * as jdenticon from "jdenticon/standalone";
export class CustomWidgetBuilder {
......@@ -38,16 +56,14 @@ export class CustomWidgetBuilder {
private createPropertiesFile(propertiesInfo: PropertiesInfo) {
//TODO replace console.log() by logging
let output = JSON.stringify(propertiesInfo, null, 2)
console.log(output);
// console.log(output);
if (!fs.existsSync(this.outputDir)) {
console.log(`ERROR: output directory does not exist: ${this.outputDir}`);
return;
}
let filePath = `${this.outputDir}/${propertiesInfo.id}.json`;
fs.writeFile(filePath, output, (err) => {
if (err) {
console.log(`ERROR: Cannot write properties file ${filePath}`);
console.log(`[${err.message}]`);
} else {
console.log(`${filePath} has been generated!`);
}
});
fs.writeFileSync(filePath, output);
console.log(`${filePath} has been generated!`);
}
private analyzeFile(): string {
......
/*
* Copyright © 2021 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {Property} from "./Property";
export class PropertiesInfo {
......
/*
* Copyright © 2021 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {PropertyConstraint} from "./PropertyConstraint";
export class Property {
......
/*
* Copyright © 2021 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
export class PropertyConstraint {
public min: string | undefined;
public max: string | undefined;
......
import {CustomWidgetBuilder} from "./CustomWidgetBuilder.js";
/*
* Copyright © 2021 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {CustomWidgetBuilder} from "./CustomWidgetBuilder";
let wcFile;
let outputDir;
......
/*
* Copyright © 2019 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {CustomWidgetBuilder} from "../src/CustomWidgetBuilder";
import * as os from "os";
const fs = require('fs');
describe('CustomWidgetBuilder', () => {
test('should generate a correct json file when a simple web component is given as input', async () => {
let builder = new CustomWidgetBuilder();
let tempDir = fs.mkdtempSync(os.tmpdir());
builder.generatePropertiesFile("test/resources/WcExample.ts", tempDir);
let generatedFile = tempDir + "/WcExample.json";
expect(fs.existsSync(generatedFile)).toBeTruthy();
let jsonProperties = JSON.parse(fs.readFileSync(generatedFile, 'utf8'));
expect(jsonProperties.id).toBe("wcExample");
expect(jsonProperties.name).toBe("WcExample");
expect(jsonProperties.template).toBe("@wcExample.tpl.html");
expect(jsonProperties.description.length).toBeGreaterThan(0);
expect(jsonProperties.order).toBe("1");
expect(jsonProperties.icon.length).toBeGreaterThan(0);
expect(jsonProperties.properties.length).toBe(2);
});
});
......@@ -20,7 +20,8 @@ export class WcExample extends LitElement {
/**
* -@bond variable
*/
@property({ type: Number }) counter = 5;
@property({ type: Number })
counter = 5;
__increment() {
this.counter += 1;
......
{
"compilerOptions": {
/* Basic Options */
"target": "esnext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": ["esnext"], /* Specify library files to be included in the compilation. */
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
// "lib": ["esnext"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
......@@ -45,8 +45,8 @@
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
// "skipLibCheck": true,
// "forceConsistentCasingInFileNames": true
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
......@@ -59,5 +59,5 @@
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"exclude": ["test/**/*"]
"exclude": ["test/resources/*"]
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment