stacks 0.0.9 → 0.37.3

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 (219) hide show
  1. package/.gitignore +10 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +65 -104
  4. package/auto-imports.d.ts +826 -0
  5. package/bin/stacks.mjs +4 -0
  6. package/components.d.ts +22 -0
  7. package/core/actions/README.md +59 -0
  8. package/core/actions/node_modules/.bin/markdown-it +17 -0
  9. package/core/actions/node_modules/.bin/mkdist +17 -0
  10. package/core/actions/node_modules/.bin/tsc +17 -0
  11. package/core/actions/node_modules/.bin/tsserver +17 -0
  12. package/core/actions/package.json +64 -0
  13. package/core/actions/src/copy-types.ts +22 -0
  14. package/core/actions/src/generate/component-meta.ts +94 -0
  15. package/core/actions/src/generate/index.ts +4 -0
  16. package/core/actions/src/generate/lib-entries.ts +106 -0
  17. package/core/actions/src/generate/package-json.ts +87 -0
  18. package/core/actions/src/generate/vscode-custom-data.ts +28 -0
  19. package/core/actions/src/generate/vue-compat.ts +17 -0
  20. package/core/actions/src/generate-component-meta.ts +19 -0
  21. package/core/actions/src/generate-ide-helpers.ts +23 -0
  22. package/core/actions/src/generate-lib-entries.ts +22 -0
  23. package/core/actions/src/generate-package-json.ts +15 -0
  24. package/core/actions/src/generate-vscode-custom-data.ts +20 -0
  25. package/core/actions/src/generate-vue-compat.ts +10 -0
  26. package/core/arrays/README.md +59 -0
  27. package/core/arrays/node_modules/.bin/mkdist +17 -0
  28. package/core/arrays/node_modules/.bin/tsc +17 -0
  29. package/core/arrays/node_modules/.bin/tsserver +17 -0
  30. package/core/arrays/package.json +50 -0
  31. package/core/arrays/src/index.ts +3 -0
  32. package/core/build/README.md +59 -0
  33. package/core/build/entries/README.md +7 -0
  34. package/core/build/node_modules/.bin/acorn +17 -0
  35. package/core/build/node_modules/.bin/browserslist +17 -0
  36. package/core/build/node_modules/.bin/jiti +17 -0
  37. package/core/build/node_modules/.bin/mkdist +17 -0
  38. package/core/build/node_modules/.bin/rollup +17 -0
  39. package/core/build/node_modules/.bin/vite +17 -0
  40. package/core/build/node_modules/.bin/vite-ssg +17 -0
  41. package/core/build/node_modules/.bin/vue-docgen-web-types +17 -0
  42. package/core/build/package.json +71 -0
  43. package/core/build/src/example-vue.ts +26 -0
  44. package/core/build/src/example-wc.ts +26 -0
  45. package/core/build/src/functions.ts +56 -0
  46. package/core/build/src/index.ts +7 -0
  47. package/core/build/src/pages.ts +50 -0
  48. package/core/build/src/stacks.ts +204 -0
  49. package/core/build/src/vue-components.ts +76 -0
  50. package/core/build/src/web-components.ts +63 -0
  51. package/core/build/web-types.config.cjs +4 -0
  52. package/core/build/web-types.ts +14 -0
  53. package/core/collections/README.md +59 -0
  54. package/core/collections/node_modules/.bin/mkdist +17 -0
  55. package/core/collections/node_modules/.bin/tsc +17 -0
  56. package/core/collections/node_modules/.bin/tsserver +17 -0
  57. package/core/collections/package.json +54 -0
  58. package/core/collections/src/index.ts +1 -0
  59. package/core/fs/README.md +59 -0
  60. package/core/fs/node_modules/.bin/mkdist +17 -0
  61. package/core/fs/package.json +56 -0
  62. package/core/fs/src/index.ts +170 -0
  63. package/core/helpers/node_modules/.bin/mkdist +17 -0
  64. package/core/helpers/package.json +58 -0
  65. package/core/helpers/src/index.ts +129 -0
  66. package/core/modules/README.md +61 -0
  67. package/core/modules/node_modules/.bin/acorn +17 -0
  68. package/core/modules/node_modules/.bin/mkdist +17 -0
  69. package/core/modules/package.json +51 -0
  70. package/core/modules/src/i18n.ts +23 -0
  71. package/core/modules/src/nprogress.ts +12 -0
  72. package/core/modules/src/pwa.ts +12 -0
  73. package/core/objects/README.md +59 -0
  74. package/core/objects/node_modules/.bin/mkdist +17 -0
  75. package/core/objects/node_modules/.bin/tsc +17 -0
  76. package/core/objects/node_modules/.bin/tsserver +17 -0
  77. package/core/objects/package.json +51 -0
  78. package/core/objects/src/index.ts +1 -0
  79. package/core/paths/node_modules/.bin/mkdist +17 -0
  80. package/core/paths/node_modules/.bin/tsc +17 -0
  81. package/core/paths/node_modules/.bin/tsserver +17 -0
  82. package/core/paths/package.json +51 -0
  83. package/core/paths/src/index.ts +178 -0
  84. package/core/router/README.md +59 -0
  85. package/core/router/node_modules/.bin/mkdist +17 -0
  86. package/core/router/package.json +51 -0
  87. package/core/router/src/index.ts +14 -0
  88. package/core/security/README.md +59 -0
  89. package/core/security/node_modules/.bin/mkdist +17 -0
  90. package/core/security/package.json +56 -0
  91. package/core/security/src/crypt.ts +14 -0
  92. package/core/security/src/hash.ts +52 -0
  93. package/core/security/src/index.ts +3 -0
  94. package/core/security/src/key.ts +11 -0
  95. package/core/strings/README.md +59 -0
  96. package/core/strings/node_modules/.bin/mkdist +17 -0
  97. package/core/strings/node_modules/.bin/tsc +17 -0
  98. package/core/strings/node_modules/.bin/tsserver +17 -0
  99. package/core/strings/package.json +63 -0
  100. package/core/strings/src/index.ts +14 -0
  101. package/core/types/README.md +59 -0
  102. package/core/types/node_modules/.bin/markdown-it +17 -0
  103. package/core/types/node_modules/.bin/mkdist +17 -0
  104. package/core/types/node_modules/.bin/vite +17 -0
  105. package/core/types/node_modules/.bin/vitepress +17 -0
  106. package/core/types/package.json +60 -0
  107. package/core/types/src/app.ts +131 -0
  108. package/core/types/src/auto-imports.ts +3 -0
  109. package/core/types/src/build.ts +3 -0
  110. package/core/types/src/cli.ts +49 -0
  111. package/core/types/src/components.ts +66 -0
  112. package/core/types/src/deploy.ts +11 -0
  113. package/core/types/src/docs.ts +3 -0
  114. package/core/types/src/exit-code.ts +10 -0
  115. package/core/types/src/fs.ts +17 -0
  116. package/core/types/src/git.ts +131 -0
  117. package/core/types/src/hashing.ts +107 -0
  118. package/core/types/src/i18n.ts +19 -0
  119. package/core/types/src/index.ts +21 -0
  120. package/core/types/src/inspect.ts +10 -0
  121. package/core/types/src/layout.ts +8 -0
  122. package/core/types/src/library.ts +148 -0
  123. package/core/types/src/manifest.ts +9 -0
  124. package/core/types/src/markdown.ts +198 -0
  125. package/core/types/src/pages.ts +8 -0
  126. package/core/types/src/pwa.ts +8 -0
  127. package/core/types/src/ssg.ts +3 -0
  128. package/core/types/src/ui.ts +141 -0
  129. package/core/ui/README.md +60 -0
  130. package/core/ui/node_modules/.bin/mkdist +17 -0
  131. package/core/ui/node_modules/.bin/tsc +17 -0
  132. package/core/ui/node_modules/.bin/tsserver +17 -0
  133. package/core/ui/node_modules/.bin/vite +17 -0
  134. package/core/ui/node_modules/.bin/vue-tsc +17 -0
  135. package/core/ui/package.json +62 -0
  136. package/core/ui/src/index.ts +60 -0
  137. package/custom-elements.json +14 -0
  138. package/examples/vue-components/App.vue +12 -0
  139. package/examples/vue-components/favicon.png +0 -0
  140. package/examples/vue-components/index.html +20 -0
  141. package/examples/web-components/favicon.png +0 -0
  142. package/examples/web-components/index.html +13 -0
  143. package/functions/node_modules/.bin/artisan +17 -0
  144. package/functions/node_modules/.bin/stacks +17 -0
  145. package/functions/node_modules/.bin/stx +17 -0
  146. package/functions/package.json +40 -0
  147. package/netlify.toml +18 -0
  148. package/nitro.config.ts +6 -0
  149. package/package.json +224 -27
  150. package/pages/App.vue +26 -0
  151. package/pages/index.html +23 -0
  152. package/pages/main.ts +26 -0
  153. package/pages/public/_headers +3 -0
  154. package/pages/public/favicon-dark.svg +3 -0
  155. package/pages/public/favicon.svg +3 -0
  156. package/pages/public/pwa-192x192.png +0 -0
  157. package/pages/public/pwa-512x512.png +0 -0
  158. package/pages/public/safari-pinned-tab.svg +41 -0
  159. package/pages/styles/main.css +29 -0
  160. package/pages/styles/markdown.css +28 -0
  161. package/scripts/ensure-env.sh +248 -0
  162. package/shims.d.ts +29 -0
  163. package/simple-git-hooks.cjs +4 -0
  164. package/src/cli/actions/build.ts +160 -0
  165. package/src/cli/actions/commit.ts +9 -0
  166. package/src/cli/actions/dev.ts +47 -0
  167. package/src/cli/actions/examples.ts +74 -0
  168. package/src/cli/actions/fresh.ts +9 -0
  169. package/src/cli/actions/generate.ts +159 -0
  170. package/src/cli/actions/index.ts +12 -0
  171. package/src/cli/actions/key.ts +31 -0
  172. package/src/cli/actions/lint.ts +19 -0
  173. package/src/cli/actions/make.ts +116 -0
  174. package/src/cli/actions/release.ts +9 -0
  175. package/src/cli/actions/test.ts +39 -0
  176. package/src/cli/actions/types.ts +180 -0
  177. package/src/cli/actions/update.ts +90 -0
  178. package/src/cli/build.ts +49 -0
  179. package/src/cli/create.ts +71 -0
  180. package/src/cli/dev.ts +28 -0
  181. package/src/cli/example.ts +28 -0
  182. package/src/cli/generate.ts +64 -0
  183. package/src/cli/index.ts +13 -0
  184. package/src/cli/key.ts +12 -0
  185. package/src/cli/make.ts +47 -0
  186. package/src/cli/test.ts +24 -0
  187. package/src/cli/types.ts +18 -0
  188. package/src/cli/update.ts +17 -0
  189. package/src/cli/utility.ts +39 -0
  190. package/src/cli.ts +48 -0
  191. package/src/docs.ts +4 -0
  192. package/src/index.ts +22 -0
  193. package/tsconfig.json +96 -0
  194. package/vitest.config.ts +22 -0
  195. package/vue-components/dist/.gitkeep +0 -0
  196. package/vue-components/index.html +13 -0
  197. package/vue-components/main.ts +18 -0
  198. package/vue-components/node_modules/.bin/artisan +17 -0
  199. package/vue-components/node_modules/.bin/stacks +17 -0
  200. package/vue-components/node_modules/.bin/stx +17 -0
  201. package/vue-components/node_modules/.vite/deps/@vueuse_core.js +7847 -0
  202. package/vue-components/node_modules/.vite/deps/@vueuse_core.js.map +7 -0
  203. package/vue-components/node_modules/.vite/deps/_metadata.json +13 -0
  204. package/vue-components/node_modules/.vite/deps/package.json +1 -0
  205. package/vue-components/package.json +40 -0
  206. package/web-components/dist/.gitkeep +0 -0
  207. package/web-components/node_modules/.bin/artisan +17 -0
  208. package/web-components/node_modules/.bin/stacks +17 -0
  209. package/web-components/node_modules/.bin/stx +17 -0
  210. package/web-components/package.json +40 -0
  211. package/web-types.json +67 -0
  212. package/.npmignore +0 -1
  213. package/.travis.yml +0 -4
  214. package/examples/stringReverse.js +0 -41
  215. package/examples/sumServer.js +0 -21
  216. package/examples/sumWorker.js +0 -23
  217. package/index.js +0 -1
  218. package/lib/stacks.js +0 -398
  219. package/test/test.stacks.js +0 -148
@@ -0,0 +1,159 @@
1
+ import consola from 'consola'
2
+ import Prompts from 'prompts'
3
+ import { runNpmScript } from '@stacksjs/helpers'
4
+ import { ExitCode, NpmScript } from '@stacksjs/types'
5
+ import { lintFix } from './lint'
6
+ import { generateTypes } from './types'
7
+
8
+ const { prompts } = Prompts
9
+
10
+ export async function generateLibEntries() {
11
+ try {
12
+ await runNpmScript(NpmScript.GenerateEntries, 'ignore')
13
+ consola.success('Library entry points were generated successfully.')
14
+ }
15
+ catch (error) {
16
+ consola.error('There was an error generating your library entry points.')
17
+ consola.error(error)
18
+ }
19
+ }
20
+
21
+ export async function generateVueCompat() {
22
+ try {
23
+ await runNpmScript(NpmScript.GenerateVueCompat, 'ignore')
24
+ consola.success('Vue 2 & 3 compatibility was generated successfully.')
25
+ }
26
+ catch (error) {
27
+ consola.error('There was an error generating Vue compatibility.')
28
+ consola.error(error)
29
+ }
30
+ }
31
+
32
+ export async function generateWebTypes() {
33
+ try {
34
+ await runNpmScript(NpmScript.GenerateWebTypes, 'ignore')
35
+ consola.success('Successfully generated the web-types.json file.')
36
+ }
37
+ catch (error) {
38
+ consola.error('There was an error generating the web-types.json file')
39
+ consola.error(error)
40
+ process.exit(ExitCode.FatalError)
41
+ }
42
+ }
43
+
44
+ export async function generateVsCodeCustomData() {
45
+ try {
46
+ await runNpmScript(NpmScript.GenerateVsCodeCustomData, 'ignore')
47
+ await lintFix('ignore') // the created json file needs to be linted
48
+ consola.success('Successfully generated the custom-elements.json file.')
49
+ }
50
+ catch (error) {
51
+ consola.error('There was an error generating the custom-elements.json file')
52
+ consola.error(error)
53
+ process.exit(ExitCode.FatalError)
54
+ }
55
+ }
56
+
57
+ export async function generateIdeHelpers() {
58
+ try {
59
+ await runNpmScript(NpmScript.GenerateIdeHelpers, 'ignore')
60
+ await lintFix('ignore') // the created json file needs to be linted
61
+ consola.success('Successfully generated IDE helpers.')
62
+ }
63
+ catch (error) {
64
+ consola.error('There was an error generating IDE helpers.')
65
+ consola.error(error)
66
+ process.exit(ExitCode.FatalError)
67
+ }
68
+ }
69
+
70
+ export async function generateComponentMeta() {
71
+ try {
72
+ await runNpmScript(NpmScript.GenerateComponentMeta, 'ignore')
73
+ await lintFix('ignore') // the created json file needs to be linted
74
+ consola.success('Successfully generated component meta.')
75
+ }
76
+ catch (error) {
77
+ consola.error('There was an error generating your component meta information.')
78
+ consola.error(error)
79
+ process.exit(ExitCode.FatalError)
80
+ }
81
+ }
82
+
83
+ export async function startGenerationProcess(options: any) {
84
+ if (options.types || options === 'types') {
85
+ await generateTypes()
86
+ }
87
+
88
+ else if (options.entries || options === 'entries') {
89
+ await generateLibEntries()
90
+ }
91
+
92
+ else if (options.webTypes || options === 'web-types') {
93
+ await generateWebTypes()
94
+ }
95
+
96
+ else if (options.customData || options === 'custom-data') {
97
+ await generateVsCodeCustomData()
98
+ }
99
+
100
+ else if (options.ideHelpers || options === 'ide-helpers') {
101
+ await generateIdeHelpers()
102
+ }
103
+
104
+ else if (options.vueCompatibility || options === 'vue-compatibility') {
105
+ await generateVueCompat()
106
+ }
107
+
108
+ else if (options.componentMeta || options === 'component-meta') {
109
+ await generateComponentMeta()
110
+ }
111
+
112
+ else {
113
+ const answer = await prompts.select({
114
+ type: 'select',
115
+ name: 'generate',
116
+ message: 'What are you trying to generate?',
117
+ choices: [ // todo: should be a multi-select
118
+ { title: '1.) TypeScript Types', value: 'types' },
119
+ { title: '2.) Library Entry Points', value: 'entries' },
120
+ { title: '3.) Web Types', value: 'web-types' },
121
+ { title: '4.) VS Code Custom Data', value: 'custom-data' },
122
+ { title: '5.) IDE Helpers', value: 'ide-helpers' },
123
+ { title: '6.) Vue 2 & 3 Compatibility', value: 'vue-compatibility' },
124
+ { title: '7.) Component Meta', value: 'component-meta' },
125
+ ],
126
+ initial: 0,
127
+ })
128
+
129
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
130
+ if (answer === 'types')
131
+ await generateTypes()
132
+
133
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
134
+ else if (answer === 'entries')
135
+ await generateLibEntries()
136
+
137
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
138
+ else if (answer === 'web-types')
139
+ await generateWebTypes()
140
+
141
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
142
+ else if (answer === 'custom-data')
143
+ await generateVsCodeCustomData()
144
+
145
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
146
+ else if (answer === 'ide-helpers')
147
+ await generateIdeHelpers()
148
+
149
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
150
+ else if (answer === 'vue-compatibility')
151
+ await generateVueCompat()
152
+
153
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
154
+ else if (answer === 'component-meta')
155
+ await generateComponentMeta()
156
+
157
+ else process.exit(ExitCode.InvalidArgument)
158
+ }
159
+ }
@@ -0,0 +1,12 @@
1
+ export * from './build'
2
+ export * from './commit'
3
+ export * from './dev'
4
+ export * from './examples'
5
+ export * from './fresh'
6
+ export * from './generate'
7
+ export * from './key'
8
+ export * from './lint'
9
+ export * from './make'
10
+ export * from './release'
11
+ export * from './test'
12
+ export * from './update'
@@ -0,0 +1,31 @@
1
+ import { getRandomValues } from 'node:crypto'
2
+ import consola from 'consola'
3
+ import ezSpawn from '@jsdevtools/ez-spawn'
4
+ // import { generateAppKey } from '@stacksjs/security'
5
+ import { projectPath } from '@stacksjs/paths'
6
+ import { setEnvValue } from '@stacksjs/helpers'
7
+ import { isFile } from '@stacksjs/fs'
8
+ import utf8 from 'crypto-js/enc-utf8'
9
+ import base64 from 'crypto-js/enc-base64'
10
+
11
+ export async function generateAppKey() {
12
+ const random = getRandomValues(new Uint8Array(32))
13
+ const encodedWord = utf8.parse(random.toString())
14
+ const key = base64.stringify(encodedWord)
15
+
16
+ return `base64:${key}`
17
+ }
18
+
19
+ export async function generate() {
20
+ consola.info('Setting random application key.')
21
+
22
+ // if the .env file does not exist, ensure it is created
23
+ if (!isFile('.env'))
24
+ await ezSpawn.async('cp .env.example .env', { stdio: 'inherit', cwd: projectPath() })
25
+
26
+ await setEnvValue('APP_KEY', await generateAppKey())
27
+
28
+ consola.success('Application key set.')
29
+
30
+ return true
31
+ }
@@ -0,0 +1,19 @@
1
+ import consola from 'consola'
2
+ import { runNpmScript } from '@stacksjs/helpers'
3
+ import { NpmScript } from '@stacksjs/types'
4
+
5
+ export async function lint(debug: 'ignore' | 'inherit' = 'inherit') {
6
+ consola.info('Linting your codebase...')
7
+ await runNpmScript(NpmScript.Lint, debug)
8
+ consola.success('Successfully linted your codebase.')
9
+ }
10
+
11
+ export async function lintFix(debug: 'ignore' | 'inherit' = 'inherit') {
12
+ if (debug !== 'ignore')
13
+ consola.info('Fixing lint errors...')
14
+
15
+ await runNpmScript(NpmScript.LintFix, debug)
16
+
17
+ if (debug !== 'ignore')
18
+ consola.success('Fixed lint errors.')
19
+ }
@@ -0,0 +1,116 @@
1
+ import consola from 'consola'
2
+ import * as ezSpawn from '@jsdevtools/ez-spawn'
3
+ import { writeTextFile } from '@stacksjs/fs'
4
+ import { resolve } from '@stacksjs/paths'
5
+
6
+ export async function component(name: string) {
7
+ consola.info('Creating your component...')
8
+
9
+ try {
10
+ await writeTextFile({
11
+ path: `./components/${name}.vue`,
12
+ data: `<script setup lang="ts">
13
+ // eslint-disable-next-line no-console
14
+ console.log('Hello World component created')
15
+ </script>
16
+
17
+ <template>
18
+ <div>
19
+ Some HTML block
20
+ </div>
21
+ </template>
22
+ `,
23
+ })
24
+
25
+ consola.success(`Created the ${name} component.`)
26
+ }
27
+ catch (err) {
28
+ consola.error(err)
29
+ }
30
+ }
31
+
32
+ export async function page(name: string) {
33
+ consola.info('Creating your component...')
34
+
35
+ try {
36
+ await writeTextFile({
37
+ path: `./pages/${name}.vue`,
38
+ data: `<script setup lang="ts">
39
+ // eslint-disable-next-line no-console
40
+ console.log('Hello World page created')
41
+ </script>
42
+
43
+ <template>
44
+ <div>
45
+ Visit http://127.0.0.1/${name}
46
+ </div>
47
+ </template>
48
+ `,
49
+ })
50
+
51
+ consola.success(`Created the ${name} page.`)
52
+ }
53
+ catch (err) {
54
+ consola.error(err)
55
+ }
56
+ }
57
+
58
+ export async function fx(name: string) {
59
+ consola.info('Creating your function...')
60
+
61
+ try {
62
+ await writeTextFile({
63
+ path: `./functions/${name}.ts`,
64
+ data: `// reactive state
65
+ const ${name} = ref(0)
66
+
67
+ // functions that mutate state and trigger updates
68
+ function increment() {
69
+ ${name}.value++
70
+ }
71
+
72
+ export {
73
+ ${name},
74
+ increment,
75
+ }
76
+ `,
77
+ })
78
+
79
+ consola.success(`Created the ${name} function.`)
80
+ }
81
+ catch (err) {
82
+ consola.error(err)
83
+ }
84
+ }
85
+
86
+ export async function language(language: string) {
87
+ consola.info('Creating your translation file...')
88
+
89
+ try {
90
+ await writeTextFile({
91
+ path: `./lang/${language}.yml`,
92
+ data: `button:
93
+ text: Copy
94
+ `,
95
+ })
96
+
97
+ consola.success(`Created the ${language} translation file.`)
98
+ }
99
+ catch (err) {
100
+ consola.error(err)
101
+ }
102
+ }
103
+
104
+ export async function stack(name: string) {
105
+ consola.info('Creating your stack...')
106
+
107
+ try {
108
+ const path = resolve(process.cwd(), name)
109
+ await ezSpawn.async(`giget stacks ${path}`)
110
+ consola.success('Successfully scaffolded your project.')
111
+ consola.info(`cd ${path} && pnpm install`)
112
+ }
113
+ catch (err) {
114
+ consola.error(err)
115
+ }
116
+ }
@@ -0,0 +1,9 @@
1
+ import consola from 'consola'
2
+ import { runNpmScript } from '@stacksjs/helpers'
3
+ import { NpmScript } from '@stacksjs/types'
4
+
5
+ export async function release() {
6
+ consola.info('Releasing...')
7
+ await runNpmScript(NpmScript.Release)
8
+ consola.success('Triggered release workflow')
9
+ }
@@ -0,0 +1,39 @@
1
+ import consola from 'consola'
2
+ import { runNpmScript } from '@stacksjs/helpers'
3
+ import { NpmScript } from '@stacksjs/types'
4
+
5
+ export async function typecheck() {
6
+ consola.info('Typechecking your codebase...')
7
+
8
+ try {
9
+ await runNpmScript(NpmScript.TestTypes)
10
+ consola.success('Finished typechecking your codebase.')
11
+ }
12
+ catch (error) {
13
+ consola.error(error)
14
+ }
15
+ }
16
+
17
+ export async function runTestSuite() {
18
+ consola.info('Running your test suite...')
19
+
20
+ try {
21
+ await runNpmScript(NpmScript.Test)
22
+ consola.success('Completed running the test suite.')
23
+ }
24
+ catch (error) {
25
+ consola.error(error)
26
+ }
27
+ }
28
+
29
+ export async function generateTestCoverageReport() {
30
+ consola.info('Generating a test coverage report...')
31
+
32
+ try {
33
+ await runNpmScript(NpmScript.TestCoverage)
34
+ consola.success('Generated the test coverage report.')
35
+ }
36
+ catch (error) {
37
+ consola.error(error)
38
+ }
39
+ }
@@ -0,0 +1,180 @@
1
+ import consola from 'consola'
2
+ import Prompts from 'prompts'
3
+ import { runNpmScript } from '@stacksjs/helpers'
4
+ import { ExitCode, NpmScript } from '@stacksjs/types'
5
+ import { lintFix } from './lint'
6
+
7
+ const { prompts } = Prompts
8
+
9
+ export async function generateTypes() {
10
+ try {
11
+ await runNpmScript(NpmScript.TypesGenerate, 'ignore')
12
+ consola.success('Types were generated successfully.')
13
+ }
14
+ catch (error) {
15
+ consola.error('There was an error generating your types.')
16
+ consola.error(error)
17
+ }
18
+ }
19
+
20
+ export async function fixTypes() {
21
+ try {
22
+ await runNpmScript(NpmScript.TypesFix, 'ignore')
23
+ consola.success('Types were generated successfully.')
24
+ }
25
+ catch (error) {
26
+ consola.error('There was an error generating your types.')
27
+ consola.error(error)
28
+ }
29
+ }
30
+
31
+ export async function generateLibEntries() {
32
+ try {
33
+ await runNpmScript(NpmScript.GenerateEntries, 'ignore')
34
+ consola.success('Library entry points were generated successfully.')
35
+ }
36
+ catch (error) {
37
+ consola.error('There was an error generating your library entry points.')
38
+ consola.error(error)
39
+ }
40
+ }
41
+
42
+ export async function generateVueCompat() {
43
+ try {
44
+ await runNpmScript(NpmScript.GenerateVueCompat, 'ignore')
45
+ consola.success('Vue 2 & 3 compatibility was generated successfully.')
46
+ }
47
+ catch (error) {
48
+ consola.error('There was an error generating Vue compatibility.')
49
+ consola.error(error)
50
+ }
51
+ }
52
+
53
+ export async function generateWebTypes() {
54
+ try {
55
+ await runNpmScript(NpmScript.GenerateWebTypes, 'ignore')
56
+ consola.success('Successfully generated the web-types.json file.')
57
+ }
58
+ catch (error) {
59
+ consola.error('There was an error generating the web-types.json file')
60
+ consola.error(error)
61
+ process.exit(ExitCode.FatalError)
62
+ }
63
+ }
64
+
65
+ export async function generateVsCodeCustomData() {
66
+ try {
67
+ await runNpmScript(NpmScript.GenerateVsCodeCustomData, 'ignore')
68
+ await lintFix('ignore') // the created json file needs to be linted
69
+ consola.success('Successfully generated the custom-elements.json file.')
70
+ }
71
+ catch (error) {
72
+ consola.error('There was an error generating the custom-elements.json file')
73
+ consola.error(error)
74
+ process.exit(ExitCode.FatalError)
75
+ }
76
+ }
77
+
78
+ export async function generateIdeHelpers() {
79
+ try {
80
+ await runNpmScript(NpmScript.GenerateIdeHelpers, 'ignore')
81
+ await lintFix('ignore') // the created json file needs to be linted
82
+ consola.success('Successfully generated IDE helpers.')
83
+ }
84
+ catch (error) {
85
+ consola.error('There was an error generating IDE helpers.')
86
+ consola.error(error)
87
+ process.exit(ExitCode.FatalError)
88
+ }
89
+ }
90
+
91
+ export async function generateComponentMeta() {
92
+ try {
93
+ await runNpmScript(NpmScript.GenerateComponentMeta, 'ignore')
94
+ await lintFix('ignore') // the created json file needs to be linted
95
+ consola.success('Successfully generated component meta.')
96
+ }
97
+ catch (error) {
98
+ consola.error('There was an error generating your component meta information.')
99
+ consola.error(error)
100
+ process.exit(ExitCode.FatalError)
101
+ }
102
+ }
103
+
104
+ export async function startGenerationProcess(options: any) {
105
+ if (options.types || options === 'types') {
106
+ await generateTypes()
107
+ }
108
+
109
+ else if (options.entries || options === 'entries') {
110
+ await generateLibEntries()
111
+ }
112
+
113
+ else if (options.webTypes || options === 'web-types') {
114
+ await generateWebTypes()
115
+ }
116
+
117
+ else if (options.customData || options === 'custom-data') {
118
+ await generateVsCodeCustomData()
119
+ }
120
+
121
+ else if (options.ideHelpers || options === 'ide-helpers') {
122
+ await generateIdeHelpers()
123
+ }
124
+
125
+ else if (options.vueCompatibility || options === 'vue-compatibility') {
126
+ await generateVueCompat()
127
+ }
128
+
129
+ else if (options.componentMeta || options === 'component-meta') {
130
+ await generateComponentMeta()
131
+ }
132
+
133
+ else {
134
+ const answer = await prompts.select({
135
+ type: 'select',
136
+ name: 'generate',
137
+ message: 'What are you trying to generate?',
138
+ choices: [ // todo: should be a multi-select
139
+ { title: '1.) TypeScript Types', value: 'types' },
140
+ { title: '2.) Library Entry Points', value: 'entries' },
141
+ { title: '3.) Web Types', value: 'web-types' },
142
+ { title: '4.) VS Code Custom Data', value: 'custom-data' },
143
+ { title: '5.) IDE Helpers', value: 'ide-helpers' },
144
+ { title: '6.) Vue 2 & 3 Compatibility', value: 'vue-compatibility' },
145
+ { title: '7.) Component Meta', value: 'component-meta' },
146
+ ],
147
+ initial: 0,
148
+ })
149
+
150
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
151
+ if (answer === 'types')
152
+ await generateTypes()
153
+
154
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
155
+ else if (answer === 'entries')
156
+ await generateLibEntries()
157
+
158
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
159
+ else if (answer === 'web-types')
160
+ await generateWebTypes()
161
+
162
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
163
+ else if (answer === 'custom-data')
164
+ await generateVsCodeCustomData()
165
+
166
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
167
+ else if (answer === 'ide-helpers')
168
+ await generateIdeHelpers()
169
+
170
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
171
+ else if (answer === 'vue-compatibility')
172
+ await generateVueCompat()
173
+
174
+ // @ts-expect-error the answer object type expects to return a void type but it returns a string
175
+ else if (answer === 'component-meta')
176
+ await generateComponentMeta()
177
+
178
+ else process.exit(ExitCode.InvalidArgument)
179
+ }
180
+ }
@@ -0,0 +1,90 @@
1
+ import * as ezSpawn from '@jsdevtools/ez-spawn'
2
+ import consola from 'consola'
3
+ import Prompts from 'prompts'
4
+ import { copyFolder, deleteEmptyFolders, deleteFiles, deleteFolder, doesFolderExist } from '@stacksjs/fs'
5
+ import { resolve } from '@stacksjs/paths'
6
+ import { runNpmScript } from '@stacksjs/helpers'
7
+ import { ExitCode, NpmScript } from '@stacksjs/types'
8
+
9
+ const { prompts } = Prompts
10
+
11
+ export async function stacks(options: any) {
12
+ // first, we need to update the framework, if updates available
13
+ // TODO: need to delete all files except the whitelisted ones
14
+ if (options.framework) {
15
+ try {
16
+ // check if the .stacks folder has any updates
17
+ // https://carlosbecker.com/posts/git-changed/
18
+ await ezSpawn.async('git diff --quiet HEAD -- ./.stacks', { stdio: 'inherit', cwd: process.cwd() })
19
+ }
20
+ catch (error: any) {
21
+ if (error.status === 1) {
22
+ // even though the ./.stacks folder should not be edited, instead config values should be adjusted,
23
+ // there is a chance that users may apply local core edits, as it's totally acceptable, as long as
24
+ // the user knows what they are doing. There is also a change that simply the deps within .stacks
25
+ // folder have been updated and that could produce a diff.
26
+ if (!options.force) {
27
+ const answer = await prompts.confirm({
28
+ type: 'select',
29
+ name: 'framework-update',
30
+ message: 'Would you like to overwrite your ./stacks changes in favor of the Stacks update?',
31
+ })
32
+
33
+ // @ts-expect-error the answer object type expects to return a void type but it returns boolean
34
+ if (!answer) {
35
+ consola.info('The framework was not updated.')
36
+ consola.info('Note: if you commit your changes and replay the update, you will see what has changed.')
37
+ process.exit(ExitCode.Success)
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ consola.info('Downloading framework updates...')
44
+
45
+ const tempFolderName = 'updates'
46
+ const tempUpdatePath = resolve(process.cwd(), tempFolderName)
47
+ if (doesFolderExist(tempUpdatePath))
48
+ await deleteFolder(tempUpdatePath)
49
+
50
+ await ezSpawn.async(`giget stacks ${tempFolderName}`, { stdio: options.debug ? 'inherit' : 'ignore' }) // TODO: stdio should inherit when APP_DEBUG or debug flag is true
51
+ consola.success('Downloaded framework updates.')
52
+
53
+ consola.info('Updating framework...')
54
+
55
+ const frameworkPath = resolve(process.cwd(), '.stacks')
56
+ const exclude = ['functions/package.json', 'vue-components/package.json', 'web-components/package.json', 'auto-imports.d.ts', 'components.d.ts', 'dist']
57
+
58
+ await deleteFiles(frameworkPath, exclude)
59
+
60
+ // loop 5 times to make sure all "deep empty" folders are deleted
61
+ for (let i = 0; i < 5; i++)
62
+ await deleteEmptyFolders(frameworkPath)
63
+
64
+ const from = resolve(process.cwd(), './updates/.stacks')
65
+ const to = frameworkPath
66
+ await copyFolder(from, to, exclude)
67
+
68
+ consola.info('Cleanup...')
69
+ await deleteFolder(tempUpdatePath)
70
+ consola.success('Framework updated.')
71
+ }
72
+
73
+ // then, we need to update the project's & framework's dependencies, if updates available
74
+ if (options.dependencies) {
75
+ consola.info('Updating dependencies...')
76
+ await runNpmScript(NpmScript.Update)
77
+ consola.success('Updated dependencies.')
78
+ }
79
+
80
+ if (options.packageManager) {
81
+ consola.info('Updating pnpm...')
82
+ const version = await runNpmScript(NpmScript.UpdatePackageManager)
83
+ consola.success('Successfully updated pnpm to: ', version)
84
+ }
85
+
86
+ // TODO: also update CI files & configurations, and other files, possibly
87
+ // ideally we want this to be smart enough to update only the files that have changed
88
+
89
+ // TODO: this script should trigger regeneration of auto-imports.d.ts & components.d.ts
90
+ }