-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dx): add new dev script behavior
tailored towards the examples within the library
- Loading branch information
1 parent
08c58dc
commit 680a333
Showing
13 changed files
with
1,117 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Thanks: https://github.com/vitebook/vitebook/tree/main/.scripts | ||
*/ | ||
|
||
import { spawn } from 'child_process'; | ||
import { readdirSync, readFileSync } from 'fs'; | ||
import Prompts from 'prompts'; | ||
import path from 'upath'; | ||
import minimist from 'minimist'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const { prompts } = Prompts; | ||
|
||
const args = minimist(process.argv.slice(2)); | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const examplesDir = path.resolve(__dirname, '../examples'); | ||
|
||
const examples = readdirSync(examplesDir).filter( | ||
(dirName) => !dirName.startsWith('.'), | ||
); | ||
|
||
const exampleArg = args._[0]; | ||
|
||
const exampleArgIndex = examples.findIndex((example) => example === exampleArg); | ||
|
||
const exampleIndex = | ||
exampleArgIndex >= 0 | ||
? exampleArgIndex | ||
: await prompts.select({ | ||
message: 'Pick an example', | ||
choices: examples, | ||
initial: 0, | ||
}); | ||
|
||
const example = examples[exampleIndex]; | ||
const exampleDir = path.resolve(examplesDir, example); | ||
const relativePathToExample = path.relative(process.cwd(), exampleDir); | ||
const examplePkgPath = path.resolve(exampleDir, 'package.json'); | ||
const examplePkgContent = JSON.parse(readFileSync(examplePkgPath).toString()); | ||
|
||
const scripts = Object.keys(examplePkgContent.scripts); | ||
const scriptArg = args.script; | ||
const scriptArgIndex = scripts.findIndex((script) => script === scriptArg); | ||
|
||
const scriptIndex = | ||
scriptArgIndex >= 0 | ||
? scriptArgIndex | ||
: await prompts.select({ | ||
message: 'Pick a script', | ||
choices: scripts, | ||
initial: 0, | ||
}); | ||
|
||
const script = scripts[scriptIndex]; | ||
|
||
spawn('npm', ['run', script, `--prefix=${relativePathToExample}`], { | ||
stdio: 'inherit', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.cache | ||
.temp | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script setup lang="ts"> | ||
import { HelloWorld } from '../../src/index' | ||
</script> | ||
|
||
<template> | ||
<HelloWorld /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Hello World | ||
|
||
This directory contains a simple "Hello World" component usage example. | ||
|
||
## Commands | ||
|
||
```shell | ||
# run dev server | ||
pnpm run dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createApp } from 'vue' | ||
import App from './App.vue' | ||
|
||
createApp(App).mount('#app') |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@openweb/vue-example", | ||
"version": "0.3.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"preinstall": "node ../../.scripts/check-for-pnpm.js && node ../../.scripts/check-node-version.js", | ||
"dev": "vite dev --open --port=3333" | ||
}, | ||
"dependencies": { | ||
"vue": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@vitejs/plugin-vue": "^2.3.1", | ||
"@vue/compiler-sfc": "^3.2.26", | ||
"autoprefixer": "^10.4.5", | ||
"postcss": "^8.4.12", | ||
"tailwindcss": "^3.0.24", | ||
"vite": "^2.8.0" | ||
}, | ||
"engines": { | ||
"node": ">=v16.15.0", | ||
"pnpm": ">=6.32.11" | ||
} | ||
} |
Oops, something went wrong.