blob: 090ded64d5dd723acfd56943226e6394f3cc2abf [file] [log] [blame]
Paul Gschwendtner4a5ce0d2019-01-17 19:49:54 -08001// Main package that provides a command line interface for starting a Bazel devserver
2// using Bazel runfile resolution and ConcatJS for in-memory bundling of specified AMD files.
3package main
4
5import (
6 "io/ioutil"
7 "os"
8 "time"
9
10 "github.com/bazelbuild/rules_typescript/devserver/runfiles"
11)
12
13// RunfileFileSystem implements FileSystem type from concatjs.
14type RunfileFileSystem struct{}
15
16// StatMtime gets the filestamp for the last file modification.
17func (fs *RunfileFileSystem) StatMtime(filename string) (time.Time, error) {
18 s, err := os.Stat(filename)
19 if err != nil {
20 return time.Time{}, err
21 }
22 return s.ModTime(), nil
23}
24
25// ReadFile reads a file given its file name
26func (fs *RunfileFileSystem) ReadFile(filename string) ([]byte, error) {
27 return ioutil.ReadFile(filename)
28}
29
30// ResolvePath resolves the specified path within a given root using Bazel's runfile resolution.
31// This is necessary because on Windows, runfiles are not symlinked and need to be
32// resolved using the runfile manifest file.
Paul Gschwendtner58b19102019-02-08 11:53:07 -080033func (fs *RunfileFileSystem) ResolvePath(root string, manifestFilePath string) (string, error) {
34 return runfiles.Runfile(root, manifestFilePath)
Paul Gschwendtner4a5ce0d2019-01-17 19:49:54 -080035}