mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(cli): find root dir
This commit is contained in:
parent
71415e467d
commit
c86d3d166f
@ -1,12 +1,12 @@
|
|||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { exec } from 'shelljs';
|
import { exec } from 'shelljs';
|
||||||
|
import { ROOT } from '../common/constant';
|
||||||
|
|
||||||
export function changelog(dist: string, cmd: { tag?: string }) {
|
export function changelog(dist: string, cmd: { tag?: string }) {
|
||||||
const basepath = process.cwd();
|
|
||||||
const tag = cmd.tag || 'v1.0.0';
|
const tag = cmd.tag || 'v1.0.0';
|
||||||
|
|
||||||
exec(`
|
exec(`
|
||||||
basepath=${basepath}
|
basepath=${ROOT}
|
||||||
|
|
||||||
github_changelog_generator \
|
github_changelog_generator \
|
||||||
--header-label "# 更新日志" \
|
--header-label "# 更新日志" \
|
||||||
@ -18,6 +18,6 @@ export function changelog(dist: string, cmd: { tag?: string }) {
|
|||||||
--no-author \
|
--no-author \
|
||||||
--no-unreleased \
|
--no-unreleased \
|
||||||
--since-tag ${tag} \
|
--since-tag ${tag} \
|
||||||
-o ${join(basepath, dist)}
|
-o ${join(ROOT, dist)}
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { runCLI } from 'jest';
|
import { runCLI } from 'jest';
|
||||||
import { setNodeEnv } from '../common';
|
import { setNodeEnv } from '../common';
|
||||||
import { genPackageEntry } from '../compiler/gen-package-entry';
|
import { genPackageEntry } from '../compiler/gen-package-entry';
|
||||||
import { CWD, JEST_CONFIG_FILE, PACKAGE_ENTRY_FILE } from '../common/constant';
|
import { ROOT, JEST_CONFIG_FILE, PACKAGE_ENTRY_FILE } from '../common/constant';
|
||||||
|
|
||||||
export function test(command: any) {
|
export function test(command: any) {
|
||||||
setNodeEnv('test');
|
setNodeEnv('test');
|
||||||
@ -11,10 +11,10 @@ export function test(command: any) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
rootDir: CWD,
|
rootDir: ROOT,
|
||||||
watch: command.watch,
|
watch: command.watch,
|
||||||
config: JEST_CONFIG_FILE
|
config: JEST_CONFIG_FILE
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
runCLI(config, [CWD]);
|
runCLI(config, [ROOT]);
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,28 @@
|
|||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import { join, isAbsolute } from 'path';
|
import { existsSync } from 'fs-extra';
|
||||||
|
import { join, dirname, isAbsolute } from 'path';
|
||||||
|
|
||||||
|
function findRootDir(dir: string): string {
|
||||||
|
if (dir === '/') {
|
||||||
|
return '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existsSync(join(dir, 'vant.config.js'))) {
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
return findRootDir(dirname(dir));
|
||||||
|
}
|
||||||
|
|
||||||
export const CWD = process.cwd();
|
export const CWD = process.cwd();
|
||||||
export const ES_DIR = join(CWD, 'es');
|
export const ROOT = findRootDir(CWD);
|
||||||
export const LIB_DIR = join(CWD, 'lib');
|
export const ES_DIR = join(ROOT, 'es');
|
||||||
export const DOCS_DIR = join(CWD, 'docs');
|
export const LIB_DIR = join(ROOT, 'lib');
|
||||||
export const SITE_DIST_DIR = join(CWD, 'site');
|
export const DOCS_DIR = join(ROOT, 'docs');
|
||||||
export const VANT_CONFIG_FILE = join(CWD, 'vant.config.js');
|
export const SITE_DIST_DIR = join(ROOT, 'site');
|
||||||
export const PACKAGE_JSON_FILE = join(CWD, 'package.json');
|
export const VANT_CONFIG_FILE = join(ROOT, 'vant.config.js');
|
||||||
export const WEBPACK_CONFIG_FILE = join(CWD, 'webpack.config.js');
|
export const PACKAGE_JSON_FILE = join(ROOT, 'package.json');
|
||||||
|
export const WEBPACK_CONFIG_FILE = join(ROOT, 'webpack.config.js');
|
||||||
|
|
||||||
export const DIST_DIR = join(__dirname, '../../dist');
|
export const DIST_DIR = join(__dirname, '../../dist');
|
||||||
export const CONFIG_DIR = join(__dirname, '../config');
|
export const CONFIG_DIR = join(__dirname, '../config');
|
||||||
@ -19,10 +33,10 @@ export const SITE_MODILE_SHARED_FILE = join(DIST_DIR, 'site-mobile-shared.js');
|
|||||||
export const SITE_DESKTOP_SHARED_FILE = join(DIST_DIR, 'site-desktop-shared.js');
|
export const SITE_DESKTOP_SHARED_FILE = join(DIST_DIR, 'site-desktop-shared.js');
|
||||||
export const STYPE_DEPS_JSON_FILE = join(DIST_DIR, 'style-deps.json');
|
export const STYPE_DEPS_JSON_FILE = join(DIST_DIR, 'style-deps.json');
|
||||||
|
|
||||||
export const JEST_CONFIG_FILE = join(CONFIG_DIR, 'jest.config.js');
|
|
||||||
export const BABEL_CONFIG_FILE = join(CONFIG_DIR, 'babel.config.js');
|
export const BABEL_CONFIG_FILE = join(CONFIG_DIR, 'babel.config.js');
|
||||||
export const POSTCSS_CONFIG_FILE = join(CONFIG_DIR, 'postcss.config.js');
|
export const POSTCSS_CONFIG_FILE = join(CONFIG_DIR, 'postcss.config.js');
|
||||||
export const JEST_INIT_FILE = join(CONFIG_DIR, 'jest.init.js');
|
export const JEST_INIT_FILE = join(CONFIG_DIR, 'jest.init.js');
|
||||||
|
export const JEST_CONFIG_FILE = join(CONFIG_DIR, 'jest.config.js');
|
||||||
export const JEST_TRANSFORM_FILE = join(CONFIG_DIR, 'jest.transform.js');
|
export const JEST_TRANSFORM_FILE = join(CONFIG_DIR, 'jest.transform.js');
|
||||||
export const JEST_FILE_MOCK_FILE = join(CONFIG_DIR, 'jest.file-mock.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_STYLE_MOCK_FILE = join(CONFIG_DIR, 'jest.style-mock.js');
|
||||||
@ -47,10 +61,10 @@ function getSrcDir() {
|
|||||||
return srcDir;
|
return srcDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
return join(CWD, srcDir);
|
return join(ROOT, srcDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
return join(CWD, 'src');
|
return join(ROOT, 'src');
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SRC_DIR = getSrcDir();
|
export const SRC_DIR = getSrcDir();
|
||||||
|
@ -4,7 +4,7 @@ import { join } from 'path';
|
|||||||
import { transformFileAsync } from '@babel/core';
|
import { transformFileAsync } from '@babel/core';
|
||||||
import { removeSync, outputFileSync, existsSync } from 'fs-extra';
|
import { removeSync, outputFileSync, existsSync } from 'fs-extra';
|
||||||
import { replaceExt } from '../common';
|
import { replaceExt } from '../common';
|
||||||
import { CWD, DIST_DIR } from '../common/constant';
|
import { ROOT, DIST_DIR } from '../common/constant';
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
// whether to fouce reload babel config
|
// whether to fouce reload babel config
|
||||||
@ -14,7 +14,7 @@ type Options = {
|
|||||||
const TEMP_BABEL_CONFIG = join(DIST_DIR, 'babel.config.js');
|
const TEMP_BABEL_CONFIG = join(DIST_DIR, 'babel.config.js');
|
||||||
|
|
||||||
function genTempBabelConfig() {
|
function genTempBabelConfig() {
|
||||||
const { config } = findBabelConfig.sync(CWD);
|
const { config } = findBabelConfig.sync(ROOT);
|
||||||
const content = `module.exports = function (api) {
|
const content = `module.exports = function (api) {
|
||||||
api.cache.never();
|
api.cache.never();
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import sass from 'sass';
|
|||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import { VueLoaderPlugin } from 'vue-loader';
|
import { VueLoaderPlugin } from 'vue-loader';
|
||||||
import {
|
import {
|
||||||
CWD,
|
ROOT,
|
||||||
STYLE_EXTS,
|
STYLE_EXTS,
|
||||||
SCRIPT_EXTS,
|
SCRIPT_EXTS,
|
||||||
POSTCSS_CONFIG_FILE
|
POSTCSS_CONFIG_FILE
|
||||||
@ -63,7 +63,7 @@ export const baseConfig = {
|
|||||||
{
|
{
|
||||||
loader: 'less-loader',
|
loader: 'less-loader',
|
||||||
options: {
|
options: {
|
||||||
paths: [resolve(CWD, 'node_modules')]
|
paths: [resolve(ROOT, 'node_modules')]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user