Paul Gschwendtner | 4a5ce0d | 2019-01-17 19:49:54 -0800 | [diff] [blame] | 1 | // 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. |
| 3 | package main |
| 4 | |
| 5 | import ( |
| 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. |
| 14 | type RunfileFileSystem struct{} |
| 15 | |
| 16 | // StatMtime gets the filestamp for the last file modification. |
| 17 | func (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 |
| 26 | func (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 Gschwendtner | 58b1910 | 2019-02-08 11:53:07 -0800 | [diff] [blame] | 33 | func (fs *RunfileFileSystem) ResolvePath(root string, manifestFilePath string) (string, error) { |
| 34 | return runfiles.Runfile(root, manifestFilePath) |
Paul Gschwendtner | 4a5ce0d | 2019-01-17 19:49:54 -0800 | [diff] [blame] | 35 | } |