equal
deleted
inserted
replaced
|
1 import ammonite.ops._ |
|
2 import os.FileType.{Dir, File} |
|
3 import ujson.{Obj, Str, Value} |
|
4 |
|
5 import scala.collection.mutable |
|
6 |
|
7 def fs2json(p: Path): Obj = { |
|
8 val l: Seq[(String, Value)] = ls(p) flatMap { f => f.fileType match { |
|
9 case Dir => Some(f.last -> fs2json(f)) |
|
10 case File if f.last endsWith ".json" => |
|
11 Some(f.last.dropRight(5) -> ujson.read(os.read(f))) |
|
12 case File => |
|
13 val n = f.last.split("\\.").toList match { |
|
14 case v :: Nil => v |
|
15 case v => v dropRight 1 mkString "." |
|
16 } |
|
17 Some(n -> Str(os.read(f).stripLineEnd)) |
|
18 case _ => None |
|
19 }} |
|
20 Obj(mutable.LinkedHashMap.from(l)) |
|
21 } |
|
22 |
|
23 // vim: et sw=2 ts=2 syn=scala |