Skip to content

Commit

Permalink
chore: enable errors for cem validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nayden Naydenov committed Jan 17, 2024
1 parent 38861c8 commit 15e257e
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/base/package-scripts.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const scripts = {
generateTemplates: `mkdirp src/generated/templates && cross-env UI5_BASE=true UI5_TS=true node "${LIB}/hbs2ui5/index.js" -d test/elements -o src/generated/templates`,
generateAPI: {
default: "nps generateAPI.generateCEM generateAPI.validateCEM",
generateCEM: `cem analyze --config "${LIB}/cem/custom-elements-manifest.config.mjs"`,
validateCEM: `node "${LIB}/cem/validate.js"`,
generateCEM: `cem analyze --config "${LIB}/cem/custom-elements-manifest.config.mjs" --ui5package`,
validateCEM: `node "${LIB}/cem/validate.js" --ui5package`,
},
watch: {
default: 'concurrently "nps watch.src" "nps watch.styles"',
Expand Down
1 change: 1 addition & 0 deletions packages/fiori/package-scripts.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const filterOut = [
const options = {
port: 8081,
portStep: 2,
ui5package: true,
fioriPackage: true,
typescript: true,
noWatchTS: true,
Expand Down
1 change: 1 addition & 0 deletions packages/main/package-scripts.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const options = {
portStep: 2,
typescript: true,
noWatchTS: true,
ui5package: true,
};

const scripts = getScripts(options);
Expand Down
4 changes: 2 additions & 2 deletions packages/tools/components-package/nps.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ const getScripts = (options) => {
},
generateAPI: {
default: `nps ${ tsOption ? "generateAPI.generateCEM generateAPI.validateCEM" : "generateAPI.prepare generateAPI.preprocess generateAPI.jsdoc generateAPI.cleanup generateAPI.prepareManifest"}`,
generateCEM: `cem analyze --config "${LIB}/cem/custom-elements-manifest.config.mjs"`,
validateCEM: `node "${LIB}/cem/validate.js"`,
generateCEM: `cem analyze --config "${LIB}/cem/custom-elements-manifest.config.mjs" ${ options.ui5package ? "--ui5package" : "" }`,
validateCEM: `node "${LIB}/cem/validate.js" ${ options.ui5package ? "--ui5package" : "" }`,
prepare: `node "${LIB}/copy-and-watch/index.js" --silent "dist/**/*.js" jsdoc-dist/`,
prepareManifest: `node "${LIB}/generate-custom-elements-manifest/index.js" dist dist`,
preprocess: `node "${preprocessJSDocScript}" jsdoc-dist/ src`,
Expand Down
17 changes: 9 additions & 8 deletions packages/tools/lib/cem/custom-elements-manifest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,15 @@ export default {
}
})
},
packageLinkPhase({ customElementsManifest }) {
// Uncomment and handle errors appropriately
// const JSDocErrors = getJSDocErrors();
// if (JSDocErrors.length > 0) {
// console.log(JSDocErrors.join("\n"));
// console.log(`Invalid JSDoc. ${JSDocErrors.length} were found.`);
// throw new Error(`Invalid JSDoc.`);
// }
packageLinkPhase({ customElementsManifest, context }) {
if (context.ui5package) {
const JSDocErrors = getJSDocErrors();
if (JSDocErrors.length > 0) {
console.log(JSDocErrors.join("\n"));
console.log(`Invalid JSDoc. ${JSDocErrors.length} were found.`);
throw new Error(`Invalid JSDoc.`);
}
}

customElementsManifest.modules?.forEach(m => {
m.path = m.path?.replace(/^src/, "dist").replace(/\.ts$/, ".js");
Expand Down
10 changes: 6 additions & 4 deletions packages/tools/lib/cem/validate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const fs = require('fs');
const Ajv = require('ajv');
const path = require('path');
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const argv = yargs(hideBin(process.argv))
.argv;

// Load your JSON schema
const extenalSchema = require('./schema.json');
Expand Down Expand Up @@ -46,8 +50,7 @@ let validate = ajv.compile(internalSchema)
if (validate(inputDataInternal)) {
console.log('Validation internal custom-elements successful');
} else {
console.error('Validation of internal custom-elements failed');
// console.error('Validation of internal custom-elements failed:', validate.errors);
console.error('Validation of internal custom-elements failed:', argv.ui5package ? validate.errors : "");
}

validate = ajv.compile(extenalSchema)
Expand All @@ -58,6 +61,5 @@ if (validate(inputDataExternal)) {
fs.writeFileSync(inputFilePath, JSON.stringify(inputDataExternal, null, 2), 'utf8');
fs.writeFileSync(inputFilePath.replace("custom-elements", "custom-elements-internal"), JSON.stringify(inputDataInternal, null, 2), 'utf8');
} else {
console.error('Validation of external custom-elements failed:');
// console.error('Validation of external custom-elements failed:', ajv.errorsText(validate.errors));
console.error('Validation of external custom-elements failed:', argv.ui5package ? validate.errors : "" );
}
33 changes: 33 additions & 0 deletions patches/@custom-elements-manifest+analyzer+0.8.4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/node_modules/@custom-elements-manifest/analyzer/cli.js b/node_modules/@custom-elements-manifest/analyzer/cli.js
index 49da928..1868c9b 100755
--- a/node_modules/@custom-elements-manifest/analyzer/cli.js
+++ b/node_modules/@custom-elements-manifest/analyzer/cli.js
@@ -63,7 +63,7 @@ export async function cli({ argv = process.argv, cwd = process.cwd(), noWrite }
let plugins = await addFrameworkPlugins(mergedOptions);
plugins = [...plugins, ...(userConfig?.plugins || [])];

- const context = { dev: mergedOptions.dev, thirdPartyCEMs };
+ const context = { dev: mergedOptions.dev, thirdPartyCEMs, ui5package: mergedOptions.ui5package };

/**
* Create the manifest
diff --git a/node_modules/@custom-elements-manifest/analyzer/src/utils/cli-helpers.js b/node_modules/@custom-elements-manifest/analyzer/src/utils/cli-helpers.js
index 30cfee9..ff27d8b 100644
--- a/node_modules/@custom-elements-manifest/analyzer/src/utils/cli-helpers.js
+++ b/node_modules/@custom-elements-manifest/analyzer/src/utils/cli-helpers.js
@@ -61,6 +61,7 @@ export const DEFAULTS = {
stencil: false,
fast: false,
catalyst: false,
+ ui5generation: false,
'catalyst-major-2': false,
}

@@ -80,6 +81,7 @@ export function getCliConfig(argv) {
{ name: 'fast', type: Boolean },
{ name: 'catalyst', type: Boolean },
{ name: 'catalyst-major-2', type: Boolean },
+ { name: 'ui5generation', type: Boolean },
];

return commandLineArgs(optionDefinitions, { argv });

0 comments on commit 15e257e

Please sign in to comment.