提交 4434b3de 编写于 作者: fxy060608's avatar fxy060608

wip(uts): update compiler

上级 1d401f16
......@@ -11611,17 +11611,29 @@ const GetLocationProtocol = {
};
const API_OPEN_LOCATION = 'openLocation';
const checkProps = (key, value) => {
if (value === undefined) {
return `${key} should not be empty.`;
}
if (typeof value !== 'number') {
let receivedType = typeof value;
receivedType = receivedType[0].toUpperCase() + receivedType.substring(1);
return `Expected Number, got ${receivedType} with value ${JSON.stringify(value)}.`;
}
};
const OpenLocationOptions = {
formatArgs: {
latitude(value, params) {
if (value !== 0 && !value) {
return 'latitude should not be empty.';
const checkedInfo = checkProps('latitude', value);
if (checkedInfo) {
return checkedInfo;
}
params.latitude = value;
},
longitude(value, params) {
if (value !== 0 && !value) {
return 'longitude should not be empty.';
const checkedInfo = checkProps('longitude', value);
if (checkedInfo) {
return checkedInfo;
}
params.longitude = value;
},
......
......@@ -4835,17 +4835,29 @@ const GetLocationProtocol = {
altitude: Boolean
};
const API_OPEN_LOCATION = "openLocation";
const checkProps = (key, value) => {
if (value === void 0) {
return `${key} should not be empty.`;
}
if (typeof value !== "number") {
let receivedType = typeof value;
receivedType = receivedType[0].toUpperCase() + receivedType.substring(1);
return `Expected Number, got ${receivedType} with value ${JSON.stringify(value)}.`;
}
};
const OpenLocationOptions = {
formatArgs: {
latitude(value, params) {
if (value !== 0 && !value) {
return "latitude should not be empty.";
const checkedInfo = checkProps("latitude", value);
if (checkedInfo) {
return checkedInfo;
}
params.latitude = value;
},
longitude(value, params) {
if (value !== 0 && !value) {
return "longitude should not be empty.";
const checkedInfo = checkProps("longitude", value);
if (checkedInfo) {
return checkedInfo;
}
params.longitude = value;
},
......
......@@ -11,7 +11,13 @@ import type {
UtsOutputOptions,
UtsResult,
} from './types'
import { printStartup, printUtsResult, printUtsResults, timeEnd } from './utils'
import {
printDone,
printStartup,
printUtsResult,
printUtsResults,
timeEnd,
} from './utils'
export enum UtsTarget {
KOTLIN = 'kotlin',
......@@ -124,18 +130,13 @@ function initOutputOptions(
}
}
function watch(
function initOptions(
target: UtsTarget,
{
silent,
input: { dir: inputDir, extname },
input: { dir: inputDir },
output: { dir: outputDir, sourceMap, inlineSourcesContent },
}: ToOptions
) {
fs.emptyDirSync(outputDir)
extname = extname || EXTNAME
const inputSrcDir = resolveSrcDir(target, inputDir)
const outputSrcDir = resolveSrcDir(target, outputDir)
......@@ -146,63 +147,97 @@ function watch(
sourceMap,
!!inlineSourcesContent
)
return { input, output }
}
chokidar
.watch('**/*' + extname, {
cwd: inputSrcDir,
ignored: ['**/*.d' + extname],
})
.on('add', (filename) => {
buildFile(
target,
path.resolve(inputSrcDir, filename),
input,
output
).then((res) => {
!silent && printUtsResult(res)
async function watch(target: UtsTarget, toOptions: ToOptions) {
fs.emptyDirSync(toOptions.output.dir)
const { input, output } = initOptions(target, toOptions)
const inputDir = toOptions.input.dir
const outputDir = toOptions.output.dir
const inputSrcDir = input.root
const outputSrcDir = output.outDir
const extname = toOptions.input.extname || EXTNAME
const silent = !!toOptions.silent
// 先完整编译后,再启用监听
doBuild(target, {
watch: true,
input,
output,
inputDir,
outputDir,
inputSrcDir,
outputSrcDir,
extname,
silent,
}).then(() => {
// TODO 监听动态添加的资源文件
chokidar
.watch('**/*' + extname, {
cwd: inputSrcDir,
ignored: ['**/*.d' + extname],
ignoreInitial: true,
})
})
.on('change', (filename) => {
buildFile(
target,
path.resolve(inputSrcDir, filename),
input,
output
).then((res) => {
!silent && printUtsResult(res)
.on('add', (filename) => {
buildFile(
target,
path.resolve(inputSrcDir, filename),
input,
output
).then((res) => {
if (!silent) {
printUtsResult(res)
printDone(true)
}
})
})
})
.on('unlink', (filename) => {
try {
fs.unlinkSync(path.resolve(outputSrcDir, filename))
} catch (e) {}
})
.on('ready', () => {
copyAssets(UtsTarget.KOTLIN, inputDir, outputDir, extname!)
})
.on('change', (filename) => {
buildFile(
target,
path.resolve(inputSrcDir, filename),
input,
output
).then((res) => {
if (!silent) {
printUtsResult(res)
printDone(true)
}
})
})
.on('unlink', (filename) => {
try {
fs.unlinkSync(path.resolve(outputSrcDir, filename))
} catch (e) {}
})
})
}
interface DoBuildOptions {
watch: boolean
silent: boolean
input: UtsInputOptions
output: UtsOutputOptions
inputDir: string
inputSrcDir: string
outputDir: string
outputSrcDir: string
extname: string
}
function build(
function doBuild(
target: UtsTarget,
{
watch,
silent,
input: { dir: inputDir, extname },
output: { dir: outputDir, sourceMap, inlineSourcesContent },
}: ToOptions
extname,
inputDir,
inputSrcDir,
outputDir,
input,
output,
}: DoBuildOptions
) {
fs.emptyDirSync(outputDir)
extname = extname || EXTNAME
const inputSrcDir = resolveSrcDir(target, inputDir)
const outputSrcDir = resolveSrcDir(target, outputDir)
const input = initInputOptions(target, inputSrcDir)
const output = initOutputOptions(
target,
outputSrcDir,
sourceMap,
!!inlineSourcesContent
)
const files = glob.sync('**/*' + extname, {
absolute: true,
cwd: inputSrcDir,
......@@ -224,11 +259,33 @@ function build(
)
})
.then((res) => {
!silent && printUtsResults(res)
!silent && printUtsResults(res, watch)
return res
})
}
function build(target: UtsTarget, toOptions: ToOptions) {
fs.emptyDirSync(toOptions.output.dir)
const { input, output } = initOptions(target, toOptions)
const inputDir = toOptions.input.dir
const outputDir = toOptions.output.dir
const inputSrcDir = input.root
const outputSrcDir = output.outDir
const extname = toOptions.input.extname || EXTNAME
const silent = !!toOptions.silent
return doBuild(target, {
watch: false,
input,
output,
inputDir,
outputDir,
inputSrcDir,
outputSrcDir,
extname,
silent,
})
}
function copyAssets(
target: UtsTarget,
inputDir: string,
......
......@@ -28,7 +28,15 @@ export function printStartup(target: UtsTarget, mode: string) {
)
}
export function printUtsResults(results: UtsResult[]) {
export function printDone(watch: boolean = false) {
if (watch) {
console.log(`DONE Build complete. Watching for changes...`)
} else {
console.log(`DONE Build complete.`)
}
}
export function printUtsResults(results: UtsResult[], watch: boolean = false) {
let longest = 0
let failed: UtsResult[] = []
let transformed: UtsResult[] = []
......@@ -61,6 +69,7 @@ export function printUtsResults(results: UtsResult[]) {
}
})
}
printDone(watch)
}
export function printUtsResult(result: UtsResult, maxLength = 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册