Skip to content

Commit

Permalink
feat: add patches
Browse files Browse the repository at this point in the history
fix: user ignore the file suffix and uses the alias(@) to refer a file
  • Loading branch information
YJZQV committed Jul 5, 2021
1 parent 220fed5 commit 5e53c0b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import chalk from 'chalk'
import { geneIndexHtml } from '../generate/geneIndexHtml'
import { genePackageJson } from '../generate/genePackageJson'
import { geneViteConfig } from '../generate/geneViteConfig'
import { genePatches } from '../generate/genePatches'
import { Command } from 'commander'
import { Config } from '../config/config'
import { astParseRoot } from '../ast-parse/astParse'
Expand Down Expand Up @@ -50,6 +51,10 @@ export async function start (config : Config): Promise<void> {
// generate index.html must be after generate vite.config.js
geneIndexHtml(rootDir, config)

// generate patches
const patchesDir = path.resolve(rootDir, 'patches')
genePatches(patchesDir)

console.log(chalk.green('************************ Done ! ************************'))
const pkgManager = fs.existsSync(path.resolve(rootDir, 'yarn.lock'))
? 'yarn'
Expand Down
1 change: 1 addition & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export const VITE_PLUGIN_ENV_COMPATIBLE = '^1.0.0'
export const SASS_VERSION = '^1.34.0'
export const VITE_PLUGIN_COMMONJS_VERSION = '^1.0.0-beta3'
export const POSTCSS_VERSION = '^8.3.5'
export const PATCH_PACKAGE_VERSION = '^6.4.7'
6 changes: 6 additions & 0 deletions src/generate/genePackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ export function genePackageJson (packageJsonPath: string): void {
packageJson.dependencies.postcss = constants.POSTCSS_VERSION
}

// patch-package support
packageJson.devDependencies['patch-package'] = constants.PATCH_PACKAGE_VERSION

// add vite dev script
packageJson.scripts['serve-vite'] = 'vite'
packageJson.scripts['build-vite'] = 'vite build'

// add postinatall
packageJson.scripts.postinstall = 'patch-package'

writeSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
}
14 changes: 14 additions & 0 deletions src/generate/genePatches.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import fs from 'fs'
import path from 'path'
import { readSync, writeSync } from '../utils/file'

export function genePatches (patchesDir: string): void {
// read all patches name
const patchesInfo = fs.readdirSync('patches');
// inject patch
patchesInfo.forEach(patch => {
const filePath = path.resolve(patchesDir, patch);
const patchContent = readSync(path.resolve('patches', patch));
writeSync(filePath, patchContent);
});
}

0 comments on commit 5e53c0b

Please sign in to comment.