feat(cli): restart compile when vant config updated

This commit is contained in:
陈嘉涵
2019-12-04 18:10:14 +08:00
parent 2db6e2a44d
commit b19b287276
11 changed files with 152 additions and 105 deletions

View File

@@ -1,14 +1,19 @@
import { transformFileSync } from '@babel/core';
import { transformFileAsync } from '@babel/core';
import { removeSync, outputFileSync } from 'fs-extra';
import { replaceExt } from '../common';
export function compileJs(filePath: string) {
const result = transformFileSync(filePath);
export function compileJs(filePath: string): Promise<undefined> {
return new Promise((resolve, reject) => {
transformFileAsync(filePath)
.then(result => {
if (result) {
const jsFilePath = replaceExt(filePath, '.js');
if (result) {
const jsFilePath = replaceExt(filePath, '.js');
removeSync(filePath);
outputFileSync(jsFilePath, result.code);
}
removeSync(filePath);
outputFileSync(jsFilePath, result.code);
resolve();
}
})
.catch(reject);
});
}