docus 1.0.6 → 3.0.0-beta.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 (127) hide show
  1. package/README.md +9 -22
  2. package/app/router.options.ts +18 -0
  3. package/assets/css/fonts.css +84 -0
  4. package/assets/css/main.css +11 -0
  5. package/assets/css/tailwind.css +282 -0
  6. package/components/app/Container.vue +23 -0
  7. package/components/app/Footer.vue +38 -0
  8. package/components/app/Navbar.vue +26 -0
  9. package/components/app/NavbarLogo.vue +31 -0
  10. package/components/app/Page.vue +7 -0
  11. package/components/app/PoweredByDocus.vue +11 -0
  12. package/components/content/Alert.vue +124 -0
  13. package/components/content/BlockHero.vue +54 -0
  14. package/components/content/ButtonLink.vue +44 -0
  15. package/components/content/Card.vue +46 -0
  16. package/components/content/CardGrid.vue +23 -0
  17. package/components/content/CodeBlock.vue +47 -0
  18. package/components/content/CodeGroup.vue +134 -0
  19. package/components/content/CopyButton.vue +48 -0
  20. package/components/content/List.vue +5 -0
  21. package/components/content/NeedContribution.vue +23 -0
  22. package/components/content/ReadMore.vue +24 -0
  23. package/components/content/Sandbox.vue +100 -0
  24. package/components/content/TabsHeader.vue +44 -0
  25. package/components/content/Terminal.vue +70 -0
  26. package/components/content/VideoPlayer.vue +113 -0
  27. package/components/docs/DocsAside.vue +19 -0
  28. package/components/docs/DocsAsideTree.vue +101 -0
  29. package/components/docs/DocsHero.vue +39 -0
  30. package/components/docs/DocsPage.vue +22 -0
  31. package/components/docs/DocsPageContent.vue +29 -0
  32. package/components/docs/DocsToc.vue +72 -0
  33. package/components/globals/Icon.vue +24 -0
  34. package/components/globals/Logo.vue +3 -0
  35. package/components/globals/NuxtImg.vue +43 -0
  36. package/components/globals/SocialIcons.vue +43 -0
  37. package/components/globals/ThemeSelect.vue +35 -0
  38. package/components/icons/IconAlgolia.vue +8 -0
  39. package/components/icons/IconArrowLeft.vue +10 -0
  40. package/components/icons/IconArrowRight.vue +10 -0
  41. package/components/icons/IconBadgeCheck.vue +14 -0
  42. package/components/icons/IconCheck.vue +10 -0
  43. package/components/icons/IconCheckCircle.vue +10 -0
  44. package/components/icons/IconChevronRight.vue +12 -0
  45. package/components/icons/IconClipboardCheck.vue +14 -0
  46. package/components/icons/IconClipboardCopy.vue +14 -0
  47. package/components/icons/IconCodeSandbox.vue +8 -0
  48. package/components/icons/IconCopy.vue +17 -0
  49. package/components/icons/IconDots.vue +10 -0
  50. package/components/icons/IconEdit.vue +18 -0
  51. package/components/icons/IconExclamationCircle.vue +12 -0
  52. package/components/icons/IconExclamationTriangle.vue +10 -0
  53. package/components/icons/IconExternalLink.vue +12 -0
  54. package/components/icons/IconGit.vue +7 -0
  55. package/components/icons/IconGitHub.vue +10 -0
  56. package/components/icons/IconHeart.vue +9 -0
  57. package/components/icons/IconInformationCircle.vue +10 -0
  58. package/components/icons/IconLighthouse.vue +83 -0
  59. package/components/icons/IconLine.vue +10 -0
  60. package/components/icons/IconMarkdown.vue +13 -0
  61. package/components/icons/IconMenu.vue +12 -0
  62. package/components/icons/IconMenuAlt.vue +10 -0
  63. package/components/icons/IconMinus.vue +10 -0
  64. package/components/icons/IconMoon.vue +10 -0
  65. package/components/icons/IconNuxt.vue +14 -0
  66. package/components/icons/IconNuxtContent.vue +20 -0
  67. package/components/icons/IconNuxtLabs.vue +21 -0
  68. package/components/icons/IconPlus.vue +10 -0
  69. package/components/icons/IconPuzzle.vue +8 -0
  70. package/components/icons/IconSSG.vue +7 -0
  71. package/components/icons/IconSearch.vue +12 -0
  72. package/components/icons/IconSun.vue +10 -0
  73. package/components/icons/IconTocBack.vue +21 -0
  74. package/components/icons/IconTocCurrent.vue +21 -0
  75. package/components/icons/IconTocNext.vue +8 -0
  76. package/components/icons/IconTranslate.vue +14 -0
  77. package/components/icons/IconTwitter.vue +8 -0
  78. package/components/icons/IconVite.vue +30 -0
  79. package/components/icons/IconVue.vue +6 -0
  80. package/components/icons/IconVueTelescope.vue +11 -0
  81. package/components/icons/IconWindi.vue +17 -0
  82. package/components/icons/IconX.vue +12 -0
  83. package/components/icons/IconXCircle.vue +10 -0
  84. package/components/icons/IconZap.vue +8 -0
  85. package/components/prose/ProseA.vue +66 -0
  86. package/components/prose/ProseBlockquote.vue +21 -0
  87. package/components/prose/ProseCode.vue +68 -0
  88. package/components/prose/ProseCodeInline.vue +38 -0
  89. package/components/prose/ProseEm.vue +11 -0
  90. package/components/prose/ProseH1.vue +22 -0
  91. package/components/prose/ProseH2.vue +22 -0
  92. package/components/prose/ProseH3.vue +24 -0
  93. package/components/prose/ProseH4.vue +24 -0
  94. package/components/prose/ProseHr.vue +13 -0
  95. package/components/prose/ProseImg.vue +32 -0
  96. package/components/prose/ProseLi.vue +31 -0
  97. package/components/prose/ProseOl.vue +16 -0
  98. package/components/prose/ProseP.vue +14 -0
  99. package/components/prose/ProseStrong.vue +14 -0
  100. package/components/prose/ProseTable.vue +13 -0
  101. package/components/prose/ProseTbody.vue +5 -0
  102. package/components/prose/ProseTd.vue +11 -0
  103. package/components/prose/ProseTh.vue +11 -0
  104. package/components/prose/ProseThead.vue +11 -0
  105. package/components/prose/ProseTr.vue +11 -0
  106. package/components/prose/ProseUl.vue +15 -0
  107. package/composables/useContent.ts +155 -0
  108. package/composables/useMenu.ts +20 -0
  109. package/composables/useScrollToHeading.ts +35 -0
  110. package/composables/useScrollspy.ts +45 -0
  111. package/composables/useTheme.ts +10 -0
  112. package/layouts/default.vue +27 -0
  113. package/layouts/page.vue +11 -0
  114. package/nuxt.config.ts +151 -0
  115. package/package.json +45 -63
  116. package/pages/[...slug].vue +24 -0
  117. package/public/android-chrome-192x192.png +0 -0
  118. package/public/android-chrome-512x512.png +0 -0
  119. package/public/apple-touch-icon.png +0 -0
  120. package/public/favicon-16x16.png +0 -0
  121. package/public/favicon-32x32.png +0 -0
  122. package/public/favicon.ico +0 -0
  123. package/public/site.webmanifest +1 -0
  124. package/dist/create-docus/create-docus.js +0 -7
  125. package/dist/create-docus/index.js +0 -122
  126. package/dist/helpers.js +0 -154
  127. package/dist/index.js +0 -10
@@ -0,0 +1,20 @@
1
+ export const useMenu = () => {
2
+ // Menu visible reference
3
+ const visible = useState('menu-visible', () => false)
4
+
5
+ // Open the menu
6
+ const open = () => (visible.value = true)
7
+
8
+ // Close the menu
9
+ const close = () => (visible.value = false)
10
+
11
+ // Toggle the menu (useful for one-off buttons)
12
+ const toggle = () => (visible.value = !visible.value)
13
+
14
+ return {
15
+ open,
16
+ close,
17
+ toggle,
18
+ visible,
19
+ }
20
+ }
@@ -0,0 +1,35 @@
1
+ export const useConvertPropToPixels = (prop: string): number => {
2
+ const tempDiv = document.createElement('div')
3
+
4
+ tempDiv.style.position = 'absolute'
5
+ tempDiv.style.opacity = '0'
6
+ tempDiv.style.height = getComputedStyle(document.documentElement).getPropertyValue(prop)
7
+
8
+ document.body.appendChild(tempDiv)
9
+
10
+ const pixels = parseInt(getComputedStyle(tempDiv).height)
11
+
12
+ document.body.removeChild(tempDiv)
13
+
14
+ return pixels
15
+ }
16
+
17
+ export const useScrollToHeading = (id: string, scrollMarginCssVar: string) => {
18
+ // Use replaceState to prevent page jump when adding hash
19
+ history.replaceState({}, '', `#${id}`)
20
+
21
+ // Do not remove setTimeout (does not work in Safari)
22
+ setTimeout(() => {
23
+ const escapedId = id.replace(/\./g, '\\.')
24
+
25
+ const heading = document.querySelector(`#${escapedId}`) as any
26
+
27
+ const offset = heading.offsetTop - useConvertPropToPixels(scrollMarginCssVar)
28
+
29
+ window.scrollTo({
30
+ top: offset,
31
+ left: 0,
32
+ behavior: 'smooth',
33
+ })
34
+ })
35
+ }
@@ -0,0 +1,45 @@
1
+ import type { Ref } from 'vue'
2
+
3
+ /**
4
+ * Scrollspy allows you to watch visible headings in a specific page.
5
+ * Useful for table of contents live style updates.
6
+ */
7
+ export const useScrollspy = () => {
8
+ const observer = ref() as Ref<IntersectionObserver>
9
+ const visibleHeadings = ref([]) as Ref<string[]>
10
+ const activeHeadings = ref([]) as Ref<string[]>
11
+
12
+ const observerCallback = (entries: IntersectionObserverEntry[]) =>
13
+ entries.forEach((entry) => {
14
+ const id = entry.target.id
15
+
16
+ if (entry.isIntersecting)
17
+ visibleHeadings.value.push(id)
18
+ else
19
+ visibleHeadings.value = visibleHeadings.value.filter(t => t !== id)
20
+ })
21
+
22
+ const updateHeadings = (headings: Element[]) =>
23
+ headings.forEach((heading) => {
24
+ observer.value.observe(heading)
25
+ })
26
+
27
+ watch(visibleHeadings, (val, oldVal) => {
28
+ if (val.length === 0)
29
+ activeHeadings.value = oldVal
30
+ else
31
+ activeHeadings.value = val
32
+ })
33
+
34
+ // Create intersection observer
35
+ onBeforeMount(() => (observer.value = new IntersectionObserver(observerCallback)))
36
+
37
+ // Destroy it
38
+ onBeforeUnmount(() => observer.value?.disconnect())
39
+
40
+ return {
41
+ visibleHeadings,
42
+ activeHeadings,
43
+ updateHeadings,
44
+ }
45
+ }
@@ -0,0 +1,10 @@
1
+ export const useTheme = () => {
2
+ const { theme } = useRuntimeConfig()
3
+
4
+ return theme
5
+ }
6
+
7
+ export const classNames = (...args: any[]) => {
8
+ const classes = args.filter(Boolean).join(' ')
9
+ return classes.length ? classes : undefined
10
+ }
@@ -0,0 +1,27 @@
1
+ <script setup>
2
+ const { page, fetchNavigation } = useContent()
3
+
4
+ await fetchNavigation()
5
+ </script>
6
+
7
+ <template>
8
+ <div class="w-full flex min-h-screen flex-col">
9
+ <Navbar />
10
+
11
+ <div class="min-h-[calc(100vh-12rem)] sm:min-h-[calc(100vh-8rem)] flex flex-col">
12
+ <DocsPage>
13
+ <template #aside>
14
+ <DocsAside v-if="page?.value?.aside || typeof page?.value?.aside === 'undefined'" />
15
+ </template>
16
+
17
+ <DocsPageContent>
18
+ <div class="max-w-none">
19
+ <NuxtPage />
20
+ </div>
21
+ </DocsPageContent>
22
+ </DocsPage>
23
+ </div>
24
+
25
+ <Footer />
26
+ </div>
27
+ </template>
@@ -0,0 +1,11 @@
1
+ <template>
2
+ <div class="w-full flex min-h-screen flex-col">
3
+ <Navbar />
4
+
5
+ <div class="min-h-[calc(100vh-12rem)] sm:min-h-[calc(100vh-8rem)] flex flex-col ">
6
+ <NuxtPage />
7
+ </div>
8
+
9
+ <Footer />
10
+ </div>
11
+ </template>
package/nuxt.config.ts ADDED
@@ -0,0 +1,151 @@
1
+ import { fileURLToPath } from 'url'
2
+ import { defineNuxtConfig } from 'nuxt'
3
+ import colors from 'tailwindcss/colors.js'
4
+ import { resolve } from 'pathe'
5
+
6
+ const themeDir = fileURLToPath(new URL('./', import.meta.url))
7
+ const resolveThemeDir = (path: string) => resolve(themeDir, path)
8
+
9
+ export default defineNuxtConfig({
10
+ runtimeConfig: {
11
+ public: {
12
+ plausible: {
13
+ domain: process.env.PLAUSIBLE_DOMAIN,
14
+ },
15
+ theme: {
16
+ title: 'Docus',
17
+ twitter: '@docus_',
18
+ github: 'nuxtlabs/docus',
19
+ header: {
20
+ title: false,
21
+ logo: true,
22
+ },
23
+ footer: {
24
+ credits: {
25
+ icon: 'IconNuxtLabs',
26
+ text: 'Made by Nuxt Labs',
27
+ },
28
+ icons: [
29
+ {
30
+ label: 'NuxtJS',
31
+ href: 'https://nuxtjs.org',
32
+ component: 'IconNuxt',
33
+ },
34
+ {
35
+ label: 'Vue Telescope',
36
+ href: 'https://vuetelescope.com',
37
+ component: 'IconVueTelescope',
38
+ },
39
+ ],
40
+ },
41
+ },
42
+ },
43
+ },
44
+ head: {
45
+ title: 'Docus',
46
+ link: [
47
+ {
48
+ rel: 'stylesheet',
49
+ href: 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap',
50
+ },
51
+ { rel: 'preconnect', href: 'https://fonts.gstatic.com' },
52
+ ],
53
+ meta: [
54
+ { hid: 'og:site_name', property: 'og:site_name', content: 'Nuxt 3' },
55
+ { hid: 'og:type', property: 'og:type', content: 'website' },
56
+ ],
57
+ },
58
+ loading: {
59
+ color: '#00DC82',
60
+ },
61
+ /**
62
+ * Components
63
+ */
64
+ components: [
65
+ {
66
+ prefix: '',
67
+ path: './components/app',
68
+ global: true,
69
+ },
70
+ {
71
+ prefix: '',
72
+ path: './components/docs',
73
+ global: true,
74
+ },
75
+ {
76
+ prefix: '',
77
+ path: './components/prose',
78
+ global: true,
79
+ },
80
+ {
81
+ prefix: '',
82
+ path: './components/globals',
83
+ global: true,
84
+ },
85
+ {
86
+ prefix: '',
87
+ path: './components/content',
88
+ global: true,
89
+ },
90
+ {
91
+ prefix: '',
92
+ path: './components/icons',
93
+ global: true,
94
+ },
95
+ ],
96
+ css: [
97
+ resolveThemeDir('assets/css/main.css'),
98
+ resolveThemeDir('assets/css/fonts.css'),
99
+ resolveThemeDir('assets/css/tailwind.css'),
100
+ ],
101
+ tailwindcss: {
102
+ viewer: false,
103
+
104
+ config: {
105
+ darkMode: 'class',
106
+ theme: {
107
+ extend: {
108
+ colors: {
109
+ gray: colors.gray,
110
+ primary: colors.indigo,
111
+ },
112
+ fontFamily: {
113
+ sans: 'Inter, sans-serif',
114
+ },
115
+ },
116
+ },
117
+ plugins: [
118
+ require('@tailwindcss/typography'),
119
+ require('@tailwindcss/forms'),
120
+ require('@tailwindcss/line-clamp'),
121
+ require('@tailwindcss/aspect-ratio'),
122
+ ],
123
+ content: [
124
+ resolveThemeDir('components/**/*.{mjs,vue,js,ts}'),
125
+ resolveThemeDir('layouts/**/*.{mjs,vue,js,ts}'),
126
+ resolveThemeDir('pages/**/*.{mjs,vue,js,ts}'),
127
+ ],
128
+ safelist: [24, 36, 48, 60, 72, 84, 96, 108, 120].map(number => `pl-[${number}px]`),
129
+ cssPath: resolveThemeDir('assets/css/tailwind.css'),
130
+ },
131
+ },
132
+ content: {
133
+ highlight: {
134
+ theme: 'one-dark-pro',
135
+ preload: ['json', 'js', 'ts', 'html', 'css', 'vue', 'diff', 'shell', 'markdown', 'yaml', 'bash'],
136
+ },
137
+ },
138
+ colorMode: {
139
+ classSuffix: '',
140
+ },
141
+ /**
142
+ * Modules
143
+ */
144
+ modules: [
145
+ '@nuxt/content',
146
+ '@nuxtjs/tailwindcss',
147
+ '@nuxtjs/color-mode',
148
+ '@nuxthq/admin',
149
+ 'vue-plausible',
150
+ ],
151
+ })
package/package.json CHANGED
@@ -1,72 +1,54 @@
1
1
  {
2
+ "version": "3.0.0-beta.1",
2
3
  "name": "docus",
3
- "version": "1.0.6",
4
- "description": "The Docus CLI.",
5
- "repository": "https://github.com/docusgen/cli",
6
- "bugs": {
7
- "url": "https://github.com/docusgen/cli/issues"
8
- },
9
- "homepage": "https://github.com/docusgen/cli#readme",
10
- "author": "Yaël GUILLOUX <yael.guilloux@gmail.com>",
11
- "license": "MIT",
12
- "keywords": [
13
- "typescript",
14
- "starter"
15
- ],
16
- "main": "dist/index.js",
17
- "module": "dist/index.mjs",
18
- "types": "dist/src/index.d.ts",
19
4
  "scripts": {
20
- "dev": "jiti scripts/watch.ts --cache",
21
- "build": "unbuild",
22
- "lint": "prettier -c --parser typescript \"{src,tests}/**/*.[jt]s?(x)\"",
23
- "lint:fix": "yarn run lint --write",
24
- "test:types": "tsc --build tsconfig.json",
25
- "test:unit": "jest",
26
- "test": "yarn run test:types && yarn run test:unit"
27
- },
28
- "engines": {
29
- "node": ">=14.0.0"
5
+ "build": "nuxi build",
6
+ "dev": "nuxi dev",
7
+ "preview": "nuxi preview",
8
+ "lint": "eslint --ext .ts,.js,.vue,.css ."
30
9
  },
31
- "bin": {
32
- "create-docus": "dist/create-docus/create-docus.js"
10
+ "devDependencies": {
11
+ "@antfu/eslint-config": "^0.20.6",
12
+ "@nuxtjs/eslint-config-typescript": "^9.0.0",
13
+ "eslint": "^8.13.0",
14
+ "nuxt": "^3.0.0-rc.1",
15
+ "parse-entities": "^4.0.0",
16
+ "typescript": "^4.6.3"
33
17
  },
34
- "files": [
35
- "dist/**/*",
36
- "LICENSE",
37
- "README.md"
38
- ],
39
18
  "dependencies": {
40
- "degit": "^2.8.4",
41
- "execa": "^5.1.1",
42
- "kolorist": "^1.5.0",
43
- "minimist": "^1.2.5",
44
- "prompts": "^2.4.1"
19
+ "@iconify/vue": "^3.2.1",
20
+ "@nuxt/content": "npm:@nuxt/content-edge@latest",
21
+ "@nuxthq/admin": "npm:@nuxthq/admin-edge@latest",
22
+ "@nuxtjs/color-mode": "^3.0.2",
23
+ "@nuxtjs/tailwindcss": "^5.0.3",
24
+ "@tailwindcss/aspect-ratio": "^0.4.0",
25
+ "@tailwindcss/forms": "^0.5.0",
26
+ "@tailwindcss/line-clamp": "^0.3.1",
27
+ "@tailwindcss/typography": "^0.5.2",
28
+ "@vueuse/core": "^8.3.0",
29
+ "@vueuse/motion": "2.0.0-beta.12",
30
+ "clipboard": "^2.0.10",
31
+ "defu": "^6.0.0",
32
+ "lodash-es": "^4.17.21",
33
+ "tailwindcss": "^3.0.24",
34
+ "vue-plausible": "^1.3.1"
45
35
  },
46
- "devDependencies": {
47
- "@types/degit": "^2.8.3",
48
- "@types/jest": "^27.0.1",
49
- "@types/minimist": "^1.2.2",
50
- "@types/prompts": "^2.0.14",
51
- "chokidar": "^3.5.2",
52
- "jest": "^27.0.6",
53
- "jiti": "^1.11.0",
54
- "lint-staged": "^11.1.2",
55
- "pascalcase": "^1.0.0",
56
- "prettier": "^2.3.2",
57
- "ts-jest": "^27.0.5",
58
- "typescript": "^4.3.5",
59
- "unbuild": "^0.4.2"
60
- },
61
- "gitHooks": {
62
- "pre-commit": "lint-staged"
36
+ "main": "./nuxt.config.ts",
37
+ "exports": {
38
+ ".": {
39
+ "require": "./nuxt.config.ts",
40
+ "import": "./nuxt.config.ts"
41
+ }
63
42
  },
64
- "lint-staged": {
65
- "*.js": [
66
- "prettier --write"
67
- ],
68
- "*.ts?(x)": [
69
- "prettier --parser=typescript --write"
70
- ]
71
- }
43
+ "files": [
44
+ "README.md",
45
+ "app",
46
+ "assets",
47
+ "components",
48
+ "composables",
49
+ "layouts",
50
+ "pages",
51
+ "public",
52
+ "nuxt.config.ts"
53
+ ]
72
54
  }
@@ -0,0 +1,24 @@
1
+ <script setup lang="ts">
2
+ const router = useRouter()
3
+
4
+ const { page, fetchPage } = useContent()
5
+
6
+ await fetchPage()
7
+
8
+ if (page.value && page.value.layout)
9
+ router.currentRoute.value.meta.layout = page.value.layout
10
+ else
11
+ router.currentRoute.value.meta.layout = 'default'
12
+ </script>
13
+
14
+ <template>
15
+ <Content v-if="page" class="content" :document="page" />
16
+ </template>
17
+
18
+ <style scoped>
19
+ .content {
20
+ & > :first-child {
21
+ margin-top: 0 !important;
22
+ }
23
+ }
24
+ </style>
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1 @@
1
+ {"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- // #!/usr/bin/env node
3
- "use strict";
4
-
5
- var _index = require("./index");
6
-
7
- (0, _index.createDocus)().catch(console.log);
@@ -1,122 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createDocus = createDocus;
7
-
8
- var _fs = _interopRequireDefault(require("fs"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _minimist = _interopRequireDefault(require("minimist"));
13
-
14
- var _prompts = _interopRequireDefault(require("prompts"));
15
-
16
- var _execa = _interopRequireDefault(require("execa"));
17
-
18
- var _helpers = require("../helpers");
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- const argv = (0, _minimist.default)(process.argv.slice(2));
23
- const {
24
- motd,
25
- primary,
26
- secondary,
27
- bold,
28
- space,
29
- broadcast
30
- } = (0, _helpers.log)();
31
- const cwd = process.cwd();
32
-
33
- async function createDocus() {
34
- motd();
35
- let targetDir = argv._[0];
36
-
37
- if (!targetDir) {
38
- const {
39
- projectName
40
- } = await (0, _prompts.default)({
41
- type: "text",
42
- name: "projectName",
43
- message: "Project name:",
44
- initial: "my-website"
45
- });
46
- targetDir = projectName.trim();
47
- }
48
-
49
- const packageName = await (0, _helpers.getValidPackageName)(targetDir);
50
-
51
- const root = _path.default.join(cwd, targetDir);
52
-
53
- await (0, _helpers.overwriteDir)(root);
54
- space();
55
- broadcast(secondary("Scaffolding project in ") + targetDir + secondary("..."));
56
- const {
57
- templateDir
58
- } = await (0, _helpers.getTemplate)();
59
-
60
- const write = (file, content = void 0) => {
61
- const targetPath = _path.default.join(root, file);
62
-
63
- if (content) _fs.default.writeFileSync(targetPath, content);else (0, _helpers.copy)(_path.default.join(templateDir, file), targetPath);
64
- };
65
-
66
- const files = _fs.default.readdirSync(templateDir);
67
-
68
- for (const file of files.filter(f => f !== "package.json")) write(file);
69
-
70
- const pkg = require(_path.default.join(templateDir, "package.json"));
71
-
72
- pkg.name = packageName;
73
- write("package.json", JSON.stringify(pkg, null, 2));
74
- const pkgManager = /pnpm/.test(process.env.npm_execpath || "") || /pnpm/.test(process.env.npm_config_user_agent || "") ? "pnpm" : /yarn/.test(process.env.npm_execpath || "") ? "yarn" : "npm";
75
-
76
- const related = _path.default.relative(cwd, root);
77
-
78
- broadcast(primary("Done."));
79
- space();
80
- const {
81
- yes
82
- } = await (0, _prompts.default)({
83
- type: "confirm",
84
- name: "yes",
85
- initial: "Y",
86
- message: "Install and start it now?"
87
- });
88
- if (yes) await startProject(root);else startItLater(pkgManager, root, related);
89
- }
90
-
91
- async function startProject(projectPath) {
92
- space();
93
- const {
94
- agent
95
- } = await (0, _prompts.default)({
96
- name: "agent",
97
- type: "select",
98
- message: "Choose the agent",
99
- choices: ["yarn", "npm", "pnpm"].map(i => ({
100
- value: i,
101
- title: i
102
- }))
103
- });
104
- if (!agent) return;
105
- await (0, _execa.default)(agent, ["install"], {
106
- stdio: "inherit",
107
- cwd: projectPath
108
- });
109
- await (0, _execa.default)(agent, ["run", "dev"], {
110
- stdio: "inherit",
111
- cwd: projectPath
112
- });
113
- }
114
-
115
- function startItLater(pkgManager, root, dir) {
116
- space();
117
- broadcast(secondary("Start it later with:"));
118
- space();
119
- if (root !== cwd) broadcast(primary(`cd ${bold(dir)}`));
120
- broadcast(primary(`${pkgManager === "yarn" ? "yarn" : `${pkgManager} install`}`));
121
- broadcast(primary(`${pkgManager === "yarn" ? "yarn dev" : `${pkgManager} run dev`}`));
122
- }