我正在尝试tsc
在 Windows 上构建一个使用(TypeScript 编译器)的项目,看起来当 SCons 调用编译器时,它在错误的目录中调用它。此外,尽管我尽最大努力使用相对路径而不是绝对路径,但它生成的命令失败了,下面是执行此操作的代码:
import os
sdk_sources = [] # some *.ts files
deployments_settings = [] # some more files
def prefix_file(file):
return os.path.join(Dir('.').abspath, 'src', str(file))
def modify_targets(target, source, env):
for x in source:
print "source: %s" % str(x)
return target, source
Tsc = Builder(
action = 'tsc --target ES5 --out $TARGETS $SOURCES',
suffix = '.js', src_suffix = '.ts', emitter = modify_targets)
env = Environment(BUILDERS = { 'Tsc' : Tsc },
BUILD_ROOT = Dir('.'),
ENV = { 'PATH' : os.environ['PATH'] })
env.Tsc(target = 'deploy/test', source = map(prefix_file, sdk_sources))
这是我运行它后发生的情况:
tsc --target ES5 --out deploy\test.js src\***.ts src\***.ts
Error reading file "C:\Program Files (x86)\Microsoft SDKs\TypeScript\lib.d.ts": File not found
Error reading file "src\***.ts": File not found
*** repeated many times ***
scons: *** [deploy\test.js] Error 1
scons: building terminated because of errors.
PS。如果我只是从 SCons 构建开始的同一目录运行生成的命令,则构建成功。
编辑:
更多信息
from subprocess import call
def name_of(file): return file.abspath
def tsc(source, target, env):
call(['tsc', '--target', 'ES5', '--out', target[0].abspath] +
map(name_of, source))
Tsc = Builder(action = tsc)
该构建器按预期工作。