create-vite-extra 0.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.
Files changed (177) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +79 -0
  3. package/index.js +384 -0
  4. package/package.json +34 -0
  5. package/template-library/_gitignore +24 -0
  6. package/template-library/index.d.ts +1 -0
  7. package/template-library/index.html +13 -0
  8. package/template-library/javascript.svg +1 -0
  9. package/template-library/lib/main.js +9 -0
  10. package/template-library/main.js +23 -0
  11. package/template-library/package.json +22 -0
  12. package/template-library/public/vite.svg +1 -0
  13. package/template-library/style.css +97 -0
  14. package/template-library/vite.config.js +11 -0
  15. package/template-library-ts/_gitignore +24 -0
  16. package/template-library-ts/index.d.ts +1 -0
  17. package/template-library-ts/index.html +13 -0
  18. package/template-library-ts/lib/main.ts +9 -0
  19. package/template-library-ts/package.json +23 -0
  20. package/template-library-ts/public/vite.svg +1 -0
  21. package/template-library-ts/src/main.ts +23 -0
  22. package/template-library-ts/src/style.css +97 -0
  23. package/template-library-ts/src/typescript.svg +1 -0
  24. package/template-library-ts/src/vite-env.d.ts +1 -0
  25. package/template-library-ts/tsconfig.json +20 -0
  26. package/template-library-ts/vite.config.ts +11 -0
  27. package/template-ssr-preact/_gitignore +24 -0
  28. package/template-ssr-preact/index.html +14 -0
  29. package/template-ssr-preact/package.json +25 -0
  30. package/template-ssr-preact/public/vite.svg +1 -0
  31. package/template-ssr-preact/server.js +71 -0
  32. package/template-ssr-preact/src/app.css +25 -0
  33. package/template-ssr-preact/src/app.jsx +32 -0
  34. package/template-ssr-preact/src/assets/preact.svg +1 -0
  35. package/template-ssr-preact/src/entry-client.jsx +5 -0
  36. package/template-ssr-preact/src/entry-server.jsx +7 -0
  37. package/template-ssr-preact/src/index.css +70 -0
  38. package/template-ssr-preact/vite.config.js +15 -0
  39. package/template-ssr-preact-ts/_gitignore +24 -0
  40. package/template-ssr-preact-ts/index.html +14 -0
  41. package/template-ssr-preact-ts/package.json +27 -0
  42. package/template-ssr-preact-ts/public/vite.svg +1 -0
  43. package/template-ssr-preact-ts/server.js +71 -0
  44. package/template-ssr-preact-ts/src/app.css +25 -0
  45. package/template-ssr-preact-ts/src/app.tsx +32 -0
  46. package/template-ssr-preact-ts/src/assets/preact.svg +1 -0
  47. package/template-ssr-preact-ts/src/entry-client.tsx +5 -0
  48. package/template-ssr-preact-ts/src/entry-server.tsx +7 -0
  49. package/template-ssr-preact-ts/src/index.css +70 -0
  50. package/template-ssr-preact-ts/src/preact.d.ts +1 -0
  51. package/template-ssr-preact-ts/src/vite-env.d.ts +1 -0
  52. package/template-ssr-preact-ts/tsconfig.json +23 -0
  53. package/template-ssr-preact-ts/tsconfig.node.json +16 -0
  54. package/template-ssr-preact-ts/vite.config.ts +15 -0
  55. package/template-ssr-react/_gitignore +24 -0
  56. package/template-ssr-react/index.html +14 -0
  57. package/template-ssr-react/package.json +27 -0
  58. package/template-ssr-react/public/vite.svg +1 -0
  59. package/template-ssr-react/server.js +71 -0
  60. package/template-ssr-react/src/App.css +41 -0
  61. package/template-ssr-react/src/App.jsx +34 -0
  62. package/template-ssr-react/src/assets/react.svg +1 -0
  63. package/template-ssr-react/src/entry-client.jsx +11 -0
  64. package/template-ssr-react/src/entry-server.jsx +12 -0
  65. package/template-ssr-react/src/index.css +70 -0
  66. package/template-ssr-react/vite.config.js +7 -0
  67. package/template-ssr-react-ts/_gitignore +24 -0
  68. package/template-ssr-react-ts/index.html +14 -0
  69. package/template-ssr-react-ts/package.json +28 -0
  70. package/template-ssr-react-ts/public/vite.svg +1 -0
  71. package/template-ssr-react-ts/server.js +71 -0
  72. package/template-ssr-react-ts/src/App.css +41 -0
  73. package/template-ssr-react-ts/src/App.tsx +34 -0
  74. package/template-ssr-react-ts/src/assets/react.svg +1 -0
  75. package/template-ssr-react-ts/src/entry-client.tsx +11 -0
  76. package/template-ssr-react-ts/src/entry-server.tsx +12 -0
  77. package/template-ssr-react-ts/src/index.css +70 -0
  78. package/template-ssr-react-ts/src/vite-env.d.ts +1 -0
  79. package/template-ssr-react-ts/tsconfig.json +21 -0
  80. package/template-ssr-react-ts/tsconfig.node.json +15 -0
  81. package/template-ssr-react-ts/vite.config.ts +7 -0
  82. package/template-ssr-svelte/.vscode/extensions.json +3 -0
  83. package/template-ssr-svelte/README.md +48 -0
  84. package/template-ssr-svelte/_gitignore +24 -0
  85. package/template-ssr-svelte/index.html +14 -0
  86. package/template-ssr-svelte/jsconfig.json +34 -0
  87. package/template-ssr-svelte/package.json +24 -0
  88. package/template-ssr-svelte/public/vite.svg +1 -0
  89. package/template-ssr-svelte/server.js +71 -0
  90. package/template-ssr-svelte/src/App.svelte +45 -0
  91. package/template-ssr-svelte/src/app.css +81 -0
  92. package/template-ssr-svelte/src/assets/svelte.svg +1 -0
  93. package/template-ssr-svelte/src/entry-client.js +7 -0
  94. package/template-ssr-svelte/src/entry-server.js +6 -0
  95. package/template-ssr-svelte/src/lib/Counter.svelte +10 -0
  96. package/template-ssr-svelte/src/vite-env.d.ts +2 -0
  97. package/template-ssr-svelte/vite.config.js +13 -0
  98. package/template-ssr-svelte-ts/.vscode/extensions.json +3 -0
  99. package/template-ssr-svelte-ts/README.md +48 -0
  100. package/template-ssr-svelte-ts/_gitignore +24 -0
  101. package/template-ssr-svelte-ts/index.html +14 -0
  102. package/template-ssr-svelte-ts/package.json +29 -0
  103. package/template-ssr-svelte-ts/public/vite.svg +1 -0
  104. package/template-ssr-svelte-ts/server.js +71 -0
  105. package/template-ssr-svelte-ts/src/App.svelte +45 -0
  106. package/template-ssr-svelte-ts/src/app.css +81 -0
  107. package/template-ssr-svelte-ts/src/assets/svelte.svg +1 -0
  108. package/template-ssr-svelte-ts/src/entry-client.ts +7 -0
  109. package/template-ssr-svelte-ts/src/entry-server.ts +6 -0
  110. package/template-ssr-svelte-ts/src/lib/Counter.svelte +10 -0
  111. package/template-ssr-svelte-ts/src/vite-env.d.ts +2 -0
  112. package/template-ssr-svelte-ts/svelte.config.js +7 -0
  113. package/template-ssr-svelte-ts/tsconfig.json +21 -0
  114. package/template-ssr-svelte-ts/tsconfig.node.json +8 -0
  115. package/template-ssr-svelte-ts/vite.config.ts +13 -0
  116. package/template-ssr-transform/README.md +3 -0
  117. package/template-ssr-transform/_gitignore +24 -0
  118. package/template-ssr-transform/package.json +12 -0
  119. package/template-ssr-transform/src/foo.js +3 -0
  120. package/template-ssr-transform/src/main.js +5 -0
  121. package/template-ssr-transform/test.js +13 -0
  122. package/template-ssr-vanilla/_gitignore +24 -0
  123. package/template-ssr-vanilla/index.html +14 -0
  124. package/template-ssr-vanilla/package.json +22 -0
  125. package/template-ssr-vanilla/public/vite.svg +1 -0
  126. package/template-ssr-vanilla/server.js +71 -0
  127. package/template-ssr-vanilla/src/counter.js +9 -0
  128. package/template-ssr-vanilla/src/entry-client.js +5 -0
  129. package/template-ssr-vanilla/src/entry-server.js +22 -0
  130. package/template-ssr-vanilla/src/javascript.svg +1 -0
  131. package/template-ssr-vanilla/src/style.css +97 -0
  132. package/template-ssr-vanilla-ts/_gitignore +24 -0
  133. package/template-ssr-vanilla-ts/index.html +14 -0
  134. package/template-ssr-vanilla-ts/package.json +25 -0
  135. package/template-ssr-vanilla-ts/public/vite.svg +1 -0
  136. package/template-ssr-vanilla-ts/server.js +71 -0
  137. package/template-ssr-vanilla-ts/src/counter.ts +9 -0
  138. package/template-ssr-vanilla-ts/src/entry-client.ts +5 -0
  139. package/template-ssr-vanilla-ts/src/entry-server.ts +22 -0
  140. package/template-ssr-vanilla-ts/src/style.css +97 -0
  141. package/template-ssr-vanilla-ts/src/typescript.svg +1 -0
  142. package/template-ssr-vanilla-ts/src/vite-env.d.ts +1 -0
  143. package/template-ssr-vanilla-ts/tsconfig.json +22 -0
  144. package/template-ssr-vanilla-ts/tsconfig.node.json +8 -0
  145. package/template-ssr-vue/.vscode/extensions.json +3 -0
  146. package/template-ssr-vue/README.md +7 -0
  147. package/template-ssr-vue/_gitignore +24 -0
  148. package/template-ssr-vue/index.html +14 -0
  149. package/template-ssr-vue/package.json +24 -0
  150. package/template-ssr-vue/public/vite.svg +1 -0
  151. package/template-ssr-vue/server.js +71 -0
  152. package/template-ssr-vue/src/App.vue +31 -0
  153. package/template-ssr-vue/src/assets/vue.svg +1 -0
  154. package/template-ssr-vue/src/components/HelloWorld.vue +40 -0
  155. package/template-ssr-vue/src/entry-client.js +6 -0
  156. package/template-ssr-vue/src/entry-server.js +15 -0
  157. package/template-ssr-vue/src/main.js +10 -0
  158. package/template-ssr-vue/src/style.css +90 -0
  159. package/template-ssr-vue/vite.config.js +7 -0
  160. package/template-ssr-vue-ts/.vscode/extensions.json +3 -0
  161. package/template-ssr-vue-ts/README.md +16 -0
  162. package/template-ssr-vue-ts/_gitignore +24 -0
  163. package/template-ssr-vue-ts/index.html +14 -0
  164. package/template-ssr-vue-ts/package.json +26 -0
  165. package/template-ssr-vue-ts/public/vite.svg +1 -0
  166. package/template-ssr-vue-ts/server.js +71 -0
  167. package/template-ssr-vue-ts/src/App.vue +31 -0
  168. package/template-ssr-vue-ts/src/assets/vue.svg +1 -0
  169. package/template-ssr-vue-ts/src/components/HelloWorld.vue +38 -0
  170. package/template-ssr-vue-ts/src/entry-client.ts +6 -0
  171. package/template-ssr-vue-ts/src/entry-server.ts +15 -0
  172. package/template-ssr-vue-ts/src/main.ts +10 -0
  173. package/template-ssr-vue-ts/src/style.css +81 -0
  174. package/template-ssr-vue-ts/src/vite-env.d.ts +7 -0
  175. package/template-ssr-vue-ts/tsconfig.json +18 -0
  176. package/template-ssr-vue-ts/tsconfig.node.json +9 -0
  177. package/template-ssr-vue-ts/vite.config.ts +7 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019-present, Bjorn Lu, Yuxi (Evan) You and Vite contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # create-vite-extra
2
+
3
+ ## Scaffolding Your First Vite Project
4
+
5
+ > **Compatibility Note:**
6
+ > Vite requires [Node.js](https://nodejs.org/en/) version 14.18+, 16+. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
7
+
8
+ With NPM:
9
+
10
+ ```bash
11
+ $ npm create vite-extra@latest
12
+ ```
13
+
14
+ With Yarn:
15
+
16
+ ```bash
17
+ $ yarn create vite-extra
18
+ ```
19
+
20
+ With PNPM:
21
+
22
+ ```bash
23
+ $ pnpm create vite-extra
24
+ ```
25
+
26
+ Then follow the prompts!
27
+
28
+ You can also directly specify the project name and the template you want to use via additional command line options. For example, to scaffold a Vite + SSR + Vue project, run:
29
+
30
+ ```bash
31
+ # npm
32
+ npm create vite-extra@latest my-vue-app -- --template ssr-vue
33
+
34
+ # yarn
35
+ yarn create vite-extra my-vue-app --template ssr-vue
36
+
37
+ # pnpm
38
+ pnpm create vite-extra my-vue-app --template ssr-vue
39
+ ```
40
+
41
+ Currently supported template presets include:
42
+
43
+ - `ssr-vanilla`
44
+ - `ssr-vanilla-ts`
45
+ - `ssr-vue`
46
+ - `ssr-vue-ts`
47
+ - `ssr-react`
48
+ - `ssr-react-ts`
49
+ - `ssr-preact`
50
+ - `ssr-preact-ts`
51
+ - `ssr-svelte`
52
+ - `ssr-svelte-ts`
53
+ - `ssr-transform`
54
+ - `library`
55
+ - `library-ts`
56
+
57
+ You can use `.` for the project name to scaffold in the current directory.
58
+
59
+ ## Community Templates
60
+
61
+ create-vite is a tool to quickly start a project from a basic template for popular frameworks. Check out Awesome Vite for [community maintained templates](https://github.com/vitejs/awesome-vite#templates) that include other tools or target different frameworks. You can use a tool like [degit](https://github.com/Rich-Harris/degit) to scaffold your project with one of the templates.
62
+
63
+ ```bash
64
+ npx degit user/project my-project
65
+ cd my-project
66
+
67
+ npm install
68
+ npm run dev
69
+ ```
70
+
71
+ If the project uses `main` as the default branch, suffix the project repo with `#main`
72
+
73
+ ```bash
74
+ npx degit user/project#main my-project
75
+ ```
76
+
77
+ ## Attribution
78
+
79
+ This project is originally a fork of [create-vite](https://github.com/vitejs/vite/tree/main/packages/create-vite). Credit goes to all of it's contributors.
package/index.js ADDED
@@ -0,0 +1,384 @@
1
+ #!/usr/bin/env node
2
+
3
+ // @ts-check
4
+ import fs from 'node:fs'
5
+ import path from 'node:path'
6
+ import { fileURLToPath } from 'node:url'
7
+ import minimist from 'minimist'
8
+ import prompts from 'prompts'
9
+ import {
10
+ blue,
11
+ cyan,
12
+ green,
13
+ lightRed,
14
+ magenta,
15
+ red,
16
+ reset,
17
+ yellow,
18
+ lightMagenta
19
+ } from 'kolorist'
20
+
21
+ // Avoids autoconversion to number of the project name by defining that the args
22
+ // non associated with an option ( _ ) needs to be parsed as a string. See #4606
23
+ const argv = minimist(process.argv.slice(2), { string: ['_'] })
24
+ const cwd = process.cwd()
25
+
26
+ const FRAMEWORKS = [
27
+ {
28
+ name: 'ssr-vanilla',
29
+ color: yellow,
30
+ variants: [
31
+ {
32
+ name: 'ssr-vanilla',
33
+ display: 'JavaScript',
34
+ color: yellow
35
+ },
36
+ {
37
+ name: 'ssr-vanilla-ts',
38
+ display: 'TypeScript',
39
+ color: blue
40
+ }
41
+ ]
42
+ },
43
+ {
44
+ name: 'ssr-vue',
45
+ color: green,
46
+ variants: [
47
+ {
48
+ name: 'ssr-vue',
49
+ display: 'JavaScript',
50
+ color: yellow
51
+ },
52
+ {
53
+ name: 'ssr-vue-ts',
54
+ display: 'TypeScript',
55
+ color: blue
56
+ }
57
+ ]
58
+ },
59
+ {
60
+ name: 'ssr-react',
61
+ color: cyan,
62
+ variants: [
63
+ {
64
+ name: 'ssr-react',
65
+ display: 'JavaScript',
66
+ color: yellow
67
+ },
68
+ {
69
+ name: 'ssr-react-ts',
70
+ display: 'TypeScript',
71
+ color: blue
72
+ }
73
+ ]
74
+ },
75
+ {
76
+ name: 'ssr-preact',
77
+ color: magenta,
78
+ variants: [
79
+ {
80
+ name: 'ssr-preact',
81
+ display: 'JavaScript',
82
+ color: yellow
83
+ },
84
+ {
85
+ name: 'ssr-preact-ts',
86
+ display: 'TypeScript',
87
+ color: blue
88
+ }
89
+ ]
90
+ },
91
+ {
92
+ name: 'ssr-svelte',
93
+ color: red,
94
+ variants: [
95
+ {
96
+ name: 'ssr-svelte',
97
+ display: 'JavaScript',
98
+ color: yellow
99
+ },
100
+ {
101
+ name: 'ssr-svelte-ts',
102
+ display: 'TypeScript',
103
+ color: blue
104
+ }
105
+ ]
106
+ },
107
+
108
+ {
109
+ name: 'ssr-transform',
110
+ color: lightRed
111
+ },
112
+ {
113
+ name: 'library',
114
+ color: lightMagenta,
115
+ variants: [
116
+ {
117
+ name: 'library',
118
+ display: 'JavaScript',
119
+ color: yellow
120
+ },
121
+ {
122
+ name: 'library-ts',
123
+ display: 'TypeScript',
124
+ color: blue
125
+ }
126
+ ]
127
+ }
128
+ ]
129
+
130
+ const TEMPLATES = FRAMEWORKS.map(
131
+ (f) => (f.variants && f.variants.map((v) => v.name)) || [f.name]
132
+ ).reduce((a, b) => a.concat(b), [])
133
+
134
+ const renameFiles = {
135
+ _gitignore: '.gitignore'
136
+ }
137
+
138
+ async function init() {
139
+ let targetDir = formatTargetDir(argv._[0])
140
+ let template = argv.template || argv.t
141
+
142
+ const defaultTargetDir = 'vite-project'
143
+ const getProjectName = () =>
144
+ targetDir === '.' ? path.basename(path.resolve()) : targetDir
145
+
146
+ let result = {}
147
+
148
+ try {
149
+ result = await prompts(
150
+ [
151
+ {
152
+ type: targetDir ? null : 'text',
153
+ name: 'projectName',
154
+ message: reset('Project name:'),
155
+ initial: defaultTargetDir,
156
+ onState: (state) => {
157
+ targetDir = formatTargetDir(state.value) || defaultTargetDir
158
+ }
159
+ },
160
+ {
161
+ type: () =>
162
+ !fs.existsSync(targetDir) || isEmpty(targetDir) ? null : 'confirm',
163
+ name: 'overwrite',
164
+ message: () =>
165
+ (targetDir === '.'
166
+ ? 'Current directory'
167
+ : `Target directory "${targetDir}"`) +
168
+ ` is not empty. Remove existing files and continue?`
169
+ },
170
+ {
171
+ type: (_, { overwrite } = {}) => {
172
+ if (overwrite === false) {
173
+ throw new Error(red('✖') + ' Operation cancelled')
174
+ }
175
+ return null
176
+ },
177
+ name: 'overwriteChecker'
178
+ },
179
+ {
180
+ type: () => (isValidPackageName(getProjectName()) ? null : 'text'),
181
+ name: 'packageName',
182
+ message: reset('Package name:'),
183
+ initial: () => toValidPackageName(getProjectName()),
184
+ validate: (dir) =>
185
+ isValidPackageName(dir) || 'Invalid package.json name'
186
+ },
187
+ {
188
+ type: template && TEMPLATES.includes(template) ? null : 'select',
189
+ name: 'framework',
190
+ message:
191
+ typeof template === 'string' && !TEMPLATES.includes(template)
192
+ ? reset(
193
+ `"${template}" isn't a valid template. Please choose from below: `
194
+ )
195
+ : reset('Select a template:'),
196
+ initial: 0,
197
+ choices: FRAMEWORKS.map((framework) => {
198
+ const frameworkColor = framework.color
199
+ return {
200
+ title: frameworkColor(framework.name),
201
+ value: framework
202
+ }
203
+ })
204
+ },
205
+ {
206
+ type: (framework) =>
207
+ framework && framework.variants ? 'select' : null,
208
+ name: 'variant',
209
+ message: reset('Select a variant:'),
210
+ // @ts-ignore
211
+ choices: (framework) =>
212
+ framework.variants.map((variant) => {
213
+ const variantColor = variant.color
214
+ return {
215
+ title: variantColor(variant.name),
216
+ value: variant.name
217
+ }
218
+ })
219
+ }
220
+ ],
221
+ {
222
+ onCancel: () => {
223
+ throw new Error(red('✖') + ' Operation cancelled')
224
+ }
225
+ }
226
+ )
227
+ } catch (cancelled) {
228
+ console.log(cancelled.message)
229
+ return
230
+ }
231
+
232
+ // user choice associated with prompts
233
+ const { framework, overwrite, packageName, variant } = result
234
+
235
+ const root = path.join(cwd, targetDir)
236
+
237
+ if (overwrite) {
238
+ emptyDir(root)
239
+ } else if (!fs.existsSync(root)) {
240
+ fs.mkdirSync(root, { recursive: true })
241
+ }
242
+
243
+ // determine template
244
+ template = variant || framework.name || template
245
+
246
+ console.log(`\nScaffolding project in ${root}...`)
247
+
248
+ const templateDir = path.resolve(
249
+ fileURLToPath(import.meta.url),
250
+ '..',
251
+ `template-${template}`
252
+ )
253
+
254
+ const write = (file, content) => {
255
+ const targetPath = renameFiles[file]
256
+ ? path.join(root, renameFiles[file])
257
+ : path.join(root, file)
258
+ if (content) {
259
+ fs.writeFileSync(targetPath, content)
260
+ } else {
261
+ copy(path.join(templateDir, file), targetPath)
262
+ }
263
+ }
264
+
265
+ const files = fs.readdirSync(templateDir)
266
+ for (const file of files.filter((f) => f !== 'package.json')) {
267
+ write(file)
268
+ }
269
+
270
+ const pkg = JSON.parse(
271
+ fs.readFileSync(path.join(templateDir, `package.json`), 'utf-8')
272
+ )
273
+
274
+ pkg.name = packageName || getProjectName()
275
+
276
+ write('package.json', JSON.stringify(pkg, null, 2))
277
+
278
+ const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent)
279
+ const pkgManager = pkgInfo ? pkgInfo.name : 'npm'
280
+
281
+ console.log(`\nDone. Now run:\n`)
282
+ if (root !== cwd) {
283
+ console.log(` cd ${path.relative(cwd, root)}`)
284
+ }
285
+ switch (pkgManager) {
286
+ case 'yarn':
287
+ console.log(' yarn')
288
+ console.log(' yarn dev')
289
+ break
290
+ default:
291
+ console.log(` ${pkgManager} install`)
292
+ console.log(` ${pkgManager} run dev`)
293
+ break
294
+ }
295
+ console.log()
296
+ }
297
+
298
+ /**
299
+ * @param {string | undefined} targetDir
300
+ */
301
+ function formatTargetDir(targetDir) {
302
+ return targetDir?.trim().replace(/\/+$/g, '')
303
+ }
304
+
305
+ function copy(src, dest) {
306
+ const stat = fs.statSync(src)
307
+ if (stat.isDirectory()) {
308
+ copyDir(src, dest)
309
+ } else {
310
+ fs.copyFileSync(src, dest)
311
+ }
312
+ }
313
+
314
+ /**
315
+ * @param {string} projectName
316
+ */
317
+ function isValidPackageName(projectName) {
318
+ return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
319
+ projectName
320
+ )
321
+ }
322
+
323
+ /**
324
+ * @param {string} projectName
325
+ */
326
+ function toValidPackageName(projectName) {
327
+ return projectName
328
+ .trim()
329
+ .toLowerCase()
330
+ .replace(/\s+/g, '-')
331
+ .replace(/^[._]/, '')
332
+ .replace(/[^a-z0-9-~]+/g, '-')
333
+ }
334
+
335
+ /**
336
+ * @param {string} srcDir
337
+ * @param {string} destDir
338
+ */
339
+ function copyDir(srcDir, destDir) {
340
+ fs.mkdirSync(destDir, { recursive: true })
341
+ for (const file of fs.readdirSync(srcDir)) {
342
+ const srcFile = path.resolve(srcDir, file)
343
+ const destFile = path.resolve(destDir, file)
344
+ copy(srcFile, destFile)
345
+ }
346
+ }
347
+
348
+ /**
349
+ * @param {string} path
350
+ */
351
+ function isEmpty(path) {
352
+ const files = fs.readdirSync(path)
353
+ return files.length === 0 || (files.length === 1 && files[0] === '.git')
354
+ }
355
+
356
+ /**
357
+ * @param {string} dir
358
+ */
359
+ function emptyDir(dir) {
360
+ if (!fs.existsSync(dir)) {
361
+ return
362
+ }
363
+ for (const file of fs.readdirSync(dir)) {
364
+ fs.rmSync(path.resolve(dir, file), { recursive: true, force: true })
365
+ }
366
+ }
367
+
368
+ /**
369
+ * @param {string | undefined} userAgent process.env.npm_config_user_agent
370
+ * @returns object | undefined
371
+ */
372
+ function pkgFromUserAgent(userAgent) {
373
+ if (!userAgent) return undefined
374
+ const pkgSpec = userAgent.split(' ')[0]
375
+ const pkgSpecArr = pkgSpec.split('/')
376
+ return {
377
+ name: pkgSpecArr[0],
378
+ version: pkgSpecArr[1]
379
+ }
380
+ }
381
+
382
+ init().catch((e) => {
383
+ console.error(e)
384
+ })
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "create-vite-extra",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "author": "Bjorn Lu",
7
+ "bin": {
8
+ "create-vite-extra": "index.js"
9
+ },
10
+ "files": [
11
+ "index.js",
12
+ "template-*",
13
+ "!template-*/dist",
14
+ "!template-*/node_modules",
15
+ "!template-*/pnpm-lock.yaml"
16
+ ],
17
+ "main": "index.js",
18
+ "engines": {
19
+ "node": "^14.18.0 || >=16.0.0"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/bluwy/create-vite-extra.git"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/bluwy/create-vite-extra/issues"
27
+ },
28
+ "homepage": "https://github.com/bluwy/create-vite-extra#readme",
29
+ "dependencies": {
30
+ "kolorist": "^1.5.1",
31
+ "minimist": "^1.2.6",
32
+ "prompts": "^2.4.2"
33
+ }
34
+ }
@@ -0,0 +1,24 @@
1
+ # Logs
2
+ logs
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ pnpm-debug.log*
8
+ lerna-debug.log*
9
+
10
+ node_modules
11
+ dist
12
+ dist-ssr
13
+ *.local
14
+
15
+ # Editor directories and files
16
+ .vscode/*
17
+ !.vscode/extensions.json
18
+ .idea
19
+ .DS_Store
20
+ *.suo
21
+ *.ntvs*
22
+ *.njsproj
23
+ *.sln
24
+ *.sw?
@@ -0,0 +1 @@
1
+ export function setupCounter(element: HTMLButtonElement): void
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Vite App</title>
8
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script type="module" src="/main.js"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="32" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path fill="#F7DF1E" d="M0 0h256v256H0V0Z"></path><path d="m67.312 213.932l19.59-11.856c3.78 6.701 7.218 12.371 15.465 12.371c7.905 0 12.89-3.092 12.89-15.12v-81.798h24.057v82.138c0 24.917-14.606 36.259-35.916 36.259c-19.245 0-30.416-9.967-36.087-21.996m85.07-2.576l19.588-11.341c5.157 8.421 11.859 14.607 23.715 14.607c9.969 0 16.325-4.984 16.325-11.858c0-8.248-6.53-11.17-17.528-15.98l-6.013-2.58c-17.357-7.387-28.87-16.667-28.87-36.257c0-18.044 13.747-31.792 35.228-31.792c15.294 0 26.292 5.328 34.196 19.247l-18.732 12.03c-4.125-7.389-8.591-10.31-15.465-10.31c-7.046 0-11.514 4.468-11.514 10.31c0 7.217 4.468 10.14 14.778 14.608l6.014 2.577c20.45 8.765 31.963 17.7 31.963 37.804c0 21.654-17.012 33.51-39.867 33.51c-22.339 0-36.774-10.654-43.819-24.574"></path></svg>
@@ -0,0 +1,9 @@
1
+ export function setupCounter(element) {
2
+ let counter = 0
3
+ const setCounter = (count) => {
4
+ counter = count
5
+ element.innerHTML = `count is ${counter}`
6
+ }
7
+ element.addEventListener('click', () => setCounter(++counter))
8
+ setCounter(0)
9
+ }
@@ -0,0 +1,23 @@
1
+ import './style.css'
2
+ import javascriptLogo from './javascript.svg'
3
+ import { setupCounter } from './lib/main.js'
4
+
5
+ document.querySelector('#app').innerHTML = `
6
+ <div>
7
+ <a href="https://vitejs.dev" target="_blank">
8
+ <img src="/vite.svg" class="logo" alt="Vite logo" />
9
+ </a>
10
+ <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" target="_blank">
11
+ <img src="${javascriptLogo}" class="logo vanilla" alt="JavaScript logo" />
12
+ </a>
13
+ <h1>Hello Vite!</h1>
14
+ <div class="card">
15
+ <button id="counter" type="button"></button>
16
+ </div>
17
+ <p class="read-the-docs">
18
+ Click on the Vite logo to learn more
19
+ </p>
20
+ </div>
21
+ `
22
+
23
+ setupCounter(document.querySelector('#counter'))
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "vite-starter",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "files": ["dist", "index.d.ts"],
7
+ "main": "./dist/counter.umd.cjs",
8
+ "module": "./dist/counter.js",
9
+ "types": "./index.d.ts",
10
+ "exports": {
11
+ "types": "./index.d.ts",
12
+ "import": "./dist/counter.js",
13
+ "require": "./dist/counter.umd.cjs"
14
+ },
15
+ "scripts": {
16
+ "dev": "vite",
17
+ "build": "vite build"
18
+ },
19
+ "devDependencies": {
20
+ "vite": "^3.0.1"
21
+ }
22
+ }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>