mirror of
https://github.com/youzan/vant.git
synced 2026-05-07 01:01:01 +08:00
build: add files of vant-cli 2
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { join } from 'path';
|
||||
|
||||
export const CWD = process.cwd();
|
||||
export const SRC_DIR = join(CWD, 'src');
|
||||
export const CONFIG_FILE = join(CWD, 'components.config.js');
|
||||
export const ES_DIR = join(CWD, 'es');
|
||||
export const LIB_DIR = join(CWD, 'lib');
|
||||
export const DIST_DIR = join(__dirname, '../../dist');
|
||||
export const CONFIG_DIR = join(__dirname, '../config');
|
||||
export const MOBILE_CONFIG_FILE = join(DIST_DIR, 'mobile-config.js');
|
||||
export const DESKTOP_CONFIG_FILE = join(DIST_DIR, 'desktop-config.js');
|
||||
export const BABEL_CONFIG_FILE = join(CONFIG_DIR, 'babel.config.js');
|
||||
export const JEST_CONFIG_FILE = join(CONFIG_DIR, 'jest.config.js');
|
||||
export const JEST_FILE_MOCK_FILE = join(CONFIG_DIR, 'jest.file-mock.js');
|
||||
export const JEST_STYLE_MOCK_FILE = join(CONFIG_DIR, 'jest.style-mock.js');
|
||||
export const JEST_TRANSFORM_FILE = join(CONFIG_DIR, 'jest.transform.js');
|
||||
export const POSTCSS_CONFIG_FILE = join(CONFIG_DIR, 'postcss.config.js');
|
||||
@@ -0,0 +1,67 @@
|
||||
import fs from 'fs-extra';
|
||||
import { join } from 'path';
|
||||
import { SRC_DIR } from './constant';
|
||||
|
||||
export const EXT_REGEXP = /\.\w+$/;
|
||||
export const SFC_REGEXP = /\.(vue)$/;
|
||||
export const DEMO_REGEXP = /\/demo$/;
|
||||
export const TEST_REGEXP = /\/test$/;
|
||||
export const STYLE_REGEXP = /\.(css|less|scss)$/;
|
||||
export const SCRIPT_REGEXP = /\.(js|ts|jsx|tsx)$/;
|
||||
export const ENTRY_EXTS = ['js', 'ts', 'tsx', 'jsx', 'vue'];
|
||||
|
||||
export function removeExt(path: string) {
|
||||
return path.replace('.js', '');
|
||||
}
|
||||
|
||||
export function replaceExt(path: string, ext: string) {
|
||||
return path.replace(EXT_REGEXP, ext);
|
||||
}
|
||||
|
||||
export function getComponents() {
|
||||
const EXCLUDES = ['.DS_Store'];
|
||||
const dirs = fs.readdirSync(SRC_DIR);
|
||||
return dirs
|
||||
.filter(dir => !EXCLUDES.includes(dir))
|
||||
.filter(dir =>
|
||||
ENTRY_EXTS.some(ext => fs.existsSync(join(SRC_DIR, dir, `index.${ext}`)))
|
||||
);
|
||||
}
|
||||
|
||||
export function isDir(dir: string) {
|
||||
return fs.lstatSync(dir).isDirectory();
|
||||
}
|
||||
|
||||
export function isDemoDir(dir: string) {
|
||||
return DEMO_REGEXP.test(dir);
|
||||
}
|
||||
|
||||
export function isTestDir(dir: string) {
|
||||
return TEST_REGEXP.test(dir);
|
||||
}
|
||||
|
||||
export function isSfc(path: string) {
|
||||
return SFC_REGEXP.test(path);
|
||||
}
|
||||
|
||||
export function isStyle(path: string) {
|
||||
return STYLE_REGEXP.test(path);
|
||||
}
|
||||
|
||||
export function isScript(path: string) {
|
||||
return SCRIPT_REGEXP.test(path);
|
||||
}
|
||||
|
||||
const camelizeRE = /-(\w)/g;
|
||||
const pascalizeRE = /(\w)(\w*)/g;
|
||||
|
||||
export function camelize(str: string): string {
|
||||
return str.replace(camelizeRE, (_, c) => c.toUpperCase());
|
||||
}
|
||||
|
||||
export function pascalize(str: string): string {
|
||||
return camelize(str).replace(
|
||||
pascalizeRE,
|
||||
(_, c1, c2) => c1.toUpperCase() + c2
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user