@ramathibodi/nuxt-commons 0.1.74 → 0.1.75
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 +115 -115
- package/dist/module.json +1 -1
- package/dist/runtime/components/Alert.vue +58 -58
- package/dist/runtime/components/BarcodeReader.vue +130 -130
- package/dist/runtime/components/ExportCSV.vue +110 -110
- package/dist/runtime/components/FileBtn.vue +79 -79
- package/dist/runtime/components/ImportCSV.vue +151 -151
- package/dist/runtime/components/MrzReader.vue +168 -168
- package/dist/runtime/components/SplitterPanel.vue +67 -67
- package/dist/runtime/components/TabsGroup.vue +39 -39
- package/dist/runtime/components/TextBarcode.vue +66 -66
- package/dist/runtime/components/device/IdCardButton.vue +95 -95
- package/dist/runtime/components/device/IdCardWebSocket.vue +207 -207
- package/dist/runtime/components/device/Scanner.vue +350 -350
- package/dist/runtime/components/dialog/Confirm.vue +112 -112
- package/dist/runtime/components/dialog/Host.vue +88 -88
- package/dist/runtime/components/dialog/Index.vue +84 -84
- package/dist/runtime/components/dialog/Loading.vue +51 -51
- package/dist/runtime/components/dialog/default/Confirm.vue +112 -112
- package/dist/runtime/components/dialog/default/Loading.vue +60 -60
- package/dist/runtime/components/dialog/default/Notify.vue +82 -82
- package/dist/runtime/components/dialog/default/Printing.vue +46 -46
- package/dist/runtime/components/dialog/default/VerifyUser.vue +144 -144
- package/dist/runtime/components/document/Form.vue +50 -50
- package/dist/runtime/components/document/TemplateBuilder.vue +536 -536
- package/dist/runtime/components/form/ActionPad.vue +156 -156
- package/dist/runtime/components/form/Birthdate.vue +116 -116
- package/dist/runtime/components/form/CheckboxGroup.vue +99 -99
- package/dist/runtime/components/form/CodeEditor.vue +45 -45
- package/dist/runtime/components/form/Date.vue +270 -270
- package/dist/runtime/components/form/DateTime.vue +220 -220
- package/dist/runtime/components/form/Dialog.vue +178 -178
- package/dist/runtime/components/form/EditPad.vue +157 -157
- package/dist/runtime/components/form/File.vue +295 -295
- package/dist/runtime/components/form/Hidden.vue +44 -44
- package/dist/runtime/components/form/Iterator.vue +538 -538
- package/dist/runtime/components/form/Login.vue +143 -143
- package/dist/runtime/components/form/Pad.vue +399 -399
- package/dist/runtime/components/form/SignPad.vue +226 -226
- package/dist/runtime/components/form/System.vue +34 -34
- package/dist/runtime/components/form/Table.vue +391 -391
- package/dist/runtime/components/form/TableData.vue +236 -236
- package/dist/runtime/components/form/Time.vue +177 -177
- package/dist/runtime/components/form/images/Capture.vue +245 -245
- package/dist/runtime/components/form/images/Edit.vue +133 -133
- package/dist/runtime/components/form/images/Field.vue +331 -331
- package/dist/runtime/components/form/images/Pad.vue +54 -54
- package/dist/runtime/components/label/Date.vue +37 -37
- package/dist/runtime/components/label/DateAgo.vue +102 -102
- package/dist/runtime/components/label/DateCount.vue +152 -152
- package/dist/runtime/components/label/Field.vue +111 -111
- package/dist/runtime/components/label/FormatMoney.vue +37 -37
- package/dist/runtime/components/label/Mask.vue +46 -46
- package/dist/runtime/components/label/Object.vue +21 -21
- package/dist/runtime/components/master/Autocomplete.vue +89 -89
- package/dist/runtime/components/master/Combobox.vue +88 -88
- package/dist/runtime/components/master/RadioGroup.vue +90 -90
- package/dist/runtime/components/master/Select.vue +70 -70
- package/dist/runtime/components/master/label.vue +55 -55
- package/dist/runtime/components/model/Autocomplete.vue +91 -91
- package/dist/runtime/components/model/Combobox.vue +90 -90
- package/dist/runtime/components/model/Pad.vue +114 -114
- package/dist/runtime/components/model/Select.vue +78 -84
- package/dist/runtime/components/model/Table.vue +370 -370
- package/dist/runtime/components/model/iterator.vue +497 -497
- package/dist/runtime/components/model/label.vue +58 -58
- package/dist/runtime/components/pdf/Print.vue +75 -75
- package/dist/runtime/components/pdf/View.vue +146 -146
- package/dist/runtime/composables/dialog.d.ts +1 -1
- package/dist/runtime/composables/graphql.d.ts +1 -1
- package/dist/runtime/composables/graphqlModel.d.ts +9 -9
- package/dist/runtime/composables/graphqlModelItem.d.ts +7 -7
- package/dist/runtime/composables/graphqlModelOperation.d.ts +6 -6
- package/dist/runtime/composables/userPermission.d.ts +1 -1
- package/dist/runtime/labs/Calendar.vue +99 -99
- package/dist/runtime/labs/form/EditMobile.vue +152 -152
- package/dist/runtime/labs/form/TextFieldMask.vue +43 -43
- package/dist/runtime/plugins/clientConfig.d.ts +1 -1
- package/dist/runtime/plugins/default.d.ts +1 -1
- package/dist/runtime/plugins/dialogManager.d.ts +1 -1
- package/dist/runtime/plugins/permission.d.ts +1 -1
- package/dist/runtime/types/alert.d.ts +11 -11
- package/dist/runtime/types/clientConfig.d.ts +13 -13
- package/dist/runtime/types/dialogManager.d.ts +35 -35
- package/dist/runtime/types/formDialog.d.ts +5 -5
- package/dist/runtime/types/graphqlOperation.d.ts +23 -23
- package/dist/runtime/types/menu.d.ts +31 -31
- package/dist/runtime/types/modules.d.ts +7 -7
- package/dist/runtime/types/permission.d.ts +13 -13
- package/package.json +131 -131
- package/scripts/enrich-vue-docs-from-ai.mjs +197 -197
- package/scripts/generate-ai-summary.mjs +321 -321
- package/scripts/generate-composables-md.mjs +129 -129
- package/scripts/postInstall.cjs +70 -70
- package/templates/.codegen/codegen.ts +32 -32
- package/templates/.codegen/plugin-schema-object.js +161 -161
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
|
|
4
|
-
const rootDir = process.cwd()
|
|
5
|
-
const aiSummaryPath = path.join(rootDir, 'docs/ai-summary.json')
|
|
6
|
-
const outDir = path.join(rootDir, 'docs/composables-md')
|
|
7
|
-
|
|
8
|
-
if (!fs.existsSync(aiSummaryPath)) {
|
|
9
|
-
console.error('docs/ai-summary.json not found. Run: npm run docs:ai:summary')
|
|
10
|
-
process.exit(1)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const ai = JSON.parse(fs.readFileSync(aiSummaryPath, 'utf8'))
|
|
14
|
-
const composables = ai.composables || []
|
|
15
|
-
|
|
16
|
-
function safeName(filePath) {
|
|
17
|
-
return filePath
|
|
18
|
-
.replace(/^src\/runtime\/composables\//, '')
|
|
19
|
-
.replace(/\//g, '__')
|
|
20
|
-
.replace(/\.ts$/, '')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function mdEscape(str) {
|
|
24
|
-
return String(str ?? '').replace(/\|/g, '\\|')
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
fs.mkdirSync(outDir, { recursive: true })
|
|
28
|
-
|
|
29
|
-
const index = []
|
|
30
|
-
index.push('# Composables (Markdown)')
|
|
31
|
-
index.push('')
|
|
32
|
-
index.push(`Generated at: ${ai.generatedAt}`)
|
|
33
|
-
index.push('')
|
|
34
|
-
index.push('| Composable | Source |')
|
|
35
|
-
index.push('| ---------- | ------ |')
|
|
36
|
-
|
|
37
|
-
for (const c of composables) {
|
|
38
|
-
const fileBase = safeName(c.path)
|
|
39
|
-
const outFile = path.join(outDir, `${fileBase}.md`)
|
|
40
|
-
const content = []
|
|
41
|
-
|
|
42
|
-
content.push(`# ${fileBase}`)
|
|
43
|
-
content.push('')
|
|
44
|
-
content.push(`- Source: \`${c.path}\``)
|
|
45
|
-
content.push(`- Summary: ${c.summary || ''}`)
|
|
46
|
-
content.push('')
|
|
47
|
-
|
|
48
|
-
const exp = c.exports || {}
|
|
49
|
-
const functions = exp.functions || []
|
|
50
|
-
const interfaces = exp.interfaces || []
|
|
51
|
-
const types = exp.types || []
|
|
52
|
-
const consts = exp.constants || []
|
|
53
|
-
const enums = exp.enums || []
|
|
54
|
-
|
|
55
|
-
content.push('## Exported Functions')
|
|
56
|
-
content.push('')
|
|
57
|
-
if (functions.length) {
|
|
58
|
-
content.push('| Name | Signature | Returns |')
|
|
59
|
-
content.push('| ---- | --------- | ------- |')
|
|
60
|
-
for (const fn of functions) {
|
|
61
|
-
content.push(`| \`${mdEscape(fn.name)}\` | \`${mdEscape(fn.signature || '')}\` | \`${mdEscape(fn.returns || '')}\` |`)
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
content.push('No exported functions.')
|
|
65
|
-
}
|
|
66
|
-
content.push('')
|
|
67
|
-
|
|
68
|
-
content.push('## Exported Interfaces')
|
|
69
|
-
content.push('')
|
|
70
|
-
if (interfaces.length) {
|
|
71
|
-
for (const i of interfaces) {
|
|
72
|
-
content.push(`### \`${i.name}\``)
|
|
73
|
-
content.push('')
|
|
74
|
-
content.push('```ts')
|
|
75
|
-
content.push(i.shape || '')
|
|
76
|
-
content.push('```')
|
|
77
|
-
content.push('')
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
content.push('No exported interfaces.')
|
|
81
|
-
content.push('')
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
content.push('## Exported Types')
|
|
85
|
-
content.push('')
|
|
86
|
-
if (types.length) {
|
|
87
|
-
content.push('| Name | Definition |')
|
|
88
|
-
content.push('| ---- | ---------- |')
|
|
89
|
-
for (const t of types) {
|
|
90
|
-
content.push(`| \`${mdEscape(t.name)}\` | \`${mdEscape(t.definition || '')}\` |`)
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
content.push('No exported types.')
|
|
94
|
-
}
|
|
95
|
-
content.push('')
|
|
96
|
-
|
|
97
|
-
content.push('## Exported Constants')
|
|
98
|
-
content.push('')
|
|
99
|
-
if (consts.length) {
|
|
100
|
-
content.push('| Name | Type |')
|
|
101
|
-
content.push('| ---- | ---- |')
|
|
102
|
-
for (const k of consts) {
|
|
103
|
-
content.push(`| \`${mdEscape(k.name)}\` | \`${mdEscape(k.type || '')}\` |`)
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
content.push('No exported constants.')
|
|
107
|
-
}
|
|
108
|
-
content.push('')
|
|
109
|
-
|
|
110
|
-
content.push('## Exported Enums')
|
|
111
|
-
content.push('')
|
|
112
|
-
if (enums.length) {
|
|
113
|
-
for (const e of enums) {
|
|
114
|
-
content.push(`### \`${e.name}\``)
|
|
115
|
-
content.push('')
|
|
116
|
-
for (const m of e.members || []) content.push(`- \`${m}\``)
|
|
117
|
-
content.push('')
|
|
118
|
-
}
|
|
119
|
-
} else {
|
|
120
|
-
content.push('No exported enums.')
|
|
121
|
-
content.push('')
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
fs.writeFileSync(outFile, content.join('\n'))
|
|
125
|
-
index.push(`| [\`${fileBase}\`](${fileBase}.md) | \`${c.path}\` |`)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
fs.writeFileSync(path.join(outDir, 'README.md'), index.join('\n'))
|
|
129
|
-
console.log(`Generated markdown docs for ${composables.length} composables at docs/composables-md`)
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
const rootDir = process.cwd()
|
|
5
|
+
const aiSummaryPath = path.join(rootDir, 'docs/ai-summary.json')
|
|
6
|
+
const outDir = path.join(rootDir, 'docs/composables-md')
|
|
7
|
+
|
|
8
|
+
if (!fs.existsSync(aiSummaryPath)) {
|
|
9
|
+
console.error('docs/ai-summary.json not found. Run: npm run docs:ai:summary')
|
|
10
|
+
process.exit(1)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const ai = JSON.parse(fs.readFileSync(aiSummaryPath, 'utf8'))
|
|
14
|
+
const composables = ai.composables || []
|
|
15
|
+
|
|
16
|
+
function safeName(filePath) {
|
|
17
|
+
return filePath
|
|
18
|
+
.replace(/^src\/runtime\/composables\//, '')
|
|
19
|
+
.replace(/\//g, '__')
|
|
20
|
+
.replace(/\.ts$/, '')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function mdEscape(str) {
|
|
24
|
+
return String(str ?? '').replace(/\|/g, '\\|')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fs.mkdirSync(outDir, { recursive: true })
|
|
28
|
+
|
|
29
|
+
const index = []
|
|
30
|
+
index.push('# Composables (Markdown)')
|
|
31
|
+
index.push('')
|
|
32
|
+
index.push(`Generated at: ${ai.generatedAt}`)
|
|
33
|
+
index.push('')
|
|
34
|
+
index.push('| Composable | Source |')
|
|
35
|
+
index.push('| ---------- | ------ |')
|
|
36
|
+
|
|
37
|
+
for (const c of composables) {
|
|
38
|
+
const fileBase = safeName(c.path)
|
|
39
|
+
const outFile = path.join(outDir, `${fileBase}.md`)
|
|
40
|
+
const content = []
|
|
41
|
+
|
|
42
|
+
content.push(`# ${fileBase}`)
|
|
43
|
+
content.push('')
|
|
44
|
+
content.push(`- Source: \`${c.path}\``)
|
|
45
|
+
content.push(`- Summary: ${c.summary || ''}`)
|
|
46
|
+
content.push('')
|
|
47
|
+
|
|
48
|
+
const exp = c.exports || {}
|
|
49
|
+
const functions = exp.functions || []
|
|
50
|
+
const interfaces = exp.interfaces || []
|
|
51
|
+
const types = exp.types || []
|
|
52
|
+
const consts = exp.constants || []
|
|
53
|
+
const enums = exp.enums || []
|
|
54
|
+
|
|
55
|
+
content.push('## Exported Functions')
|
|
56
|
+
content.push('')
|
|
57
|
+
if (functions.length) {
|
|
58
|
+
content.push('| Name | Signature | Returns |')
|
|
59
|
+
content.push('| ---- | --------- | ------- |')
|
|
60
|
+
for (const fn of functions) {
|
|
61
|
+
content.push(`| \`${mdEscape(fn.name)}\` | \`${mdEscape(fn.signature || '')}\` | \`${mdEscape(fn.returns || '')}\` |`)
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
content.push('No exported functions.')
|
|
65
|
+
}
|
|
66
|
+
content.push('')
|
|
67
|
+
|
|
68
|
+
content.push('## Exported Interfaces')
|
|
69
|
+
content.push('')
|
|
70
|
+
if (interfaces.length) {
|
|
71
|
+
for (const i of interfaces) {
|
|
72
|
+
content.push(`### \`${i.name}\``)
|
|
73
|
+
content.push('')
|
|
74
|
+
content.push('```ts')
|
|
75
|
+
content.push(i.shape || '')
|
|
76
|
+
content.push('```')
|
|
77
|
+
content.push('')
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
content.push('No exported interfaces.')
|
|
81
|
+
content.push('')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
content.push('## Exported Types')
|
|
85
|
+
content.push('')
|
|
86
|
+
if (types.length) {
|
|
87
|
+
content.push('| Name | Definition |')
|
|
88
|
+
content.push('| ---- | ---------- |')
|
|
89
|
+
for (const t of types) {
|
|
90
|
+
content.push(`| \`${mdEscape(t.name)}\` | \`${mdEscape(t.definition || '')}\` |`)
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
content.push('No exported types.')
|
|
94
|
+
}
|
|
95
|
+
content.push('')
|
|
96
|
+
|
|
97
|
+
content.push('## Exported Constants')
|
|
98
|
+
content.push('')
|
|
99
|
+
if (consts.length) {
|
|
100
|
+
content.push('| Name | Type |')
|
|
101
|
+
content.push('| ---- | ---- |')
|
|
102
|
+
for (const k of consts) {
|
|
103
|
+
content.push(`| \`${mdEscape(k.name)}\` | \`${mdEscape(k.type || '')}\` |`)
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
content.push('No exported constants.')
|
|
107
|
+
}
|
|
108
|
+
content.push('')
|
|
109
|
+
|
|
110
|
+
content.push('## Exported Enums')
|
|
111
|
+
content.push('')
|
|
112
|
+
if (enums.length) {
|
|
113
|
+
for (const e of enums) {
|
|
114
|
+
content.push(`### \`${e.name}\``)
|
|
115
|
+
content.push('')
|
|
116
|
+
for (const m of e.members || []) content.push(`- \`${m}\``)
|
|
117
|
+
content.push('')
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
content.push('No exported enums.')
|
|
121
|
+
content.push('')
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
fs.writeFileSync(outFile, content.join('\n'))
|
|
125
|
+
index.push(`| [\`${fileBase}\`](${fileBase}.md) | \`${c.path}\` |`)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
fs.writeFileSync(path.join(outDir, 'README.md'), index.join('\n'))
|
|
129
|
+
console.log(`Generated markdown docs for ${composables.length} composables at docs/composables-md`)
|
package/scripts/postInstall.cjs
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
const fs = require('node:fs')
|
|
2
|
-
const path = require('node:path')
|
|
3
|
-
const { execSync } = require('node:child_process')
|
|
4
|
-
|
|
5
|
-
// Function to copy a file from source to destination
|
|
6
|
-
function copyFile(src, dest) {
|
|
7
|
-
fs.mkdirSync(path.dirname(dest), { recursive: true })
|
|
8
|
-
fs.copyFileSync(src, dest)
|
|
9
|
-
console.log(`Copied ${src} to ${dest}`)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Function to copy all files in a directory recursively
|
|
13
|
-
function copyDirectory(srcDir, destDir) {
|
|
14
|
-
const entries = fs.readdirSync(srcDir, { withFileTypes: true })
|
|
15
|
-
|
|
16
|
-
for (let entry of entries) {
|
|
17
|
-
const srcPath = path.join(srcDir, entry.name)
|
|
18
|
-
const destPath = path.join(destDir, entry.name)
|
|
19
|
-
|
|
20
|
-
if (entry.isDirectory()) {
|
|
21
|
-
copyDirectory(srcPath, destPath)
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
copyFile(srcPath, destPath)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Function to modify package.json to add a new script
|
|
30
|
-
function addScriptToPackageJson(scriptName, scriptCommand) {
|
|
31
|
-
const packageJsonPath = path.join(process.env.INIT_CWD, 'package.json')
|
|
32
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
|
|
33
|
-
|
|
34
|
-
packageJson.scripts = packageJson.scripts || {}
|
|
35
|
-
packageJson.scripts[scriptName] = scriptCommand
|
|
36
|
-
|
|
37
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
38
|
-
console.log(`Added script "${scriptName}": "${scriptCommand}" to package.json`)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Function to run npm run codegen safely
|
|
42
|
-
function runCodegen(projectRoot) {
|
|
43
|
-
try {
|
|
44
|
-
execSync('npm run codegen', { cwd: projectRoot, stdio: 'inherit' })
|
|
45
|
-
console.log('Successfully ran npm run codegen')
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
console.log('npm run codegen failed or script not found, continuing...')
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (process.env.INIT_CWD === process.cwd()) process.exit()
|
|
53
|
-
|
|
54
|
-
// Define source and destination directories
|
|
55
|
-
const srcDir = path.join(__dirname, '..', 'templates')
|
|
56
|
-
const destDir = process.env.INIT_CWD // Project root
|
|
57
|
-
|
|
58
|
-
// Copy all files from templates directory to project root
|
|
59
|
-
copyDirectory(srcDir, destDir)
|
|
60
|
-
|
|
61
|
-
// Add new script to package.json
|
|
62
|
-
addScriptToPackageJson('codegen', 'graphql-codegen --require dotenv/config --config ./.codegen/codegen.ts dotenv_config_path=.env')
|
|
63
|
-
|
|
64
|
-
// Run npm run codegen safely
|
|
65
|
-
if (!fs.existsSync(path.join(destDir, 'types', 'graphql.ts')) || !fs.existsSync(path.join(destDir, 'composables', 'graphqlObject.ts'))) {
|
|
66
|
-
if (process.env.NUXT_PUBLIC_WS_GRAPHQL) runCodegen(destDir)
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
console.log('Skipping codegen')
|
|
70
|
-
}
|
|
1
|
+
const fs = require('node:fs')
|
|
2
|
+
const path = require('node:path')
|
|
3
|
+
const { execSync } = require('node:child_process')
|
|
4
|
+
|
|
5
|
+
// Function to copy a file from source to destination
|
|
6
|
+
function copyFile(src, dest) {
|
|
7
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true })
|
|
8
|
+
fs.copyFileSync(src, dest)
|
|
9
|
+
console.log(`Copied ${src} to ${dest}`)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Function to copy all files in a directory recursively
|
|
13
|
+
function copyDirectory(srcDir, destDir) {
|
|
14
|
+
const entries = fs.readdirSync(srcDir, { withFileTypes: true })
|
|
15
|
+
|
|
16
|
+
for (let entry of entries) {
|
|
17
|
+
const srcPath = path.join(srcDir, entry.name)
|
|
18
|
+
const destPath = path.join(destDir, entry.name)
|
|
19
|
+
|
|
20
|
+
if (entry.isDirectory()) {
|
|
21
|
+
copyDirectory(srcPath, destPath)
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
copyFile(srcPath, destPath)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Function to modify package.json to add a new script
|
|
30
|
+
function addScriptToPackageJson(scriptName, scriptCommand) {
|
|
31
|
+
const packageJsonPath = path.join(process.env.INIT_CWD, 'package.json')
|
|
32
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
|
|
33
|
+
|
|
34
|
+
packageJson.scripts = packageJson.scripts || {}
|
|
35
|
+
packageJson.scripts[scriptName] = scriptCommand
|
|
36
|
+
|
|
37
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
38
|
+
console.log(`Added script "${scriptName}": "${scriptCommand}" to package.json`)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Function to run npm run codegen safely
|
|
42
|
+
function runCodegen(projectRoot) {
|
|
43
|
+
try {
|
|
44
|
+
execSync('npm run codegen', { cwd: projectRoot, stdio: 'inherit' })
|
|
45
|
+
console.log('Successfully ran npm run codegen')
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.log('npm run codegen failed or script not found, continuing...')
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (process.env.INIT_CWD === process.cwd()) process.exit()
|
|
53
|
+
|
|
54
|
+
// Define source and destination directories
|
|
55
|
+
const srcDir = path.join(__dirname, '..', 'templates')
|
|
56
|
+
const destDir = process.env.INIT_CWD // Project root
|
|
57
|
+
|
|
58
|
+
// Copy all files from templates directory to project root
|
|
59
|
+
copyDirectory(srcDir, destDir)
|
|
60
|
+
|
|
61
|
+
// Add new script to package.json
|
|
62
|
+
addScriptToPackageJson('codegen', 'graphql-codegen --require dotenv/config --config ./.codegen/codegen.ts dotenv_config_path=.env')
|
|
63
|
+
|
|
64
|
+
// Run npm run codegen safely
|
|
65
|
+
if (!fs.existsSync(path.join(destDir, 'types', 'graphql.ts')) || !fs.existsSync(path.join(destDir, 'composables', 'graphqlObject.ts'))) {
|
|
66
|
+
if (process.env.NUXT_PUBLIC_WS_GRAPHQL) runCodegen(destDir)
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
console.log('Skipping codegen')
|
|
70
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import type {CodegenConfig} from '@graphql-codegen/cli'
|
|
2
|
-
|
|
3
|
-
const config: CodegenConfig = {
|
|
4
|
-
overwrite: true,
|
|
5
|
-
schema: process.env.NUXT_PUBLIC_WS_GRAPHQL,
|
|
6
|
-
generates: {
|
|
7
|
-
'./types/graphql.ts': {
|
|
8
|
-
plugins: [{
|
|
9
|
-
add: {
|
|
10
|
-
content: '//Auto-generated file, do not make any change. Content could be overwritten.',
|
|
11
|
-
},
|
|
12
|
-
}, 'typescript'],
|
|
13
|
-
config: {
|
|
14
|
-
maybeValue: 'T | null | undefined',
|
|
15
|
-
inputMaybeValue: 'T | null | undefined',
|
|
16
|
-
declarationKind: 'class',
|
|
17
|
-
enumsAsTypes: true,
|
|
18
|
-
skipTypename: true,
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
'./composables/graphqlObject.ts': {
|
|
22
|
-
plugins: [{
|
|
23
|
-
add: {
|
|
24
|
-
content: '//Auto-generated file, do not make any change. Content could be overwritten.',
|
|
25
|
-
},
|
|
26
|
-
}, './.codegen/plugin-schema-object.js'],
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
hooks: { afterAllFileWrite: ['prettier --parser typescript --tab-width 4 --write'] },
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default config
|
|
1
|
+
import type {CodegenConfig} from '@graphql-codegen/cli'
|
|
2
|
+
|
|
3
|
+
const config: CodegenConfig = {
|
|
4
|
+
overwrite: true,
|
|
5
|
+
schema: process.env.NUXT_PUBLIC_WS_GRAPHQL,
|
|
6
|
+
generates: {
|
|
7
|
+
'./types/graphql.ts': {
|
|
8
|
+
plugins: [{
|
|
9
|
+
add: {
|
|
10
|
+
content: '//Auto-generated file, do not make any change. Content could be overwritten.',
|
|
11
|
+
},
|
|
12
|
+
}, 'typescript'],
|
|
13
|
+
config: {
|
|
14
|
+
maybeValue: 'T | null | undefined',
|
|
15
|
+
inputMaybeValue: 'T | null | undefined',
|
|
16
|
+
declarationKind: 'class',
|
|
17
|
+
enumsAsTypes: true,
|
|
18
|
+
skipTypename: true,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
'./composables/graphqlObject.ts': {
|
|
22
|
+
plugins: [{
|
|
23
|
+
add: {
|
|
24
|
+
content: '//Auto-generated file, do not make any change. Content could be overwritten.',
|
|
25
|
+
},
|
|
26
|
+
}, './.codegen/plugin-schema-object.js'],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
hooks: { afterAllFileWrite: ['prettier --parser typescript --tab-width 4 --write'] },
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default config
|