@timus-networks/theme 1.0.1
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/README.md +90 -0
- package/components-js/exporter.js +19 -0
- package/components-js/interfaces.ts +11 -0
- package/components-js/utils.ts +20 -0
- package/components-ts/exporter.js +19 -0
- package/components-ts/interfaces.ts +11 -0
- package/components-ts/utils.ts +20 -0
- package/convert.js +98 -0
- package/index.d.ts +0 -0
- package/js-converter.js +90 -0
- package/loader.js +41 -0
- package/module.js +62 -0
- package/package.json +38 -0
- package/plugins/js-components-installer.js +21 -0
- package/plugins/theme-provider.ts +75 -0
- package/plugins/ts-components-installer.js +21 -0
- package/scss/_buttons.scss +160 -0
- package/scss/_colors.scss +159 -0
- package/scss/_containers.scss +7 -0
- package/scss/_element-ui.scss +14 -0
- package/scss/_fonts.scss +69 -0
- package/scss/_icons.scss +87 -0
- package/scss/_inputs.scss +39 -0
- package/scss/_layers.scss +9 -0
- package/scss/_selectbox.scss +4 -0
- package/scss/_variables.scss +16 -0
- package/scss/element-ui/alert.scss +147 -0
- package/scss/element-ui/aside.scss +7 -0
- package/scss/element-ui/autocomplete.scss +80 -0
- package/scss/element-ui/avatar.scss +51 -0
- package/scss/element-ui/backtop.scss +22 -0
- package/scss/element-ui/badge.scss +58 -0
- package/scss/element-ui/base.scss +2 -0
- package/scss/element-ui/breadcrumb-item.scss +0 -0
- package/scss/element-ui/breadcrumb.scss +55 -0
- package/scss/element-ui/button-group.scss +0 -0
- package/scss/element-ui/button.scss +275 -0
- package/scss/element-ui/calendar.scss +79 -0
- package/scss/element-ui/card.scss +32 -0
- package/scss/element-ui/carousel-item.scss +50 -0
- package/scss/element-ui/carousel.scss +162 -0
- package/scss/element-ui/cascader-panel.scss +120 -0
- package/scss/element-ui/cascader.scss +182 -0
- package/scss/element-ui/checkbox-button.scss +0 -0
- package/scss/element-ui/checkbox-group.scss +0 -0
- package/scss/element-ui/checkbox.scss +359 -0
- package/scss/element-ui/col.scss +157 -0
- package/scss/element-ui/collapse-item.scss +0 -0
- package/scss/element-ui/collapse.scss +63 -0
- package/scss/element-ui/color-picker.scss +384 -0
- package/scss/element-ui/common/popup.scss +42 -0
- package/scss/element-ui/common/transition.scss +99 -0
- package/scss/element-ui/common/var.scss +1029 -0
- package/scss/element-ui/container.scss +14 -0
- package/scss/element-ui/date-picker/date-picker.scss +97 -0
- package/scss/element-ui/date-picker/date-range-picker.scss +101 -0
- package/scss/element-ui/date-picker/date-table.scss +151 -0
- package/scss/element-ui/date-picker/month-table.scss +82 -0
- package/scss/element-ui/date-picker/picker-panel.scss +117 -0
- package/scss/element-ui/date-picker/picker.scss +197 -0
- package/scss/element-ui/date-picker/time-picker.scss +85 -0
- package/scss/element-ui/date-picker/time-range-picker.scss +31 -0
- package/scss/element-ui/date-picker/time-spinner.scss +110 -0
- package/scss/element-ui/date-picker/year-table.scss +51 -0
- package/scss/element-ui/date-picker.scss +12 -0
- package/scss/element-ui/descriptions-item.scss +42 -0
- package/scss/element-ui/descriptions.scss +111 -0
- package/scss/element-ui/dialog.scss +123 -0
- package/scss/element-ui/display.scss +12 -0
- package/scss/element-ui/divider.scss +47 -0
- package/scss/element-ui/drawer.scss +219 -0
- package/scss/element-ui/dropdown-item.scss +0 -0
- package/scss/element-ui/dropdown-menu.scss +0 -0
- package/scss/element-ui/dropdown.scss +182 -0
- package/scss/element-ui/empty.scss +45 -0
- package/scss/element-ui/fonts/element-icons.ttf +0 -0
- package/scss/element-ui/fonts/element-icons.woff +0 -0
- package/scss/element-ui/footer.scss +8 -0
- package/scss/element-ui/form-item.scss +0 -0
- package/scss/element-ui/form.scss +167 -0
- package/scss/element-ui/header.scss +8 -0
- package/scss/element-ui/icon.scss +1167 -0
- package/scss/element-ui/image.scss +179 -0
- package/scss/element-ui/index.scss +87 -0
- package/scss/element-ui/infinite-scroll.scss +0 -0
- package/scss/element-ui/infiniteScroll.scss +0 -0
- package/scss/element-ui/input-number.scss +181 -0
- package/scss/element-ui/input.scss +360 -0
- package/scss/element-ui/link.scss +81 -0
- package/scss/element-ui/loading.scss +97 -0
- package/scss/element-ui/main.scss +12 -0
- package/scss/element-ui/menu-item-group.scss +0 -0
- package/scss/element-ui/menu-item.scss +0 -0
- package/scss/element-ui/menu.scss +289 -0
- package/scss/element-ui/message-box.scss +226 -0
- package/scss/element-ui/message.scss +120 -0
- package/scss/element-ui/mixins/_button.scss +81 -0
- package/scss/element-ui/mixins/config.scss +4 -0
- package/scss/element-ui/mixins/function.scss +44 -0
- package/scss/element-ui/mixins/mixins.scss +190 -0
- package/scss/element-ui/mixins/utils.scss +39 -0
- package/scss/element-ui/notification.scss +99 -0
- package/scss/element-ui/option-group.scss +42 -0
- package/scss/element-ui/option.scss +36 -0
- package/scss/element-ui/page-header.scss +41 -0
- package/scss/element-ui/pagination.scss +295 -0
- package/scss/element-ui/popconfirm.scss +16 -0
- package/scss/element-ui/popover.scss +40 -0
- package/scss/element-ui/popper.scss +102 -0
- package/scss/element-ui/progress.scss +141 -0
- package/scss/element-ui/radio-button.scss +113 -0
- package/scss/element-ui/radio-group.scss +9 -0
- package/scss/element-ui/radio.scss +199 -0
- package/scss/element-ui/rate.scss +49 -0
- package/scss/element-ui/reset.scss +79 -0
- package/scss/element-ui/result.scss +61 -0
- package/scss/element-ui/row.scss +43 -0
- package/scss/element-ui/scrollbar.scss +72 -0
- package/scss/element-ui/select-dropdown.scss +62 -0
- package/scss/element-ui/select.scss +152 -0
- package/scss/element-ui/skeleton-item.scss +84 -0
- package/scss/element-ui/skeleton.scss +40 -0
- package/scss/element-ui/slider.scss +250 -0
- package/scss/element-ui/spinner.scss +44 -0
- package/scss/element-ui/statistic.scss +38 -0
- package/scss/element-ui/step.scss +317 -0
- package/scss/element-ui/steps.scss +20 -0
- package/scss/element-ui/submenu.scss +0 -0
- package/scss/element-ui/switch.scss +116 -0
- package/scss/element-ui/tab-pane.scss +0 -0
- package/scss/element-ui/table-column.scss +97 -0
- package/scss/element-ui/table.scss +564 -0
- package/scss/element-ui/tabs.scss +602 -0
- package/scss/element-ui/tag.scss +163 -0
- package/scss/element-ui/time-picker.scss +8 -0
- package/scss/element-ui/time-select.scss +37 -0
- package/scss/element-ui/timeline-item.scss +86 -0
- package/scss/element-ui/timeline.scss +14 -0
- package/scss/element-ui/tooltip.scss +141 -0
- package/scss/element-ui/transfer.scss +228 -0
- package/scss/element-ui/tree.scss +123 -0
- package/scss/element-ui/upload.scss +603 -0
- package/scss/main.scss +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
## Installation:
|
|
2
|
+
|
|
3
|
+
1. First install package `npm i @timus-networks/theme`
|
|
4
|
+
2. Add package to `modules` property in `nuxt.config.js` file
|
|
5
|
+
|
|
6
|
+
```json
|
|
7
|
+
{
|
|
8
|
+
"modules": ["@nuxtjs/axios", ["@timus-networks/filter", { "client": false, "typescript": false }]]
|
|
9
|
+
}
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
- You can manually set the `client` and `typescript` support properties.
|
|
13
|
+
- If you render this component on the client side, set the value to `true`.
|
|
14
|
+
- If you prefer to use `typescript` during development, set `typescript` to `true`.
|
|
15
|
+
- You can also set the `namespace` to define the module path's position within the .nuxt folder.
|
|
16
|
+
|
|
17
|
+
3. Add below configuration to your **nuxt.config.js** file.
|
|
18
|
+
|
|
19
|
+
<sub>nuxt.config.js</sub>
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
tailwindcss: {
|
|
23
|
+
// cssPath: '~/static/scss/main.scss',
|
|
24
|
+
configPath: '@/tailwind.config.js',
|
|
25
|
+
exposeConfig: false,
|
|
26
|
+
exposeLevel: 2,
|
|
27
|
+
config: {
|
|
28
|
+
darkMode: 'class',
|
|
29
|
+
},
|
|
30
|
+
injectPosition: 'first',
|
|
31
|
+
viewer: true,
|
|
32
|
+
},
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Usage
|
|
36
|
+
|
|
37
|
+
Default dark theme is `false`
|
|
38
|
+
|
|
39
|
+
- Change the theme on button click:
|
|
40
|
+
`this.$theme.setDarkMode(!this.$theme.isDark);`
|
|
41
|
+
|
|
42
|
+
- Register the theme change listener:
|
|
43
|
+
`this.$theme.$on('darkMode', (value) => { console.log('darkMode:', value); });`
|
|
44
|
+
|
|
45
|
+
<sub>SamplePage.vue</sub>
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
<template>
|
|
49
|
+
<div class="text-black dark:text-white dark:bg-gray-800 p-4">
|
|
50
|
+
<h1>Dynamic Theming with Nuxt</h1>
|
|
51
|
+
<p>Experience the power of dynamic theming. Click the button below to toggle between light and dark modes.</p>
|
|
52
|
+
<button @click="toggleTheme" class="btn btn-sm btn-primary dark:btn-light mt-4">{{ buttonText }}</button>
|
|
53
|
+
<div class="indicator">
|
|
54
|
+
Current Theme: <strong>{{ $theme.isDark ? 'Dark' : 'Light' }}</strong>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</template>
|
|
58
|
+
<script lang="ts">
|
|
59
|
+
import Vue from 'vue';
|
|
60
|
+
|
|
61
|
+
export default Vue.extend({
|
|
62
|
+
computed: {
|
|
63
|
+
buttonText(): string {
|
|
64
|
+
return this.$theme.isDark ? 'Switch to Light Mode' : 'Switch to Dark Mode';
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
methods: {
|
|
68
|
+
toggleTheme() {
|
|
69
|
+
this.$theme.setDarkMode(!this.$theme.isDark);
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
mounted() {
|
|
73
|
+
console.log('Dark mode is:', this.$theme.isDark);
|
|
74
|
+
this.$theme.$on('darkMode', (value: boolean) => {
|
|
75
|
+
console.log('darkMode changed:', value);
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<style scoped>
|
|
82
|
+
.toggle-button {
|
|
83
|
+
transition: background-color 0.3s ease;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.indicator {
|
|
87
|
+
margin-top: 20px;
|
|
88
|
+
}
|
|
89
|
+
</style>
|
|
90
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const components = {};
|
|
2
|
+
const requireComponent = require.context(
|
|
3
|
+
'.', // bu klasördeki bileşenleri oku
|
|
4
|
+
false, // alt klasörleri okuma
|
|
5
|
+
/[A-Z]\w+\.(vue)$/, // Vue bileşenlerini al
|
|
6
|
+
// EXPERIMENTAL: /[A-Z]\w+\.(vue|js)$/, // Vue bileşenlerini veya JS dosyalarını al
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
requireComponent.keys().forEach((fileName) => {
|
|
10
|
+
const componentConfig = requireComponent(fileName);
|
|
11
|
+
const componentName = fileName
|
|
12
|
+
.split('/')
|
|
13
|
+
.pop()
|
|
14
|
+
.replace(/\.\w+$/, ''); // Dosya adını bileşen adı olarak al
|
|
15
|
+
|
|
16
|
+
components[componentName] = componentConfig.default || componentConfig;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export default components;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class Utils {
|
|
2
|
+
private timeout: ReturnType<typeof setTimeout> | null = null;
|
|
3
|
+
|
|
4
|
+
debounce(func: Function, delay: number) {
|
|
5
|
+
return (...args: any[]) => {
|
|
6
|
+
if (this.timeout !== null) {
|
|
7
|
+
clearTimeout(this.timeout);
|
|
8
|
+
}
|
|
9
|
+
this.timeout = setTimeout(() => {
|
|
10
|
+
func(...args);
|
|
11
|
+
}, delay);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
generateRandomId(): string {
|
|
16
|
+
return Date.now().toString(36) + Math.random().toString(36).slice(2, 9);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const utils = new Utils();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const components = {};
|
|
2
|
+
const requireComponent = require.context(
|
|
3
|
+
'.', // bu klasördeki bileşenleri oku
|
|
4
|
+
false, // alt klasörleri okuma
|
|
5
|
+
/[A-Z]\w+\.(vue)$/, // Vue bileşenlerini al
|
|
6
|
+
// EXPERIMENTAL: /[A-Z]\w+\.(vue|js)$/, // Vue bileşenlerini veya JS dosyalarını al
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
requireComponent.keys().forEach((fileName) => {
|
|
10
|
+
const componentConfig = requireComponent(fileName);
|
|
11
|
+
const componentName = fileName
|
|
12
|
+
.split('/')
|
|
13
|
+
.pop()
|
|
14
|
+
.replace(/\.\w+$/, ''); // Dosya adını bileşen adı olarak al
|
|
15
|
+
|
|
16
|
+
components[componentName] = componentConfig.default || componentConfig;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export default components;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class Utils {
|
|
2
|
+
private timeout: ReturnType<typeof setTimeout> | null = null;
|
|
3
|
+
|
|
4
|
+
debounce(func: Function, delay: number) {
|
|
5
|
+
return (...args: any[]) => {
|
|
6
|
+
if (this.timeout !== null) {
|
|
7
|
+
clearTimeout(this.timeout);
|
|
8
|
+
}
|
|
9
|
+
this.timeout = setTimeout(() => {
|
|
10
|
+
func(...args);
|
|
11
|
+
}, delay);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
generateRandomId(): string {
|
|
16
|
+
return Date.now().toString(36) + Math.random().toString(36).slice(2, 9);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const utils = new Utils();
|
package/convert.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const execSync = require('child_process').execSync;
|
|
4
|
+
const glob = require('glob');
|
|
5
|
+
|
|
6
|
+
// Eğer 'components-js' klasörü varsa sil
|
|
7
|
+
if (fs.existsSync('components-js')) {
|
|
8
|
+
fs.rmSync('components-js', { recursive: true, force: true });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Yeni bir 'components-js' klasörü oluştur
|
|
12
|
+
fs.mkdirSync('components-js');
|
|
13
|
+
|
|
14
|
+
// components'in içerisindeki her şeyi output'a kopyala
|
|
15
|
+
const copyRecursiveSync = function (src, dest) {
|
|
16
|
+
const exists = fs.existsSync(src);
|
|
17
|
+
const stats = exists && fs.statSync(src);
|
|
18
|
+
const isDirectory = exists && stats.isDirectory();
|
|
19
|
+
if (exists && isDirectory) {
|
|
20
|
+
if (!fs.existsSync(dest)) fs.mkdirSync(dest);
|
|
21
|
+
fs.readdirSync(src).forEach((childItemName) => {
|
|
22
|
+
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
fs.copyFileSync(src, dest);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
copyRecursiveSync('./components-ts', './components-js');
|
|
30
|
+
|
|
31
|
+
// output klasöründeki .vue dosyalarını bul
|
|
32
|
+
const vueFiles = glob.sync('./components-js/**/*.{vue,ts}');
|
|
33
|
+
|
|
34
|
+
vueFiles.forEach((file) => {
|
|
35
|
+
const content = fs.readFileSync(file, 'utf-8');
|
|
36
|
+
const scriptMatch = content.match(/<script lang="ts">(.*?)<\/script>/s);
|
|
37
|
+
let tsFilePath;
|
|
38
|
+
|
|
39
|
+
if (content) {
|
|
40
|
+
if (scriptMatch) {
|
|
41
|
+
console.log('###', scriptMatch);
|
|
42
|
+
let tsCode = scriptMatch[1];
|
|
43
|
+
tsCode = tsCode.replace(/import .*?from '.*?.vue';/g, (match) => `// ${match}`);
|
|
44
|
+
|
|
45
|
+
tsFilePath = file.replace('.vue', '.temp.ts');
|
|
46
|
+
fs.writeFileSync(tsFilePath, tsCode, 'utf-8');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let hasError = false;
|
|
50
|
+
const tscPath = path.resolve(__dirname, '../../../node_modules/.bin/tsc');
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
execSync(`${tscPath} ${scriptMatch ? tsFilePath : file} --allowJs false --module esnext --target esnext --declaration true`, {
|
|
54
|
+
encoding: 'utf8',
|
|
55
|
+
});
|
|
56
|
+
} catch (e) {
|
|
57
|
+
// console.error("### Derleme hatası:", tsFilePath, e);
|
|
58
|
+
// console.error('DERLEME HATASI: ', e.stdout.toString());
|
|
59
|
+
hasError = true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (tsFilePath && hasError ) {
|
|
63
|
+
// temp.d.ts dosyasını yeniden oluştur ve adını
|
|
64
|
+
const tsOutputFilePath = tsFilePath.replace('.temp.ts', '.temp.d.ts');
|
|
65
|
+
const desiredOutputFilePath = tsFilePath.replace('.temp.ts', '.d.ts');
|
|
66
|
+
if (fs.existsSync(tsOutputFilePath)) {
|
|
67
|
+
fs.renameSync(tsOutputFilePath, desiredOutputFilePath);
|
|
68
|
+
}
|
|
69
|
+
const jsCode = fs.readFileSync(tsFilePath.replace('.ts', '.js'), 'utf-8');
|
|
70
|
+
const finalJsCode = jsCode.replace(/\/\/ import/g, 'import');
|
|
71
|
+
const newContent = content.replace(/<script lang="ts">(.*?)<\/script>/s, `<script>${finalJsCode}</script>`);
|
|
72
|
+
fs.writeFileSync(file, newContent, 'utf-8');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (scriptMatch) {
|
|
76
|
+
// Dosyaları sil
|
|
77
|
+
if (fs.existsSync(tsFilePath)) fs.unlinkSync(tsFilePath);
|
|
78
|
+
if (fs.existsSync(tsFilePath.replace('.ts', '.js'))) fs.unlinkSync(tsFilePath.replace('.ts', '.js'));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// vueFiles.forEach döngüsünden sonra
|
|
84
|
+
const declarationFiles = glob.sync('./components-js/**/*.d.ts');
|
|
85
|
+
|
|
86
|
+
// Bu dosyaları import eden bir index.d.ts oluştur
|
|
87
|
+
let imports = declarationFiles
|
|
88
|
+
.map((file) => {
|
|
89
|
+
// Dosya yolundan modül adını elde etmek için gereken işlemler
|
|
90
|
+
let modulePath = path.relative('.', file);
|
|
91
|
+
modulePath = modulePath.replace('.d.ts', '');
|
|
92
|
+
modulePath = modulePath.replace(/\\/g, '/'); // Windows için ters eğik çizgileri düzelt
|
|
93
|
+
return `export * from './${modulePath}';`;
|
|
94
|
+
})
|
|
95
|
+
.join('\n');
|
|
96
|
+
|
|
97
|
+
fs.writeFileSync('./index.d.ts', imports);
|
|
98
|
+
console.log('### index.d.ts dosyası oluşturuldu.');
|
package/index.d.ts
ADDED
|
File without changes
|
package/js-converter.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const execSync = require('child_process').execSync;
|
|
4
|
+
const glob = require('glob');
|
|
5
|
+
|
|
6
|
+
// Eğer 'components-js' klasörü varsa sil
|
|
7
|
+
if (fs.existsSync('components-js')) {
|
|
8
|
+
fs.rmSync('components-js', { recursive: true, force: true });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Yeni bir 'components-js' klasörü oluştur
|
|
12
|
+
fs.mkdirSync('components-js');
|
|
13
|
+
|
|
14
|
+
// components'in içerisindeki her şeyi output'a kopyala
|
|
15
|
+
const copyRecursiveSync = function (src, dest) {
|
|
16
|
+
const exists = fs.existsSync(src);
|
|
17
|
+
const stats = exists && fs.statSync(src);
|
|
18
|
+
const isDirectory = exists && stats.isDirectory();
|
|
19
|
+
if (exists && isDirectory) {
|
|
20
|
+
if (!fs.existsSync(dest)) fs.mkdirSync(dest);
|
|
21
|
+
fs.readdirSync(src).forEach((childItemName) => {
|
|
22
|
+
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
fs.copyFileSync(src, dest);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
copyRecursiveSync('./components-ts', './components-js');
|
|
30
|
+
|
|
31
|
+
// output klasöründeki .vue dosyalarını bul
|
|
32
|
+
const vueFiles = glob.sync('./components-js/**/*.vue');
|
|
33
|
+
|
|
34
|
+
vueFiles.forEach((file) => {
|
|
35
|
+
const content = fs.readFileSync(file, 'utf-8');
|
|
36
|
+
const scriptMatch = content.match(/<script lang="ts">(.*?)<\/script>/s);
|
|
37
|
+
|
|
38
|
+
if (scriptMatch) {
|
|
39
|
+
let tsCode = scriptMatch[1];
|
|
40
|
+
tsCode = tsCode.replace(/import .*?from '.*?.vue';/g, (match) => `// ${match}`);
|
|
41
|
+
|
|
42
|
+
const tsFilePath = file.replace('.vue', '.temp.ts');
|
|
43
|
+
fs.writeFileSync(tsFilePath, tsCode, 'utf-8');
|
|
44
|
+
|
|
45
|
+
let hasError = false;
|
|
46
|
+
const tscPath = path.resolve(__dirname, '../../../node_modules/.bin/tsc');
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
execSync(`${tscPath} ${tsFilePath} --allowJs false --module esnext --target esnext --declaration true`, { encoding: 'utf8' });
|
|
50
|
+
} catch (e) {
|
|
51
|
+
// console.error("### Derleme hatası:", tsFilePath, e);
|
|
52
|
+
// console.error('DERLEME HATASI: ', e.stdout.toString());
|
|
53
|
+
hasError = true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (hasError) {
|
|
57
|
+
// temp.d.ts dosyasını yeniden oluştur ve adını
|
|
58
|
+
const tsOutputFilePath = tsFilePath.replace('.temp.ts', '.temp.d.ts');
|
|
59
|
+
const desiredOutputFilePath = tsFilePath.replace('.temp.ts', '.d.ts');
|
|
60
|
+
if (fs.existsSync(tsOutputFilePath)) {
|
|
61
|
+
fs.renameSync(tsOutputFilePath, desiredOutputFilePath);
|
|
62
|
+
}
|
|
63
|
+
const jsCode = fs.readFileSync(tsFilePath.replace('.ts', '.js'), 'utf-8');
|
|
64
|
+
const finalJsCode = jsCode.replace(/\/\/ import/g, 'import');
|
|
65
|
+
const newContent = content.replace(/<script lang="ts">(.*?)<\/script>/s, `<script>${finalJsCode}</script>`);
|
|
66
|
+
fs.writeFileSync(file, newContent, 'utf-8');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Dosyaları sil
|
|
70
|
+
if (fs.existsSync(tsFilePath)) fs.unlinkSync(tsFilePath);
|
|
71
|
+
if (fs.existsSync(tsFilePath.replace('.ts', '.js'))) fs.unlinkSync(tsFilePath.replace('.ts', '.js'));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// vueFiles.forEach döngüsünden sonra
|
|
76
|
+
const declarationFiles = glob.sync('./components-js/**/*.d.ts');
|
|
77
|
+
|
|
78
|
+
// Bu dosyaları import eden bir index.d.ts oluştur
|
|
79
|
+
let imports = declarationFiles
|
|
80
|
+
.map((file) => {
|
|
81
|
+
// Dosya yolundan modül adını elde etmek için gereken işlemler
|
|
82
|
+
let modulePath = path.relative('.', file);
|
|
83
|
+
modulePath = modulePath.replace('.d.ts', '');
|
|
84
|
+
modulePath = modulePath.replace(/\\/g, '/'); // Windows için ters eğik çizgileri düzelt
|
|
85
|
+
return `export * from './${modulePath}';`;
|
|
86
|
+
})
|
|
87
|
+
.join('\n');
|
|
88
|
+
|
|
89
|
+
fs.writeFileSync('./index.d.ts', imports);
|
|
90
|
+
console.log("### index.d.ts dosyası oluşturuldu.");
|
package/loader.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readdirSync } from 'fs';
|
|
2
|
+
import { join, resolve } from 'path';
|
|
3
|
+
|
|
4
|
+
export function LoadComponent(options) {
|
|
5
|
+
|
|
6
|
+
const foldersToSync = [options.typescript ? 'components-ts' : 'components-js'];
|
|
7
|
+
|
|
8
|
+
// const tsIndexFile = resolve(__dirname, './'); // bu index.ts dosyasını .nuxt/timus-networks/table adresine kopyalar
|
|
9
|
+
// this.addTemplate({
|
|
10
|
+
// src: resolve(tsIndexFile, 'index.ts'),
|
|
11
|
+
// fileName: join(options.namespace, './', 'index.ts'),
|
|
12
|
+
// options,
|
|
13
|
+
// });
|
|
14
|
+
|
|
15
|
+
for (const pathString of foldersToSync) {
|
|
16
|
+
const path = resolve(__dirname, pathString);
|
|
17
|
+
for (const file of readdirSync(path)) {
|
|
18
|
+
// console.log('#### loading:', `.nuxt/${ options.namespace }/${ pathString }/${ file}` );
|
|
19
|
+
this.addTemplate({
|
|
20
|
+
src: resolve(path, file),
|
|
21
|
+
fileName: join(options.namespace, pathString, file),
|
|
22
|
+
options,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function LoadPlugins(options, all) {
|
|
29
|
+
const pluginsToSync = ['plugins/theme-provider.ts', options.typescript ? 'plugins/ts-components-installer.js' : 'plugins/js-components-installer.js'];
|
|
30
|
+
|
|
31
|
+
for (const pathString of pluginsToSync) {
|
|
32
|
+
const str = pathString.replace(/(\.[^\.]+)$/, `.${options.server}$1`);
|
|
33
|
+
|
|
34
|
+
this.addPlugin({
|
|
35
|
+
src: resolve(__dirname, pathString),
|
|
36
|
+
fileName: join(options.namespace, pathString),
|
|
37
|
+
options,
|
|
38
|
+
...(options.client && {mode: 'client'})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
package/module.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { resolve, join } from 'path';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import { LoadComponent, LoadPlugins } from './loader';
|
|
4
|
+
import PackageJson from './package.json';
|
|
5
|
+
|
|
6
|
+
async function copyDirectory(src, dest) {
|
|
7
|
+
await fs.mkdir(dest, { recursive: true });
|
|
8
|
+
const entries = await fs.readdir(src, { withFileTypes: true });
|
|
9
|
+
|
|
10
|
+
for (const entry of entries) {
|
|
11
|
+
const srcPath = join(src, entry.name);
|
|
12
|
+
const destPath = join(dest, entry.name);
|
|
13
|
+
|
|
14
|
+
if (entry.isDirectory()) {
|
|
15
|
+
await copyDirectory(srcPath, destPath);
|
|
16
|
+
} else {
|
|
17
|
+
await fs.copyFile(srcPath, destPath);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default function (moduleOptions) {
|
|
23
|
+
this.nuxt.hook('ready', (_nuxt) => {
|
|
24
|
+
this.options.tailwindcss.config.darkMode = 'class';
|
|
25
|
+
console.log(`#### ${PackageJson.name} has been prepared with version: ${PackageJson.version}`);
|
|
26
|
+
console.log(this.options.tailwindcss)
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
this.nuxt.hook('build:before', async () => {
|
|
30
|
+
const sourceDir = resolve(__dirname, './scss/');
|
|
31
|
+
const destDir = resolve(this.options.srcDir, 'static/scss/');
|
|
32
|
+
await copyDirectory(sourceDir, destDir);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Assest'si, static fonts altına iconsax olarak gönderiyorum ve nuxt.config'in css'ine ekliyorum
|
|
36
|
+
// this.options.css.push('@/static/scss/_element-ui.scss');
|
|
37
|
+
this.options.css.push('@/static/scss/main.scss');
|
|
38
|
+
|
|
39
|
+
// get all options for the module
|
|
40
|
+
const options = {
|
|
41
|
+
...moduleOptions,
|
|
42
|
+
...this.options[PackageJson.name], // bu external olarak nuxt.config içerisinde tanımlanan değer '@timus-networks/table' olarak direk json'daki
|
|
43
|
+
version: PackageJson.version,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
options.namespace = !options.namespace ? 'timus-networks/' + PackageJson.name.split('/')[1] : options.namespace;
|
|
47
|
+
options.typescript = !!options.typescript;
|
|
48
|
+
options.client = options.client === true;
|
|
49
|
+
|
|
50
|
+
LoadPlugins.bind(this)(options, this.options);
|
|
51
|
+
LoadComponent.bind(this)(options);
|
|
52
|
+
|
|
53
|
+
// Componenti global olarak ekleyin
|
|
54
|
+
// this.addTemplate({
|
|
55
|
+
// src: path.resolve(__dirname, 'components/TableCreate.vue'),
|
|
56
|
+
// fileName: 'components/TableCreate.vue'
|
|
57
|
+
// });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// REQUIRED if publishing the module as npm package
|
|
61
|
+
module.exports.meta = require('./package.json');
|
|
62
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@timus-networks/theme",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A comprehensive Nuxt.js module providing a tailored theme experience with integrated TailwindCSS support for applications.",
|
|
5
|
+
"main": "module.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"convert": "node js-converter.js",
|
|
10
|
+
"pub": "npm run convert && npm publish --access public"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/serkon/ts-nuxt.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"nuxt",
|
|
18
|
+
"module",
|
|
19
|
+
"component",
|
|
20
|
+
"vuejs",
|
|
21
|
+
"theme",
|
|
22
|
+
"tailwind"
|
|
23
|
+
],
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"vue": "^2.x"
|
|
26
|
+
},
|
|
27
|
+
"author": "Serkan Konakcı<serkan.konakci@gmail.com>",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"sass": "*",
|
|
31
|
+
"sass-loader": "*",
|
|
32
|
+
"tailwindcss": "*"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"glob": "*"
|
|
36
|
+
},
|
|
37
|
+
"typings": "./index.d.ts"
|
|
38
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Vue from 'vue';
|
|
2
|
+
|
|
3
|
+
// get options passed from module.js
|
|
4
|
+
const options = JSON.parse(`<%= JSON.stringify(options) %>`);
|
|
5
|
+
|
|
6
|
+
import components from '../components-js/exporter';
|
|
7
|
+
|
|
8
|
+
// loop through components and register them
|
|
9
|
+
for (const name in components) {
|
|
10
|
+
Vue.component(name, {
|
|
11
|
+
// extend the original component
|
|
12
|
+
extends: components[name],
|
|
13
|
+
// add a _customCounterOptions prop to gain access to the options in the component
|
|
14
|
+
props: {
|
|
15
|
+
timus: {
|
|
16
|
+
type: Object,
|
|
17
|
+
default: () => ({ ...options }),
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Context } from '@nuxt/types';
|
|
2
|
+
import Vue from 'vue';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Helper functions to handle localStorage safely
|
|
6
|
+
*/
|
|
7
|
+
function getDarkModeFromLocalStorage(): boolean {
|
|
8
|
+
return process.client && localStorage.getItem('darkMode') === 'true';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function setDarkModeToLocalStorage(value: boolean): void {
|
|
12
|
+
if (process.client) {
|
|
13
|
+
localStorage.setItem('darkMode', value.toString());
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function setHtmlDarkClass(isDark: boolean): void {
|
|
18
|
+
if (process.client) {
|
|
19
|
+
const htmlElement = document.documentElement;
|
|
20
|
+
if (isDark) {
|
|
21
|
+
htmlElement.classList.add('dark');
|
|
22
|
+
} else {
|
|
23
|
+
htmlElement.classList.remove('dark');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* ThemeProvider: A Vue instance to provide theme related functionalities.
|
|
30
|
+
*
|
|
31
|
+
* Usage:
|
|
32
|
+
* - Change the theme on button click:
|
|
33
|
+
* this.$theme.setDarkMode(!this.$theme.isDark);
|
|
34
|
+
*
|
|
35
|
+
* - Register the theme change listener:
|
|
36
|
+
* this.$theme.$on('darkMode', (value) => { console.log('darkMode:', value); });
|
|
37
|
+
*/
|
|
38
|
+
export const ThemeProvider = new Vue({
|
|
39
|
+
data() {
|
|
40
|
+
return {
|
|
41
|
+
isDarkMode: getDarkModeFromLocalStorage(),
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
computed: {
|
|
45
|
+
isDark: {
|
|
46
|
+
get(): boolean {
|
|
47
|
+
return this.isDarkMode;
|
|
48
|
+
},
|
|
49
|
+
set(value: boolean) {
|
|
50
|
+
this.isDarkMode = value;
|
|
51
|
+
setDarkModeToLocalStorage(value);
|
|
52
|
+
this.$emit('darkMode', value);
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
watch: {
|
|
57
|
+
isDark(newVal: boolean) {
|
|
58
|
+
setHtmlDarkClass(newVal);
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
methods: {
|
|
62
|
+
setDarkMode(value: boolean) {
|
|
63
|
+
this.isDark = value; // This will trigger the setter of isDark.
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
created() {
|
|
67
|
+
setHtmlDarkClass(this.isDark); // Sayfa yüklendiğinde fonksiyonu manuel olarak tetikle
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
type InjectFunction = (key: string, value: any) => void;
|
|
72
|
+
|
|
73
|
+
export default (context: Context, inject: InjectFunction) => {
|
|
74
|
+
inject('theme', ThemeProvider);
|
|
75
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Vue from 'vue';
|
|
2
|
+
|
|
3
|
+
// get options passed from module.js
|
|
4
|
+
const options = JSON.parse(`<%= JSON.stringify(options) %>`);
|
|
5
|
+
|
|
6
|
+
import components from '../components-ts/exporter';
|
|
7
|
+
|
|
8
|
+
// loop through components and register them
|
|
9
|
+
for (const name in components) {
|
|
10
|
+
Vue.component(name, {
|
|
11
|
+
// extend the original component
|
|
12
|
+
extends: components[name],
|
|
13
|
+
// add a _customCounterOptions prop to gain access to the options in the component
|
|
14
|
+
props: {
|
|
15
|
+
timus: {
|
|
16
|
+
type: Object,
|
|
17
|
+
default: () => ({ ...options }),
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
}
|