Skip to content

Commit

Permalink
fix: leave gitignore when emptying directory
Browse files Browse the repository at this point in the history
  • Loading branch information
markmartirosian committed Nov 12, 2023
1 parent 2e670f7 commit 36e7033
Show file tree
Hide file tree
Showing 5 changed files with 3,964 additions and 1,415 deletions.
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"homepage": "https://github.com/escapace/yeux",
"license": "MPL-2.0",
"peerDependencies": {
"vite": ">=4.4.11"
"vite": ">=4.5.0"
},
"private": false,
"repository": "escapace/yeux",
Expand Down
6 changes: 4 additions & 2 deletions packages/yeux/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { OutputOptions, PreRenderedAsset } from 'rollup'
import type { Manifest, SSROptions } from 'vite'
import type { State, ViteInlineConfig } from '../types'
import { createAssetFileNames } from '../utilities/create-asset-file-names'
import { emptyDir } from '../utilities/empty-dir'
import { step } from '../utilities/log'
import { rollupInputOptions } from '../utilities/rollup-input-options'

Expand Down Expand Up @@ -51,6 +52,7 @@ export const clientConfig = async (state: State): Promise<ViteInlineConfig> => {
? current.build.terserOptions
: undefined,
outDir: path.relative(state.directory, state.clientOutputDirectory),
emptyOutDir: false,
rollupOptions: assign({}, current.build.rollupOptions, {
input,
output: mapRollupOutputOptions(
Expand Down Expand Up @@ -278,8 +280,8 @@ export const injectManifest = async (state: State) => {
}

export const build = async (state: State): Promise<void> => {
await fse.emptyDir(state.clientOutputDirectory)
await fse.emptyDir(state.serverOutputDirectory)
await emptyDir(state.clientOutputDirectory)
await emptyDir(state.serverOutputDirectory)

step(`Client Build`)

Expand Down
5 changes: 3 additions & 2 deletions packages/yeux/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { writeAssets } from '@yeuxjs/write-assets'
import bodyParser from 'body-parser'
import express from 'express'
import { fromNodeHeaders, toNodeHeaders } from 'fastify-fetch'
import fse from 'fs-extra'
import { readFile } from 'fs/promises'
import { assign, omit } from 'lodash-es'
import path from 'path'
Expand All @@ -14,9 +13,10 @@ import {
extensionImage,
hasExtension
} from '../utilities/create-asset-file-names'
import { emptyDir } from '../utilities/empty-dir'

export async function dev(state: State) {
await fse.emptyDir(state.clientOutputDirectory)
await emptyDir(state.clientOutputDirectory)

const server = express()
server.disable('x-powered-by')
Expand All @@ -40,6 +40,7 @@ export async function dev(state: State) {
},
build: {
...state.viteConfig.build,
emptyOutDir: false,
minify: false,
terserOptions: undefined
},
Expand Down
25 changes: 25 additions & 0 deletions packages/yeux/src/utilities/empty-dir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import fse from 'fs-extra'
import path from 'path'

export const emptyDir = async function emptyDir(
dir: string,
exclude = ['.gitignore']
) {
let items

try {
items = await fse.readdir(dir)
} catch {
return await fse.mkdirs(dir)
}

const aasd = items.filter((value) => !exclude.includes(value))

console.log(aasd)

return await Promise.all(
items
.filter((value) => !exclude.includes(value))
.map(async (item) => await fse.remove(path.join(dir, item)))
)
}

0 comments on commit 36e7033

Please sign in to comment.