Variadic joinPath. Close #20

This commit is contained in:
2021-07-23 14:58:36 -06:00
parent d073f819fa
commit a18a4d8150
6 changed files with 30 additions and 22 deletions

View File

@@ -60,6 +60,7 @@ class Kiss {
"pairs" => Symbol("Prelude.pairs"), // TODO test pairs
"reversed" => Symbol("Prelude.reversed"), // TODO test reversed
"memoize" => Symbol("Prelude.memoize"), // TODO test memoize
"joinPath" => Symbol("Prelude.joinPath"),
"symbolName" => Symbol("Prelude.symbolName"),
"symbolNameValue" => Symbol("Prelude.symbolNameValue"),
"symbol" => Symbol("Prelude.symbol"),

View File

@@ -12,6 +12,7 @@ import js.node.Buffer;
import sys.io.Process;
#end
import uuid.Uuid;
import haxe.io.Path;
using StringTools;
using uuid.Uuid;
@@ -239,7 +240,7 @@ class Prelude {
// Ranges with a min, exclusive max, and step size, just like Python.
public static function range(min, max, step):Iterator<Int> {
if (step <= 0)
if (step <= 0 || max < min)
throw "(range...) can only count up";
var count = min;
return {
@@ -254,6 +255,12 @@ class Prelude {
};
}
static function _joinPath(parts:Array<Dynamic>) {
return Path.join([for (part in parts) cast(part, String)]);
}
public static var joinPath:Function = Reflect.makeVarArgs(_joinPath);
public static dynamic function truthy<T>(v:T) {
return switch (Type.typeof(v)) {
case TNull: false;

View File

@@ -250,9 +250,9 @@
currentFileDirectory
(Path.directory currentFile)
haxeFile
(Path.join [currentFileDirectory "${className}.hx"])
(joinPath currentFileDirectory "${className}.hx")
kissFile
(Path.join [currentFileDirectory "${className}.kiss"])
(joinPath currentFileDirectory "${className}.kiss")
// Try to use the same package statement from the first line of the
// currently open Kiss class's .hx file
pkg

View File

@@ -1,7 +1,7 @@
(defun userConfigDir []
(Path.join [
(joinPath
(or (Sys.getEnv "MSYSHOME") (Sys.getEnv "HOME") (Sys.getEnv "UserProfile"))
".kiss"]))
".kiss"))
(defvar &mut activeConfigDir "")
(defvar &mut lastConfigDir "")
@@ -22,12 +22,12 @@
(let [customConfigDir
(#if test
// When running unit tests, build the example config
(Path.join [builtinConfigDir "example"])
(joinPath builtinConfigDir "example")
// When running for real, try the user's config directory
(if (FileSystem.exists (userConfigDir))
(userConfigDir)
// Supply the default (empty) config if the user doesn't have one
(Path.join [builtinConfigDir "default"])))
(joinPath builtinConfigDir "default")))
// TODO this isn't recursive, so it doesn't allow the user to organize their config with folders
// TODO it would also attempt to copy over any documentation cache in the .kiss directory, but does File.copy work on directories?
@@ -37,13 +37,13 @@
// Copy the boilerplate config files to the active config directory
(doFor file ["build.hxml" "KissConfig.hx" "KissConfig.kiss"]
(File.copy
(Path.join [builtinConfigDir file])
(Path.join [activeConfigDir file])))
(joinPath builtinConfigDir file)
(joinPath activeConfigDir file)))
// Copy the user's custom config files to the active config directory
(doFor file customConfigFiles
(File.copy
(Path.join [customConfigDir file])
(Path.join [activeConfigDir file])))
(joinPath customConfigDir file)
(joinPath activeConfigDir file)))
// When running from unit tests, install all dependencies in the example config:
(#when test (ChildProcess.spawnSync "haxelib" ["install" "all"] (object cwd activeConfigDir)))
// Run the haxe compiler:
@@ -55,8 +55,8 @@
// Require the config.js package.
// But since Node.require() caches modules by filename,
// copy it to a unique path first so hot-reloading works properly.
(let [activeConfigFile (Path.join [activeConfigDir "config.js"])
uniqueConfigFile (Path.join [activeConfigDir "$(.toShort (Uuid.v4)).js"])]
(let [activeConfigFile (joinPath activeConfigDir "config.js")
uniqueConfigFile (joinPath activeConfigDir "$(.toShort (Uuid.v4)).js")]
(File.copy activeConfigFile uniqueConfigFile)
(set config (the KissConfig .KissConfig (Node.require uniqueConfigFile)))
// (FileSystem.deleteFile uniqueConfigFile)
@@ -116,9 +116,9 @@
// TODO overload Prelude.print to use showInformationMessage
(set builtinConfigDir (Path.join [context.extensionPath "config"]))
(set activeConfigDir (Path.join [context.extensionPath "_activeConfig"]))
(set lastConfigDir (Path.join [context.extensionPath "_lastActiveConfig"]))
(set builtinConfigDir (joinPath context.extensionPath "config"))
(set activeConfigDir (joinPath context.extensionPath "_activeConfig"))
(set lastConfigDir (joinPath context.extensionPath "_lastActiveConfig"))
(tryLoadConfig)))
(defun :Void main []

View File

@@ -3,12 +3,12 @@
[:Array<System> systems
[]
:Map<String,Entry> entries
(let [entryDir (Path.join [archiveDir "entries"])
componentDir (Path.join [archiveDir "components"])]
(let [entryDir (joinPath archiveDir "entries")
componentDir (joinPath archiveDir "components")]
(FileSystem.createDirectory entryDir)
(FileSystem.createDirectory componentDir)
(let [entryFiles (FileSystem.readDirectory entryDir)]
(for file entryFiles =>(file.withoutExtension) (the Entry (Json.parse (File.getContent (Path.join [archiveDir "entries" file])))))))])
(for file entryFiles =>(file.withoutExtension) (the Entry (Json.parse (File.getContent (joinPath archiveDir "entries" file)))))))])
(defmethod addSystem [:System system]
// Assign entries to the Systems that care about them
@@ -33,11 +33,11 @@
(defmethod _saveEntry [:Entry e]
(File.saveContent
(Path.join [archiveDir "entries" (e.id.withExtension "json")])
(joinPath archiveDir "entries" (e.id.withExtension "json"))
(Json.stringify e)))
(defmethod componentData [:Entry e :String componentType]
(haxe.Json.parse (File.getContent (haxe.io.Path.join [archiveDir "components" "$(dictGet e.components componentType).json"]))))
(haxe.Json.parse (File.getContent (joinPath archiveDir "components" "$(dictGet e.components componentType).json"))))
(defmethod fullData [:Entry e]
(object

View File

@@ -5,7 +5,7 @@
`(.exists .components ,e ,(symbolName componentType)))
(defmacro _componentPath [archive e componentType]
`(haxe.io.Path.join [.archiveDir (the nat.Archive ,archive) "components" (+ (dictGet (the Map<String,String> .components ,e) ,(symbolName componentType)) ".json")]))
`(joinPath .archiveDir (the nat.Archive ,archive) "components" (+ (dictGet (the Map<String,String> .components ,e) ,(symbolName componentType)) ".json")))
// Changes to the object returned by (readComponent) will not be saved! Use (withWritableComponents) for making changes
(defmacro readComponent [archive e componentType]