-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
233 additions
and
52 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
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
This file was deleted.
Oops, something went wrong.
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 @@ | ||
export async function build() { | ||
const { build } = await import('../../vite/build.js') | ||
await build() | ||
} |
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,6 @@ | ||
export async function dev() { | ||
const { createDevServer } = await import('../../vite/dev-server.js') | ||
const server = await createDevServer() | ||
await server.listen() | ||
server.printUrls() | ||
} |
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,92 @@ | ||
// TODO: spice it up | ||
|
||
import { dirname, resolve } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
// @ts-expect-error | ||
import { detect } from 'detect-package-manager' | ||
import { execa } from 'execa' | ||
import { default as fs } from 'fs-extra' | ||
import { default as prompts } from 'prompts' | ||
|
||
type InitParameters = { name: string; git: boolean; install: boolean } | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
|
||
export async function init(options: InitParameters) { | ||
const templateDir = resolve(__dirname, '../templates/default') | ||
|
||
const displayName = | ||
options.name || | ||
(( | ||
await prompts({ | ||
type: 'text', | ||
name: 'displayName', | ||
message: 'Enter the name of your project', | ||
validate: (value) => (value ? true : 'Please enter a name'), | ||
}) | ||
).displayName as string) | ||
const name = kebabcase(displayName) as string | ||
|
||
const destDir = resolve(process.cwd(), name) | ||
|
||
console.log(`Scaffolding project in ${name}...`) | ||
|
||
// Copy contents | ||
fs.copySync(templateDir, destDir) | ||
|
||
// Replace dotfiles | ||
for (const file of fs.readdirSync(destDir)) { | ||
if (!file.startsWith('_')) continue | ||
fs.renameSync(resolve(destDir, file), resolve(destDir, `.${file.slice(1)}`)) | ||
} | ||
|
||
// Replace package.json properties | ||
const pkgJson = fs.readJsonSync(resolve(destDir, 'package.json')) | ||
pkgJson.name = name | ||
fs.writeJsonSync(resolve(destDir, 'package.json'), pkgJson, { spaces: 2 }) | ||
|
||
// Install dependencies | ||
if (options.install) { | ||
const packageManager = | ||
typeof options.install === 'string' ? options.install : detectPackageManager() | ||
await execa(packageManager, ['install', packageManager === 'npm' ? '--quiet' : '--silent'], { | ||
cwd: destDir, | ||
env: { | ||
...process.env, | ||
ADBLOCK: '1', | ||
DISABLE_OPENCOLLECTIVE: '1', | ||
// we set NODE_ENV to development as pnpm skips dev | ||
// dependencies when production | ||
NODE_ENV: 'development', | ||
}, | ||
}) | ||
} | ||
|
||
// Create git repository | ||
if (options.git) { | ||
await execa('git', ['init'], { cwd: destDir }) | ||
await execa('git', ['add', '.'], { cwd: destDir }) | ||
await execa('git', ['commit', '--no-verify', '--message', 'initial commit'], { | ||
cwd: destDir, | ||
}) | ||
} | ||
|
||
console.log('Done!') | ||
} | ||
|
||
export function kebabcase(str: string) { | ||
return str | ||
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g) | ||
?.join('-') | ||
.toLowerCase() | ||
} | ||
|
||
export function detectPackageManager() { | ||
const userAgent = process.env.npm_config_user_agent | ||
if (!userAgent) return 'npm' | ||
if (userAgent.includes('pnpm')) return 'pnpm' | ||
if (userAgent.includes('npm')) return 'npm' | ||
if (userAgent.includes('yarn')) return 'yarn' | ||
if (userAgent.includes('bun')) return 'bun' | ||
return 'npm' | ||
} |
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,5 @@ | ||
export async function preview() { | ||
const { preview } = await import('../../vite/preview.js') | ||
const server = await preview() | ||
server.printUrls() | ||
} |
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,31 @@ | ||
#!/usr/bin/env node | ||
import { cac } from 'cac' | ||
|
||
import { build } from './commands/build.js' | ||
import { dev } from './commands/dev.js' | ||
import { init } from './commands/init.js' | ||
import { preview } from './commands/preview.js' | ||
import { version } from './version.js' | ||
|
||
const cli = cac('vocs') | ||
|
||
cli.command('[root]').alias('dev').action(dev) | ||
cli | ||
.command('init') | ||
.option('-n, --name [name]', 'Name of project') | ||
.option( | ||
'-i, --install [false|npm|pnpm|yarn|bun]', | ||
'Install dependencies (and optionally force package manager)', | ||
{ | ||
default: true, | ||
}, | ||
) | ||
.option('-g, --git', 'Initialize git repository', { default: true }) | ||
.action(init) | ||
cli.command('build').action(build) | ||
cli.command('preview').action(preview) | ||
|
||
cli.help() | ||
cli.version(version) | ||
|
||
cli.parse() |
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 @@ | ||
This is a [Vocs](https://vocs.dev) project bootstrapped with the Vocs CLI. |
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,21 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# production | ||
/dist | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# typescript | ||
*.tsbuildinfo |
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 @@ | ||
# Hello world! | ||
|
||
Welcome to my site! |
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,15 @@ | ||
{ | ||
"name": "__DOCS_NAME__", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vocs", | ||
"build": "vocs build", | ||
"preview": "vocs preview" | ||
}, | ||
"dependencies": { | ||
"react": "latest", | ||
"react-dom": "latest", | ||
"vocs": "latest" | ||
} | ||
} |
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,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"useDefineForClassFields": true, | ||
"lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
"module": "ESNext", | ||
"skipLibCheck": true, | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"jsx": "react-jsx", | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"include": ["**/*.ts", "**/*.tsx"] | ||
} |
File renamed without changes.
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
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
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