tera-system-ui 0.0.24 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/avatar/Avatar.svelte +43 -43
- package/dist/components/brand-logo/BrandLogo.svelte +31 -31
- package/dist/components/button/Button.svelte +49 -49
- package/dist/components/combobox/Combobox.svelte +8 -8
- package/dist/components/command/command.scss +72 -72
- package/dist/components/command/components/Command.svelte +120 -120
- package/dist/components/command/components/Command.svelte.d.ts +1 -1
- package/dist/components/command/components/CommandEmpty.svelte +30 -30
- package/dist/components/command/components/CommandEmpty.svelte.d.ts +1 -1
- package/dist/components/command/components/CommandGroup.svelte +110 -110
- package/dist/components/command/components/CommandGroup.svelte.d.ts +1 -1
- package/dist/components/command/components/CommandInput.svelte +92 -92
- package/dist/components/command/components/CommandInput.svelte.d.ts +1 -1
- package/dist/components/command/components/CommandItem.svelte +110 -110
- package/dist/components/command/components/CommandItem.svelte.d.ts +1 -1
- package/dist/components/command/components/CommandList.svelte +56 -56
- package/dist/components/command/components/CommandLoading.svelte +28 -28
- package/dist/components/command/components/CommandLoading.svelte.d.ts +1 -1
- package/dist/components/command/components/CommandSeparator.svelte +21 -21
- package/dist/components/command/components/CommandSeparator.svelte.d.ts +1 -1
- package/dist/components/dialog/Dialog.astro +64 -64
- package/dist/components/dialog/Dialog.svelte +109 -109
- package/dist/components/dialog/dialog.scss +115 -115
- package/dist/components/dropdown-menu/components/DropdownMenu.svelte +33 -33
- package/dist/components/dropdown-menu/components/DropdownMenuGroup.svelte +11 -11
- package/dist/components/dropdown-menu/components/DropdownMenuHeader.svelte +11 -11
- package/dist/components/dropdown-menu/components/DropdownMenuItem.svelte +30 -30
- package/dist/components/dropdown-menu/components/DropdownMenuSeparator.svelte +10 -10
- package/dist/components/header/Header.svelte +36 -36
- package/dist/components/header/header.scss +19 -19
- package/dist/components/icons/IconArrowBigRightFilled.svelte +10 -10
- package/dist/components/icons/IconBook.svelte +10 -10
- package/dist/components/icons/IconBookmarkPlus.svelte +10 -10
- package/dist/components/icons/IconCalculator.svelte +10 -10
- package/dist/components/icons/IconCheck.svelte +10 -10
- package/dist/components/icons/IconChevronDown.svelte +10 -10
- package/dist/components/icons/IconCopy.svelte +10 -10
- package/dist/components/icons/IconCopyCheckFilled.svelte +10 -10
- package/dist/components/icons/IconHamburger.svelte +10 -10
- package/dist/components/icons/IconLanguage.svelte +10 -10
- package/dist/components/icons/IconLoader2.svelte +10 -10
- package/dist/components/icons/IconLogout.svelte +10 -10
- package/dist/components/icons/IconMoon.svelte +10 -10
- package/dist/components/icons/IconPointFilled.svelte +10 -10
- package/dist/components/icons/IconSearch.svelte +10 -10
- package/dist/components/icons/IconSettings.svelte +10 -10
- package/dist/components/icons/IconSun.svelte +10 -10
- package/dist/components/icons/IconSwitchHorizontal.svelte +10 -10
- package/dist/components/icons/IconSwitchVertical.svelte +10 -10
- package/dist/components/icons/IconTransform.svelte +10 -10
- package/dist/components/icons/IconX.svelte +10 -10
- package/dist/components/input/Input.svelte +24 -24
- package/dist/components/language-picker-button/LanguagePickerButton.svelte +109 -109
- package/dist/components/light-dark-toggle/LightDarkToggle.svelte +36 -36
- package/dist/components/popover/Popover.svelte +159 -159
- package/dist/components/popover-responsive/PopoverResponsive.svelte +87 -87
- package/dist/components/side-navigation/SideNavigation.svelte +114 -114
- package/dist/components/side-navigation/SideNavigationItem.svelte +17 -17
- package/dist/components/side-navigation/SideNavigationLayout.svelte +19 -19
- package/dist/components/side-navigation/sidenav.scss +149 -149
- package/dist/components/slider/Slider.svelte +181 -181
- package/dist/components/star-rating/StarRating.d.ts +10 -0
- package/dist/components/star-rating/StarRating.js +7 -0
- package/dist/components/star-rating/StarRating.svelte +88 -0
- package/dist/components/star-rating/StarRating.svelte.d.ts +3 -0
- package/dist/components/star-rating/index.d.ts +1 -0
- package/dist/components/star-rating/index.js +1 -0
- package/dist/components/tabs/components/Tabs.svelte +47 -47
- package/dist/components/tabs/components/TabsContent.svelte +34 -34
- package/dist/components/tabs/components/TabsItem.svelte +29 -29
- package/dist/components/tabs/components/TabsList.svelte +41 -41
- package/dist/components/tera-ui-context/TeraUiContext.svelte +28 -28
- package/dist/components/text-area/TextArea.svelte +88 -88
- package/dist/components/user-avatar-with-menu/UserAvatarWithMenu.svelte +67 -67
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/themes/scrollbar.scss +37 -37
- package/dist/themes/tera-ui-base.css +208 -208
- package/dist/themes/tw-preset.cjs +153 -153
- package/package.json +98 -98
- package/scripts/add-component-template.js +120 -120
- package/scripts/generate-ts-index.js +138 -138
|
@@ -1,121 +1,121 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
|
|
5
|
-
import path from "path";
|
|
6
|
-
// Get the component name from the command line arguments
|
|
7
|
-
const componentName = process.argv[3];
|
|
8
|
-
const command = process.argv[2];
|
|
9
|
-
|
|
10
|
-
if (!componentName) {
|
|
11
|
-
console.error("Please provide a component name: `npx tera-ui add component-name`");
|
|
12
|
-
process.exit(1);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (command !== 'add') {
|
|
16
|
-
console.error(`Please provide a correct command: current command ${command}`);
|
|
17
|
-
process.exit(1);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const PASCAL_CASE = 'PASCAL_CASE';
|
|
22
|
-
const KEBAB_CASE = 'KEBAB_CASE';
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function convertCase(text, convertTo) {
|
|
26
|
-
const isPascalCase = /^[A-Z][a-z0-9]+([A-Z][a-z0-9]*)*$/.test(text);
|
|
27
|
-
const isKebabCase = /^[a-z]+(-[a-z0-9]+)*$/.test(text);
|
|
28
|
-
|
|
29
|
-
if ((convertTo === PASCAL_CASE && isPascalCase) ||
|
|
30
|
-
(convertTo === KEBAB_CASE && isKebabCase)) {
|
|
31
|
-
return text;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (convertTo === PASCAL_CASE) {
|
|
35
|
-
return text
|
|
36
|
-
.toLowerCase()
|
|
37
|
-
.replace(/(?:^|[-_])(.)/g, (_, char) => char.toUpperCase());
|
|
38
|
-
} else if (convertTo === KEBAB_CASE) {
|
|
39
|
-
return text
|
|
40
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
41
|
-
.toLowerCase();
|
|
42
|
-
} else {
|
|
43
|
-
throw new Error("Invalid 'convertTo' parameter. Use 'PASCAL_CASE' or 'KEBAB_CASE'.");
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
function readFileContent(path) {
|
|
49
|
-
try {
|
|
50
|
-
const data = fs.readFileSync(path, 'utf8');
|
|
51
|
-
return data;
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error("Error reading file:", error.message);
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const componentTemplateFolder = path.join(process.cwd(), 'scripts/file-template/component');
|
|
60
|
-
|
|
61
|
-
function getComponentSvelte(componentName) {
|
|
62
|
-
let template = readFileContent(componentTemplateFolder + '/Component.svelte')
|
|
63
|
-
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
64
|
-
return template.replaceAll('ComponentProps', componentNameCase + 'Props')
|
|
65
|
-
.replaceAll('"./Component"', `"./${componentNameCase}"`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function getComponentTS(componentName) {
|
|
69
|
-
let template = readFileContent(componentTemplateFolder + '/Component.ts')
|
|
70
|
-
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
71
|
-
return template.replaceAll('Component', componentNameCase);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function getIndexTS(componentName) {
|
|
75
|
-
let template = readFileContent(componentTemplateFolder + '/index.ts')
|
|
76
|
-
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
77
|
-
return template.replaceAll('Component', componentNameCase);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
function getComponentStoriesSvelte(componentName) {
|
|
82
|
-
let template = readFileContent(componentTemplateFolder + '/Component.stories.svelte')
|
|
83
|
-
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
84
|
-
return template.replaceAll('ComponentName', componentNameCase)
|
|
85
|
-
.replaceAll('component-path', convertCase(componentName, KEBAB_CASE));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// Define the component folder and files
|
|
90
|
-
const componentDir = path.join(process.cwd(), 'src', 'lib', 'components', convertCase(componentName, KEBAB_CASE));
|
|
91
|
-
const componentStoriesDir = path.join(process.cwd(), 'src', 'stories', convertCase(componentName, KEBAB_CASE));
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const files = {
|
|
95
|
-
[`${convertCase(componentName, PASCAL_CASE)}.svelte`]: getComponentSvelte(componentName),
|
|
96
|
-
[`${convertCase(componentName, PASCAL_CASE)}.ts`]: getComponentTS(componentName),
|
|
97
|
-
[`index.ts`]: getIndexTS(componentName),
|
|
98
|
-
[`${convertCase(componentName, PASCAL_CASE)}.stories.svelte`]: getComponentStoriesSvelte(componentName),
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// Create the folder and files with template content
|
|
103
|
-
if (!fs.existsSync(componentDir)) {
|
|
104
|
-
fs.mkdirSync(componentDir);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (!fs.existsSync(componentStoriesDir)) {
|
|
108
|
-
fs.mkdirSync(componentStoriesDir);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
for (const [filename, content] of Object.entries(files)) {
|
|
113
|
-
const filePath = filename.includes('.stories.')
|
|
114
|
-
? path.join(componentStoriesDir, filename)
|
|
115
|
-
: path.join(componentDir, filename);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
fs.writeFileSync(filePath, content, 'utf8');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
console.log(`Component ${componentName} created successfully with 3 template files!`);
|
|
2
|
+
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
|
|
5
|
+
import path from "path";
|
|
6
|
+
// Get the component name from the command line arguments
|
|
7
|
+
const componentName = process.argv[3];
|
|
8
|
+
const command = process.argv[2];
|
|
9
|
+
|
|
10
|
+
if (!componentName) {
|
|
11
|
+
console.error("Please provide a component name: `npx tera-ui add component-name`");
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (command !== 'add') {
|
|
16
|
+
console.error(`Please provide a correct command: current command ${command}`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const PASCAL_CASE = 'PASCAL_CASE';
|
|
22
|
+
const KEBAB_CASE = 'KEBAB_CASE';
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
function convertCase(text, convertTo) {
|
|
26
|
+
const isPascalCase = /^[A-Z][a-z0-9]+([A-Z][a-z0-9]*)*$/.test(text);
|
|
27
|
+
const isKebabCase = /^[a-z]+(-[a-z0-9]+)*$/.test(text);
|
|
28
|
+
|
|
29
|
+
if ((convertTo === PASCAL_CASE && isPascalCase) ||
|
|
30
|
+
(convertTo === KEBAB_CASE && isKebabCase)) {
|
|
31
|
+
return text;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (convertTo === PASCAL_CASE) {
|
|
35
|
+
return text
|
|
36
|
+
.toLowerCase()
|
|
37
|
+
.replace(/(?:^|[-_])(.)/g, (_, char) => char.toUpperCase());
|
|
38
|
+
} else if (convertTo === KEBAB_CASE) {
|
|
39
|
+
return text
|
|
40
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
41
|
+
.toLowerCase();
|
|
42
|
+
} else {
|
|
43
|
+
throw new Error("Invalid 'convertTo' parameter. Use 'PASCAL_CASE' or 'KEBAB_CASE'.");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
function readFileContent(path) {
|
|
49
|
+
try {
|
|
50
|
+
const data = fs.readFileSync(path, 'utf8');
|
|
51
|
+
return data;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error("Error reading file:", error.message);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
const componentTemplateFolder = path.join(process.cwd(), 'scripts/file-template/component');
|
|
60
|
+
|
|
61
|
+
function getComponentSvelte(componentName) {
|
|
62
|
+
let template = readFileContent(componentTemplateFolder + '/Component.svelte')
|
|
63
|
+
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
64
|
+
return template.replaceAll('ComponentProps', componentNameCase + 'Props')
|
|
65
|
+
.replaceAll('"./Component"', `"./${componentNameCase}"`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getComponentTS(componentName) {
|
|
69
|
+
let template = readFileContent(componentTemplateFolder + '/Component.ts')
|
|
70
|
+
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
71
|
+
return template.replaceAll('Component', componentNameCase);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getIndexTS(componentName) {
|
|
75
|
+
let template = readFileContent(componentTemplateFolder + '/index.ts')
|
|
76
|
+
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
77
|
+
return template.replaceAll('Component', componentNameCase);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
function getComponentStoriesSvelte(componentName) {
|
|
82
|
+
let template = readFileContent(componentTemplateFolder + '/Component.stories.svelte')
|
|
83
|
+
let componentNameCase = convertCase(componentName, PASCAL_CASE);
|
|
84
|
+
return template.replaceAll('ComponentName', componentNameCase)
|
|
85
|
+
.replaceAll('component-path', convertCase(componentName, KEBAB_CASE));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
// Define the component folder and files
|
|
90
|
+
const componentDir = path.join(process.cwd(), 'src', 'lib', 'components', convertCase(componentName, KEBAB_CASE));
|
|
91
|
+
const componentStoriesDir = path.join(process.cwd(), 'src', 'stories', convertCase(componentName, KEBAB_CASE));
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
const files = {
|
|
95
|
+
[`${convertCase(componentName, PASCAL_CASE)}.svelte`]: getComponentSvelte(componentName),
|
|
96
|
+
[`${convertCase(componentName, PASCAL_CASE)}.ts`]: getComponentTS(componentName),
|
|
97
|
+
[`index.ts`]: getIndexTS(componentName),
|
|
98
|
+
[`${convertCase(componentName, PASCAL_CASE)}.stories.svelte`]: getComponentStoriesSvelte(componentName),
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
// Create the folder and files with template content
|
|
103
|
+
if (!fs.existsSync(componentDir)) {
|
|
104
|
+
fs.mkdirSync(componentDir);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!fs.existsSync(componentStoriesDir)) {
|
|
108
|
+
fs.mkdirSync(componentStoriesDir);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
for (const [filename, content] of Object.entries(files)) {
|
|
113
|
+
const filePath = filename.includes('.stories.')
|
|
114
|
+
? path.join(componentStoriesDir, filename)
|
|
115
|
+
: path.join(componentDir, filename);
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
console.log(`Component ${componentName} created successfully with 3 template files!`);
|
|
@@ -1,139 +1,139 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Recursively finds all "index.ts" files in the given folder path.
|
|
8
|
-
* @param {string} folderPath - The root directory to start the search.
|
|
9
|
-
* @returns {Array} - List of objects containing `filePath` and `content` of each "index.ts" file.
|
|
10
|
-
*/
|
|
11
|
-
function findIndexFiles(folderPath) {
|
|
12
|
-
const result = [];
|
|
13
|
-
|
|
14
|
-
function searchFolder(currentPath) {
|
|
15
|
-
const filesAndDirs = fs.readdirSync(currentPath);
|
|
16
|
-
|
|
17
|
-
for (const item of filesAndDirs) {
|
|
18
|
-
const itemPath = path.join(currentPath, item);
|
|
19
|
-
const stats = fs.statSync(itemPath);
|
|
20
|
-
|
|
21
|
-
if (stats.isDirectory()) {
|
|
22
|
-
// Recursively search in subdirectories
|
|
23
|
-
searchFolder(itemPath);
|
|
24
|
-
} else if (item === "index.ts") {
|
|
25
|
-
// Read file content if the file is "index.ts"
|
|
26
|
-
const content = fs.readFileSync(itemPath, "utf-8");
|
|
27
|
-
result.push({filePath: itemPath, content});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
searchFolder(folderPath);
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Extracts export names from a given JavaScript file content.
|
|
39
|
-
* @param {string} filePath - The path to the JavaScript file.
|
|
40
|
-
* @returns {Array} - An array of export names.
|
|
41
|
-
*/
|
|
42
|
-
function extractExportNames(filePath) {
|
|
43
|
-
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
44
|
-
const exportNames = [];
|
|
45
|
-
|
|
46
|
-
// Regular expressions to match the export names
|
|
47
|
-
const defaultExportRegex = /^(?!\s*\/\/)\s*export\s*{\s*default\s+as\s+(\w+)/gm;
|
|
48
|
-
const namedExportRegex = /^(?!\s*\/\/)\s*export\s*{(\w+)\s*}/gm;
|
|
49
|
-
|
|
50
|
-
let match;
|
|
51
|
-
|
|
52
|
-
// Find all matches for `export { default as ... }`
|
|
53
|
-
while ((match = defaultExportRegex.exec(fileContent)) !== null) {
|
|
54
|
-
exportNames.push(match[1]);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Find all matches for `export { namedExport }`
|
|
58
|
-
while ((match = namedExportRegex.exec(fileContent)) !== null) {
|
|
59
|
-
exportNames.push(match[1]);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return exportNames;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Recursively finds all files in a given folder path that match the name pattern.
|
|
68
|
-
* @param {string} folderPath - The root directory to start the search.
|
|
69
|
-
* @param {RegExp} namePattern - The regular expression pattern to match file names.
|
|
70
|
-
* @returns {Array} - List of file names that match the pattern.
|
|
71
|
-
*/
|
|
72
|
-
function findFilesByPattern(folderPath, namePattern) {
|
|
73
|
-
const result = [];
|
|
74
|
-
|
|
75
|
-
console.log(folderPath)
|
|
76
|
-
function searchFolder(currentPath) {
|
|
77
|
-
const filesAndDirs = fs.readdirSync(currentPath);
|
|
78
|
-
|
|
79
|
-
for (const item of filesAndDirs) {
|
|
80
|
-
const itemPath = path.join(currentPath, item);
|
|
81
|
-
const stats = fs.statSync(itemPath);
|
|
82
|
-
|
|
83
|
-
if (stats.isDirectory()) {
|
|
84
|
-
// Recursively search in subdirectories
|
|
85
|
-
searchFolder(itemPath);
|
|
86
|
-
} else if (namePattern.test(item)) {
|
|
87
|
-
// If the file name matches the pattern, add to result
|
|
88
|
-
result.push(item);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
searchFolder(folderPath);
|
|
94
|
-
return result;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const baseLib = './src/lib'
|
|
98
|
-
const GLOBAL_INDEX_PATH = baseLib + "/index.ts"
|
|
99
|
-
const COMPONENTS_PATH = baseLib + "/components"
|
|
100
|
-
const ICON_COMPONENTS_PATH = baseLib + "/components/icons"
|
|
101
|
-
|
|
102
|
-
const iconComponentsFileList = findFilesByPattern(ICON_COMPONENTS_PATH, /^Icon\w*\.svelte$/);
|
|
103
|
-
|
|
104
|
-
// generate icon index
|
|
105
|
-
const importSvelteComponentTemplate = `export {default as Component} from './Component.svelte'`;
|
|
106
|
-
const importComponentTemplate = `export {Component} from 'path'`;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
(() => {
|
|
110
|
-
let content = ''
|
|
111
|
-
iconComponentsFileList.forEach(file => {
|
|
112
|
-
let componentName = file.replace('.svelte', '')
|
|
113
|
-
content += importSvelteComponentTemplate.replaceAll('Component', componentName);
|
|
114
|
-
content += `\n`
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
fs.writeFileSync(ICON_COMPONENTS_PATH + '/index.ts', content, 'utf8');
|
|
118
|
-
})();
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
(() => {
|
|
122
|
-
const indexFileList = findIndexFiles(COMPONENTS_PATH);
|
|
123
|
-
let content = ''
|
|
124
|
-
|
|
125
|
-
indexFileList.forEach(file => {
|
|
126
|
-
let components = extractExportNames(file.filePath)
|
|
127
|
-
if (components.length === 0) return
|
|
128
|
-
|
|
129
|
-
let importFromPath = './components/' + file.filePath.split(path.sep + `components` + path.sep)[1].replace(path.sep + 'index.ts', '');
|
|
130
|
-
|
|
131
|
-
content += importComponentTemplate.replace('path', importFromPath)
|
|
132
|
-
.replace('Component', components.join(', '));
|
|
133
|
-
content += '\n';
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
console.log(content)
|
|
137
|
-
fs.writeFileSync(GLOBAL_INDEX_PATH, content, 'utf8');
|
|
138
|
-
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Recursively finds all "index.ts" files in the given folder path.
|
|
8
|
+
* @param {string} folderPath - The root directory to start the search.
|
|
9
|
+
* @returns {Array} - List of objects containing `filePath` and `content` of each "index.ts" file.
|
|
10
|
+
*/
|
|
11
|
+
function findIndexFiles(folderPath) {
|
|
12
|
+
const result = [];
|
|
13
|
+
|
|
14
|
+
function searchFolder(currentPath) {
|
|
15
|
+
const filesAndDirs = fs.readdirSync(currentPath);
|
|
16
|
+
|
|
17
|
+
for (const item of filesAndDirs) {
|
|
18
|
+
const itemPath = path.join(currentPath, item);
|
|
19
|
+
const stats = fs.statSync(itemPath);
|
|
20
|
+
|
|
21
|
+
if (stats.isDirectory()) {
|
|
22
|
+
// Recursively search in subdirectories
|
|
23
|
+
searchFolder(itemPath);
|
|
24
|
+
} else if (item === "index.ts") {
|
|
25
|
+
// Read file content if the file is "index.ts"
|
|
26
|
+
const content = fs.readFileSync(itemPath, "utf-8");
|
|
27
|
+
result.push({filePath: itemPath, content});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
searchFolder(folderPath);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Extracts export names from a given JavaScript file content.
|
|
39
|
+
* @param {string} filePath - The path to the JavaScript file.
|
|
40
|
+
* @returns {Array} - An array of export names.
|
|
41
|
+
*/
|
|
42
|
+
function extractExportNames(filePath) {
|
|
43
|
+
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
44
|
+
const exportNames = [];
|
|
45
|
+
|
|
46
|
+
// Regular expressions to match the export names
|
|
47
|
+
const defaultExportRegex = /^(?!\s*\/\/)\s*export\s*{\s*default\s+as\s+(\w+)/gm;
|
|
48
|
+
const namedExportRegex = /^(?!\s*\/\/)\s*export\s*{(\w+)\s*}/gm;
|
|
49
|
+
|
|
50
|
+
let match;
|
|
51
|
+
|
|
52
|
+
// Find all matches for `export { default as ... }`
|
|
53
|
+
while ((match = defaultExportRegex.exec(fileContent)) !== null) {
|
|
54
|
+
exportNames.push(match[1]);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Find all matches for `export { namedExport }`
|
|
58
|
+
while ((match = namedExportRegex.exec(fileContent)) !== null) {
|
|
59
|
+
exportNames.push(match[1]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return exportNames;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Recursively finds all files in a given folder path that match the name pattern.
|
|
68
|
+
* @param {string} folderPath - The root directory to start the search.
|
|
69
|
+
* @param {RegExp} namePattern - The regular expression pattern to match file names.
|
|
70
|
+
* @returns {Array} - List of file names that match the pattern.
|
|
71
|
+
*/
|
|
72
|
+
function findFilesByPattern(folderPath, namePattern) {
|
|
73
|
+
const result = [];
|
|
74
|
+
|
|
75
|
+
console.log(folderPath)
|
|
76
|
+
function searchFolder(currentPath) {
|
|
77
|
+
const filesAndDirs = fs.readdirSync(currentPath);
|
|
78
|
+
|
|
79
|
+
for (const item of filesAndDirs) {
|
|
80
|
+
const itemPath = path.join(currentPath, item);
|
|
81
|
+
const stats = fs.statSync(itemPath);
|
|
82
|
+
|
|
83
|
+
if (stats.isDirectory()) {
|
|
84
|
+
// Recursively search in subdirectories
|
|
85
|
+
searchFolder(itemPath);
|
|
86
|
+
} else if (namePattern.test(item)) {
|
|
87
|
+
// If the file name matches the pattern, add to result
|
|
88
|
+
result.push(item);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
searchFolder(folderPath);
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const baseLib = './src/lib'
|
|
98
|
+
const GLOBAL_INDEX_PATH = baseLib + "/index.ts"
|
|
99
|
+
const COMPONENTS_PATH = baseLib + "/components"
|
|
100
|
+
const ICON_COMPONENTS_PATH = baseLib + "/components/icons"
|
|
101
|
+
|
|
102
|
+
const iconComponentsFileList = findFilesByPattern(ICON_COMPONENTS_PATH, /^Icon\w*\.svelte$/);
|
|
103
|
+
|
|
104
|
+
// generate icon index
|
|
105
|
+
const importSvelteComponentTemplate = `export {default as Component} from './Component.svelte'`;
|
|
106
|
+
const importComponentTemplate = `export {Component} from 'path'`;
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
(() => {
|
|
110
|
+
let content = ''
|
|
111
|
+
iconComponentsFileList.forEach(file => {
|
|
112
|
+
let componentName = file.replace('.svelte', '')
|
|
113
|
+
content += importSvelteComponentTemplate.replaceAll('Component', componentName);
|
|
114
|
+
content += `\n`
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
fs.writeFileSync(ICON_COMPONENTS_PATH + '/index.ts', content, 'utf8');
|
|
118
|
+
})();
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
(() => {
|
|
122
|
+
const indexFileList = findIndexFiles(COMPONENTS_PATH);
|
|
123
|
+
let content = ''
|
|
124
|
+
|
|
125
|
+
indexFileList.forEach(file => {
|
|
126
|
+
let components = extractExportNames(file.filePath)
|
|
127
|
+
if (components.length === 0) return
|
|
128
|
+
|
|
129
|
+
let importFromPath = './components/' + file.filePath.split(path.sep + `components` + path.sep)[1].replace(path.sep + 'index.ts', '');
|
|
130
|
+
|
|
131
|
+
content += importComponentTemplate.replace('path', importFromPath)
|
|
132
|
+
.replace('Component', components.join(', '));
|
|
133
|
+
content += '\n';
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
console.log(content)
|
|
137
|
+
fs.writeFileSync(GLOBAL_INDEX_PATH, content, 'utf8');
|
|
138
|
+
|
|
139
139
|
})()
|