Skip to content

Commit fb43cbd

Browse files
committed
Make the 'packages' directory optional
1 parent 9eba0fb commit fb43cbd

File tree

7 files changed

+58
-11
lines changed

7 files changed

+58
-11
lines changed

packages/create-vue-lib/src/index.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type Config = {
6464
globalVariableName: string
6565
targetDirName: string
6666
targetDirPath: string
67+
packagesDir: string
6768
mainPackageDirName: string
6869
templateDirPath: string
6970
githubPath: string
@@ -73,6 +74,7 @@ type Config = {
7374
githubPagesOrigin: string
7475
docsBase: string
7576
homepageUrl: string
77+
includePackagesDir: boolean
7678
includeDocs: boolean
7779
includeGithubPages: boolean
7880
includePlayground: boolean
@@ -216,6 +218,9 @@ async function init() {
216218
}
217219
}
218220

221+
const includePackagesDir = await togglePromptIf(extended, `Use 'packages' directory?`, true)
222+
const packagesDir = includePackagesDir ? 'packages/' : ''
223+
219224
const mainPackageDirName = await textPromptIf(extended, 'Main package directory', unscopedPackageName)
220225

221226
if (!isValidDirName(mainPackageDirName)) {
@@ -279,6 +284,12 @@ async function init() {
279284
process.exit(1)
280285
}
281286

287+
if (!includePackagesDir && mainPackageDirName === 'scripts') {
288+
console.log(`The directory name 'scripts' is reserved for the scripts, please choose a different name.`)
289+
suggestExtended()
290+
process.exit(1)
291+
}
292+
282293
const [githubUserName, githubRepoName] = (githubPath || '/').split('/')
283294
const githubUrl = githubPath ? `https://github.com/${githubPath}` : ''
284295
const githubIssues = githubPath ? `${githubUrl}/issues` : ''
@@ -296,6 +307,7 @@ async function init() {
296307
globalVariableName,
297308
targetDirName,
298309
targetDirPath,
310+
packagesDir,
299311
mainPackageDirName,
300312
templateDirPath,
301313
githubPath,
@@ -305,6 +317,7 @@ async function init() {
305317
githubPagesOrigin,
306318
docsBase,
307319
homepageUrl,
320+
includePackagesDir,
308321
includeDocs,
309322
includeGithubPages,
310323
includePlayground,
@@ -383,7 +396,13 @@ function copyFiles(templateFile: string, config: Config) {
383396
const stats = fs.statSync(templatePath)
384397
const basename = path.basename(templatePath)
385398

386-
const targetPath = path.join(config.targetDirPath, templateFile.replace(/@projectName@/g, config.mainPackageDirName))
399+
let targetFile = templateFile.replace(/@projectName@/g, config.mainPackageDirName)
400+
401+
if (!config.includePackagesDir) {
402+
targetFile = targetFile.replace(/^packages/, '.')
403+
}
404+
405+
const targetPath = path.join(config.targetDirPath, targetFile)
387406

388407
if (stats.isDirectory()) {
389408
if (basename === 'node_modules') {

packages/create-vue-lib/src/template/base/config/.gitignore.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ dist
1313
dist-ssr
1414
coverage
1515
*.local
16-
packages/docs/.vitepress/cache
17-
packages/<%- config.mainPackageDirName %>/README.md
16+
<%- config.packagesDir %>docs/.vitepress/cache
17+
<%- config.packagesDir %><%- config.mainPackageDirName %>/README.md
1818

1919
/cypress/videos/
2020
/cypress/screenshots/

packages/create-vue-lib/src/template/base/config/package.json.ejs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
"scripts": {
99
"clean": "pnpm run -r clean",
1010
<%_ if (config.includePlayground) { _%>
11-
"dev": "pnpm run --filter ./packages/playground -r dev",
11+
"dev": "pnpm run --filter ./<%- config.packagesDir %>playground -r dev",
1212
<%_ } _%>
1313
<%_ if (config.includeDocs) { _%>
14-
"docs:dev": "pnpm run --filter ./packages/docs -r dev",
15-
"docs:build": "pnpm run --filter ./packages/docs -r build",
14+
"docs:dev": "pnpm run --filter ./<%- config.packagesDir %>docs -r dev",
15+
"docs:build": "pnpm run --filter ./<%- config.packagesDir %>docs -r build",
1616
<%_ } _%>
1717
<%_ if (config.includeVitest) { _%>
18-
"test:unit": "pnpm run --filter ./packages/<%- config.mainPackageDirName %> -r test:unit",
19-
"coverage": "pnpm run --filter ./packages/<%- config.mainPackageDirName %> -r coverage",
18+
"test:unit": "pnpm run --filter ./<%- config.packagesDir %><%- config.mainPackageDirName %> -r test:unit",
19+
"coverage": "pnpm run --filter ./<%- config.packagesDir %><%- config.mainPackageDirName %> -r coverage",
2020
<%_ } _%>
2121
<%_ if (config.includeEsLint) { _%>
2222
"type-check": "run-p type-check:*",

packages/create-vue-lib/src/template/base/config/pnpm-workspace.yaml

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
packages:
2+
<%_ if (config.includePackagesDir) { _%>
3+
- '<%- config.packagesDir %>*'
4+
<%_ } else { _%>
5+
- '<%- config.mainPackageDirName %>'
6+
<%_ if (config.includeDocs) { _%>
7+
- 'docs'
8+
<%_ } _%>
9+
<%_ if (config.includePlayground) { _%>
10+
- 'playground'
11+
<%_ } _%>
12+
<%_ } _%>

packages/create-vue-lib/src/template/gh-pages/config/.github/workflows/pages.yml renamed to packages/create-vue-lib/src/template/gh-pages/config/.github/workflows/pages.yml.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
uses: actions/upload-pages-artifact@v3
4848
with:
4949
# Upload docs dist directory
50-
path: './packages/docs/dist'
50+
path: './<%- config.packagesDir %>docs/dist'
5151
- name: Deploy to GitHub Pages
5252
id: deployment
5353
uses: actions/deploy-pages@v4

packages/docs/src/questions.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
&nbsp;
4141
<span class="check">✔</span> <a href="#package-name">Package name … @skirtle/test-project</a>
4242
<span class="check">✔</span> <a href="#target-directory">Target directory … test-project</a>
43+
<span class="check">✔</span> <a href="#use-packages-directory">Use 'packages' directory? … No / Yes</a>
4344
<span class="check">✔</span> <a href="#main-package-directory">Main package directory … test-project</a>
4445
<span class="check">✔</span> <a href="#global-variable-name">Global variable name … TestProject</a>
4546
<span class="check">✔</span> <a href="#github-path">GitHub path (optional) … skirtles-code/test-project</a>
@@ -78,6 +79,23 @@ The directory can be renamed after the project is created. None of the files wit
7879

7980
The tool should only create files within the specified directory. It won't edit any global configuration or files elsewhere on the filesystem. If you want to delete the project you can just delete this directory.
8081

82+
## Use 'packages' directory?{#use-packages-directory}
83+
84+
:::info NOTE
85+
This question is only asked when using the `--extended` flag.
86+
:::
87+
88+
By default, the packages in the newly created project will be placed in a root-level directory called `packages`, like this:
89+
90+
```
91+
📁 packages
92+
📁 docs
93+
📁 playground
94+
📁 <main-package-directory>
95+
```
96+
97+
While this convention is commonly used by the official Vue libraries, the real benefits come as a project grows and the number of packages increases. If you only need one or two packages then you might prefer to keep them in root-level directories, rather than in `packages`.
98+
8199
## Main package directory
82100

83101
:::info NOTE

0 commit comments

Comments
 (0)