feat(cli): support custom src dir

This commit is contained in:
陈嘉涵 2019-12-05 17:18:44 +08:00
parent 8fd530e131
commit ebe5f6ebfd
2 changed files with 28 additions and 12 deletions

View File

@ -1,17 +1,15 @@
import { join } from 'path';
import { get } from 'lodash';
import { join, isAbsolute } from 'path';
export const CWD = process.cwd();
export const ES_DIR = join(CWD, 'es');
export const LIB_DIR = join(CWD, 'lib');
export const SRC_DIR = join(CWD, 'src');
export const DOCS_DIR = join(CWD, 'docs');
export const SITE_DIST_DIR = join(CWD, 'site');
export const VANT_CONFIG_FILE = join(CWD, 'vant.config.js');
export const PACKAGE_JSON_FILE = join(CWD, 'package.json');
export const WEBPACK_CONFIG_FILE = join(CWD, 'webpack.config.js');
export const STYLE_DIR = join(SRC_DIR, 'style');
export const DIST_DIR = join(__dirname, '../../dist');
export const CONFIG_DIR = join(__dirname, '../config');
@ -32,3 +30,27 @@ export const SCRIPT_EXTS = ['.js', '.jsx', '.vue', '.ts', '.tsx'];
export const STYLE_EXTS = ['.css', '.less', '.scss'];
export const PACKAGE_JSON = require(PACKAGE_JSON_FILE);
export function getVantConfig() {
delete require.cache[VANT_CONFIG_FILE];
return require(VANT_CONFIG_FILE);
}
function getSrcDir() {
const vantConfig = getVantConfig();
const srcDir = get(vantConfig, 'build.srcDir');
if (srcDir) {
if (isAbsolute(srcDir)) {
return srcDir;
}
return join(CWD, srcDir);
}
return join(CWD, 'src');
}
export const SRC_DIR = getSrcDir();
export const STYLE_DIR = join(SRC_DIR, 'style');

View File

@ -7,7 +7,7 @@ import {
readFileSync,
outputFileSync
} from 'fs-extra';
import { SRC_DIR, WEBPACK_CONFIG_FILE, VANT_CONFIG_FILE } from './constant';
import { SRC_DIR, getVantConfig, WEBPACK_CONFIG_FILE } from './constant';
export const EXT_REGEXP = /\.\w+$/;
export const SFC_REGEXP = /\.(vue)$/;
@ -80,12 +80,6 @@ export function pascalize(str: string): string {
);
}
export function getVantConfig() {
delete require.cache[VANT_CONFIG_FILE];
return require(VANT_CONFIG_FILE);
}
export function getWebpackConfig(): object {
if (existsSync(WEBPACK_CONFIG_FILE)) {
const config = require(WEBPACK_CONFIG_FILE);
@ -129,4 +123,4 @@ export function smartOutputFile(filePath: string, content: string) {
outputFileSync(filePath, content);
}
export { decamelize };
export { decamelize, getVantConfig };