Skip to content

Commit 42757ac

Browse files
authored
Merge pull request #599 from devtron-labs/release-candidate-v0.30.0
release: Release candidate v0.30.0
2 parents 349b6bd + 619d07d commit 42757ac

File tree

172 files changed

+3807
-1523
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+3807
-1523
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.eslintrc.cjs
2+
scripts/*.cjs
23

34
# Files with ESLint errors/warnings
45
src/Common/AddCDButton/AddCDButton.tsx
@@ -13,7 +14,6 @@ src/Common/Checkbox.tsx
1314
src/Common/ClipboardButton/__tests__/ClipboardButton.test.tsx
1415
src/Common/CodeEditor/CodeEditor.tsx
1516
src/Common/Common.service.ts
16-
src/Common/CustomInput/CustomInput.tsx
1717
src/Common/CustomTagSelector/PropagateTagInfo.tsx
1818
src/Common/CustomTagSelector/TagDetails.tsx
1919
src/Common/CustomTagSelector/TagLabelValueSelector.tsx

.eslintrc.cjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ module.exports = {
122122
{
123123
name: 'react-toastify',
124124
message: 'Please use "ToastManager.showToast" instead.',
125-
}
125+
},
126+
],
127+
patterns: [
128+
{
129+
group: ['IconBase'],
130+
message: 'Please use "Icon" component instead.',
131+
},
126132
],
127133
},
128134
],

.husky/pre-commit

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,35 @@
1717

1818
. "$(dirname "$0")/_/husky.sh"
1919

20-
npx tsc --noEmit
21-
npm run lint-staged
20+
echo "Running pre-commit hook..."
21+
22+
# Check for changes in the Icon folder
23+
CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep -E 'IconV2/|generate-icon.cjs' || true)
24+
25+
if [ -n "$CHANGED_FILES" ]; then
26+
echo "Changes detected in the Icon folder or icon generation script. Running icon generation script..."
27+
28+
if ! npm run generate-icon; then
29+
echo "Error: Icon generation script failed."
30+
exit 1
31+
fi
32+
33+
echo "Icon.tsx updated. Adding to commit."
34+
git add src/Shared/Components/Icon/Icon.tsx
35+
else
36+
echo "No changes in the IconsV2 folder. Skipping icon generation."
37+
fi
38+
39+
# TypeScript check
40+
if ! npx tsc --noEmit; then
41+
echo "Error: TypeScript check failed."
42+
exit 1
43+
fi
44+
45+
# Lint-staged
46+
if ! npm run lint-staged; then
47+
echo "Error: Lint-staged failed."
48+
exit 1
49+
fi
50+
51+
echo "Pre-commit hook completed successfully."

package-lock.json

Lines changed: 32 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.7.0-patch-1",
3+
"version": "1.8.0",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
@@ -32,7 +32,8 @@
3232
"build-lib": "vite build",
3333
"preview": "vite preview",
3434
"lint-staged": "lint-staged",
35-
"postinstall": "patch-package"
35+
"postinstall": "patch-package",
36+
"generate-icon": "node ./scripts/generate-icon.cjs"
3637
},
3738
"devDependencies": {
3839
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
@@ -84,7 +85,7 @@
8485
"@rjsf/utils": "^5.13.3",
8586
"@rjsf/validator-ajv8": "^5.13.3",
8687
"@typeform/embed-react": "2.20.0",
87-
"dompurify": "^3.0.2",
88+
"dompurify": "^3.2.4",
8889
"patch-package": "^8.0.0",
8990
"react": "^17.0.2",
9091
"react-dom": "^17.0.2",
@@ -111,7 +112,7 @@
111112
"dayjs": "^1.11.13",
112113
"fast-json-patch": "^3.1.1",
113114
"framer-motion": "^6.5.1",
114-
"jsonpath-plus": "^10.0.0",
115+
"jsonpath-plus": "^10.3.0",
115116
"marked": "^13.0.3",
116117
"nanoid": "^3.3.8",
117118
"react-codemirror-merge": "4.23.6",

scripts/generate-icon.cjs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const { execFile } = require('child_process')
4+
5+
// Base path relative to the current script
6+
const basePath = path.resolve(__dirname, '../src')
7+
8+
// Directory containing SVG icons and the output file
9+
const iconsDir = path.join(basePath, 'Assets', 'IconV2')
10+
const outputFile = path.join(basePath, 'Shared', 'Components', 'Icon', 'Icon.tsx')
11+
12+
const runESLint = (filePath) => {
13+
execFile('npx', ['eslint', filePath, '--fix'], (error, stdout, stderr) => {
14+
if (error) {
15+
console.error(`Error running ESLint: ${error.message}`)
16+
return
17+
}
18+
if (stderr) {
19+
console.error(`ESLint stderr: ${stderr}`)
20+
}
21+
if (stdout) {
22+
console.log(`ESLint output:\n${stdout}`)
23+
}
24+
console.log('ESLint completed successfully.')
25+
})
26+
}
27+
28+
const generateIconComponent = () => {
29+
// Read all files in the icons directory
30+
const files = fs.readdirSync(iconsDir)
31+
32+
// Filter for SVG files
33+
const svgFiles = files.filter((file) => file.endsWith('.svg'))
34+
35+
// Generate import statements and the icon map
36+
const imports = []
37+
const iconMapEntries = []
38+
39+
svgFiles.forEach((file) => {
40+
// Remove the .svg extension
41+
const iconName = path.basename(file, '.svg')
42+
// Convert icon-name to IconName for importName
43+
const importName = iconName
44+
.replace(/(^\w+)/, (match) => match.toUpperCase())
45+
.replace(/-./g, (match) => match[1].toUpperCase())
46+
// Push imports statement
47+
imports.push(`import { ReactComponent as ${importName} } from '@IconsV2/${file}'`)
48+
// Push icons to iconMap
49+
iconMapEntries.push(`["${iconName}"]: ${importName},`)
50+
})
51+
52+
// Generate the Icon.tsx content
53+
const content = `
54+
// NOTE: This file is auto-generated. Do not edit directly. Run the script \`npm run generate-icon\` to update.
55+
56+
${imports.join('\n')}
57+
58+
// eslint-disable-next-line no-restricted-imports
59+
import { IconBase } from './IconBase';
60+
import { IconBaseProps } from './types';
61+
62+
export const iconMap = {
63+
${iconMapEntries.join('\n')}
64+
};
65+
66+
export type IconName = keyof typeof iconMap;
67+
68+
export interface IconsProps extends Omit<IconBaseProps, 'name' | 'iconMap'> {
69+
/** The name of the icon to render. */
70+
name: keyof typeof iconMap;
71+
}
72+
73+
export const Icon = (props: IconsProps) => {
74+
return <IconBase {...props} iconMap={iconMap} />;
75+
};
76+
`
77+
78+
// Write the content to the Icon.tsx file
79+
fs.writeFileSync(outputFile, content.trim(), 'utf-8')
80+
console.log(`Icon component file generated at: ${outputFile}`)
81+
82+
// Run ESLint on the generated file
83+
runESLint(outputFile)
84+
}
85+
86+
// Run the script
87+
generateIconComponent()

src/Assets/Icon/ic-error.svg

Lines changed: 1 addition & 1 deletion
Loading

src/Assets/Icon/ic-info-filled.svg

Lines changed: 1 addition & 1 deletion
Loading

src/Assets/Icon/ic-success.svg

Lines changed: 1 addition & 1 deletion
Loading

src/Assets/Icon/ic-visibility-off.svg

Lines changed: 19 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)