Skip to content

Commit da6f4f9

Browse files
committed
Fix date and sorting by adding it to test app
1 parent 68d5ada commit da6f4f9

File tree

9 files changed

+395
-316
lines changed

9 files changed

+395
-316
lines changed

bin/create_theme.mjs

+29-16
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ const carbonDir = path.resolve(themesDir + '/svelte/carbon');
1717
// main
1818
//
1919
(async () => {
20-
let themeType = ((process.argv[2] || '').trim() || await ask('Theme type? (svelte, react, vue)')).toLowerCase();
21-
let themeName = ((process.argv[3] || '').trim() || await ask('What is the name of your new theme? (only lowercase letters and underscores)')).toLowerCase();
20+
let themeType = (
21+
(process.argv[2] || '').trim() || (await ask('Theme type? (svelte, react, vue)'))
22+
).toLowerCase();
23+
let themeName = (
24+
(process.argv[3] || '').trim() ||
25+
(await ask('What is the name of your new theme? (only lowercase letters and underscores)'))
26+
).toLowerCase();
2227

2328
if (!themeName) {
2429
throw new Error('No theme name provided.');
@@ -31,29 +36,37 @@ const carbonDir = path.resolve(themesDir + '/svelte/carbon');
3136
throw new Error('Wrong template type provided. Allowed: svelte, react, vue');
3237
}
3338

34-
const newThemePath = carbonDir.replace(/\\/g, '/').replace(/\/svelte\/carbon$/g, `/${themeType}/${themeName}`).replace(/\//g, path.sep);
39+
const newThemePath = carbonDir
40+
.replace(/\\/g, '/')
41+
.replace(/\/svelte\/carbon$/g, `/${themeType}/${themeName}`)
42+
.replace(/\//g, path.sep);
3543

36-
const files = (await getAllFiles(carbonDir));
44+
const files = await getAllFiles(carbonDir);
3745

3846
for (const file of files) {
3947
if (!file.match(/\.svelte$/gi)) {
4048
continue;
4149
}
4250
const newPath = path.resolve(file.replace(carbonDir, newThemePath));
43-
const basename = newPath.replace(projectDir + path.sep, '').replace(new RegExp('\\\\', 'g'), '/');
51+
const basename = newPath
52+
.replace(projectDir + path.sep, '')
53+
.replace(new RegExp('\\\\', 'g'), '/');
4454
const dir = path.dirname(newPath);
45-
await fs.mkdir(dir, {recursive: true});
46-
await fs.writeFile(newPath, `TODO: Implement template "${basename}" for "${themeType}/${themeName}" theme.\n`);
55+
await fs.mkdir(dir, { recursive: true });
56+
await fs.writeFile(
57+
newPath,
58+
`TODO: Implement template "${basename}" for "${themeType}/${themeName}" theme.\n`
59+
);
4760
}
4861

49-
await fs.copyFile(carbonDir+'/index.ts', newThemePath+'/index.ts');
62+
await fs.copyFile(carbonDir + '/index.ts', newThemePath + '/index.ts');
5063

51-
const themesIndex = themesDir+'/'+themeType+'/index.ts';
64+
const themesIndex = themesDir + '/' + themeType + '/index.ts';
5265
let indexContent = (await fs.readFile(themesIndex)).toString();
5366
if (!indexContent.match(new RegExp(`export *\\{ *default as ${themeName}`), 'gi')) {
54-
indexContent += `\nexport { default as ${themeName} } from './${themeName}';`
67+
indexContent += `\nexport { default as ${themeName} } from './${themeName}';`;
5568
}
56-
indexContent = indexContent.replace(/\n\n+/, "\n").trim()+"\n";
69+
indexContent = indexContent.replace(/\n\n+/, '\n').trim() + '\n';
5770
await fs.writeFile(themesIndex, indexContent);
5871
})();
5972

@@ -83,18 +96,18 @@ async function ask(question) {
8396
}
8497

8598
async function getAllFiles(dirPath, arrayOfFiles = []) {
86-
const files = await fs.readdir(dirPath)
99+
const files = await fs.readdir(dirPath);
87100

88-
arrayOfFiles = arrayOfFiles || []
101+
arrayOfFiles = arrayOfFiles || [];
89102

90103
for (const file of files) {
91104
const stat = await fs.stat(dirPath + path.sep + file);
92105
if (stat.isDirectory()) {
93-
arrayOfFiles = await getAllFiles(dirPath + path.sep + file, arrayOfFiles)
106+
arrayOfFiles = await getAllFiles(dirPath + path.sep + file, arrayOfFiles);
94107
} else {
95-
arrayOfFiles.push(path.join(dirPath, path.sep, file))
108+
arrayOfFiles.push(path.join(dirPath, path.sep, file));
96109
}
97110
}
98111

99-
return arrayOfFiles
112+
return arrayOfFiles;
100113
}

0 commit comments

Comments
 (0)