Variadic joinPath. Close #20
This commit is contained in:
@@ -60,6 +60,7 @@ class Kiss {
|
|||||||
"pairs" => Symbol("Prelude.pairs"), // TODO test pairs
|
"pairs" => Symbol("Prelude.pairs"), // TODO test pairs
|
||||||
"reversed" => Symbol("Prelude.reversed"), // TODO test reversed
|
"reversed" => Symbol("Prelude.reversed"), // TODO test reversed
|
||||||
"memoize" => Symbol("Prelude.memoize"), // TODO test memoize
|
"memoize" => Symbol("Prelude.memoize"), // TODO test memoize
|
||||||
|
"joinPath" => Symbol("Prelude.joinPath"),
|
||||||
"symbolName" => Symbol("Prelude.symbolName"),
|
"symbolName" => Symbol("Prelude.symbolName"),
|
||||||
"symbolNameValue" => Symbol("Prelude.symbolNameValue"),
|
"symbolNameValue" => Symbol("Prelude.symbolNameValue"),
|
||||||
"symbol" => Symbol("Prelude.symbol"),
|
"symbol" => Symbol("Prelude.symbol"),
|
||||||
|
@@ -12,6 +12,7 @@ import js.node.Buffer;
|
|||||||
import sys.io.Process;
|
import sys.io.Process;
|
||||||
#end
|
#end
|
||||||
import uuid.Uuid;
|
import uuid.Uuid;
|
||||||
|
import haxe.io.Path;
|
||||||
|
|
||||||
using StringTools;
|
using StringTools;
|
||||||
using uuid.Uuid;
|
using uuid.Uuid;
|
||||||
@@ -239,7 +240,7 @@ class Prelude {
|
|||||||
|
|
||||||
// Ranges with a min, exclusive max, and step size, just like Python.
|
// Ranges with a min, exclusive max, and step size, just like Python.
|
||||||
public static function range(min, max, step):Iterator<Int> {
|
public static function range(min, max, step):Iterator<Int> {
|
||||||
if (step <= 0)
|
if (step <= 0 || max < min)
|
||||||
throw "(range...) can only count up";
|
throw "(range...) can only count up";
|
||||||
var count = min;
|
var count = min;
|
||||||
return {
|
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) {
|
public static dynamic function truthy<T>(v:T) {
|
||||||
return switch (Type.typeof(v)) {
|
return switch (Type.typeof(v)) {
|
||||||
case TNull: false;
|
case TNull: false;
|
||||||
|
@@ -250,9 +250,9 @@
|
|||||||
currentFileDirectory
|
currentFileDirectory
|
||||||
(Path.directory currentFile)
|
(Path.directory currentFile)
|
||||||
haxeFile
|
haxeFile
|
||||||
(Path.join [currentFileDirectory "${className}.hx"])
|
(joinPath currentFileDirectory "${className}.hx")
|
||||||
kissFile
|
kissFile
|
||||||
(Path.join [currentFileDirectory "${className}.kiss"])
|
(joinPath currentFileDirectory "${className}.kiss")
|
||||||
// Try to use the same package statement from the first line of the
|
// Try to use the same package statement from the first line of the
|
||||||
// currently open Kiss class's .hx file
|
// currently open Kiss class's .hx file
|
||||||
pkg
|
pkg
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
(defun userConfigDir []
|
(defun userConfigDir []
|
||||||
(Path.join [
|
(joinPath
|
||||||
(or (Sys.getEnv "MSYSHOME") (Sys.getEnv "HOME") (Sys.getEnv "UserProfile"))
|
(or (Sys.getEnv "MSYSHOME") (Sys.getEnv "HOME") (Sys.getEnv "UserProfile"))
|
||||||
".kiss"]))
|
".kiss"))
|
||||||
|
|
||||||
(defvar &mut activeConfigDir "")
|
(defvar &mut activeConfigDir "")
|
||||||
(defvar &mut lastConfigDir "")
|
(defvar &mut lastConfigDir "")
|
||||||
@@ -22,12 +22,12 @@
|
|||||||
(let [customConfigDir
|
(let [customConfigDir
|
||||||
(#if test
|
(#if test
|
||||||
// When running unit tests, build the example config
|
// 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
|
// When running for real, try the user's config directory
|
||||||
(if (FileSystem.exists (userConfigDir))
|
(if (FileSystem.exists (userConfigDir))
|
||||||
(userConfigDir)
|
(userConfigDir)
|
||||||
// Supply the default (empty) config if the user doesn't have one
|
// 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 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?
|
// 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
|
// Copy the boilerplate config files to the active config directory
|
||||||
(doFor file ["build.hxml" "KissConfig.hx" "KissConfig.kiss"]
|
(doFor file ["build.hxml" "KissConfig.hx" "KissConfig.kiss"]
|
||||||
(File.copy
|
(File.copy
|
||||||
(Path.join [builtinConfigDir file])
|
(joinPath builtinConfigDir file)
|
||||||
(Path.join [activeConfigDir file])))
|
(joinPath activeConfigDir file)))
|
||||||
// Copy the user's custom config files to the active config directory
|
// Copy the user's custom config files to the active config directory
|
||||||
(doFor file customConfigFiles
|
(doFor file customConfigFiles
|
||||||
(File.copy
|
(File.copy
|
||||||
(Path.join [customConfigDir file])
|
(joinPath customConfigDir file)
|
||||||
(Path.join [activeConfigDir file])))
|
(joinPath activeConfigDir file)))
|
||||||
// When running from unit tests, install all dependencies in the example config:
|
// When running from unit tests, install all dependencies in the example config:
|
||||||
(#when test (ChildProcess.spawnSync "haxelib" ["install" "all"] (object cwd activeConfigDir)))
|
(#when test (ChildProcess.spawnSync "haxelib" ["install" "all"] (object cwd activeConfigDir)))
|
||||||
// Run the haxe compiler:
|
// Run the haxe compiler:
|
||||||
@@ -55,8 +55,8 @@
|
|||||||
// Require the config.js package.
|
// Require the config.js package.
|
||||||
// But since Node.require() caches modules by filename,
|
// But since Node.require() caches modules by filename,
|
||||||
// copy it to a unique path first so hot-reloading works properly.
|
// copy it to a unique path first so hot-reloading works properly.
|
||||||
(let [activeConfigFile (Path.join [activeConfigDir "config.js"])
|
(let [activeConfigFile (joinPath activeConfigDir "config.js")
|
||||||
uniqueConfigFile (Path.join [activeConfigDir "$(.toShort (Uuid.v4)).js"])]
|
uniqueConfigFile (joinPath activeConfigDir "$(.toShort (Uuid.v4)).js")]
|
||||||
(File.copy activeConfigFile uniqueConfigFile)
|
(File.copy activeConfigFile uniqueConfigFile)
|
||||||
(set config (the KissConfig .KissConfig (Node.require uniqueConfigFile)))
|
(set config (the KissConfig .KissConfig (Node.require uniqueConfigFile)))
|
||||||
// (FileSystem.deleteFile uniqueConfigFile)
|
// (FileSystem.deleteFile uniqueConfigFile)
|
||||||
@@ -116,9 +116,9 @@
|
|||||||
|
|
||||||
// TODO overload Prelude.print to use showInformationMessage
|
// TODO overload Prelude.print to use showInformationMessage
|
||||||
|
|
||||||
(set builtinConfigDir (Path.join [context.extensionPath "config"]))
|
(set builtinConfigDir (joinPath context.extensionPath "config"))
|
||||||
(set activeConfigDir (Path.join [context.extensionPath "_activeConfig"]))
|
(set activeConfigDir (joinPath context.extensionPath "_activeConfig"))
|
||||||
(set lastConfigDir (Path.join [context.extensionPath "_lastActiveConfig"]))
|
(set lastConfigDir (joinPath context.extensionPath "_lastActiveConfig"))
|
||||||
(tryLoadConfig)))
|
(tryLoadConfig)))
|
||||||
|
|
||||||
(defun :Void main []
|
(defun :Void main []
|
||||||
|
@@ -3,12 +3,12 @@
|
|||||||
[:Array<System> systems
|
[:Array<System> systems
|
||||||
[]
|
[]
|
||||||
:Map<String,Entry> entries
|
:Map<String,Entry> entries
|
||||||
(let [entryDir (Path.join [archiveDir "entries"])
|
(let [entryDir (joinPath archiveDir "entries")
|
||||||
componentDir (Path.join [archiveDir "components"])]
|
componentDir (joinPath archiveDir "components")]
|
||||||
(FileSystem.createDirectory entryDir)
|
(FileSystem.createDirectory entryDir)
|
||||||
(FileSystem.createDirectory componentDir)
|
(FileSystem.createDirectory componentDir)
|
||||||
(let [entryFiles (FileSystem.readDirectory entryDir)]
|
(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]
|
(defmethod addSystem [:System system]
|
||||||
// Assign entries to the Systems that care about them
|
// Assign entries to the Systems that care about them
|
||||||
@@ -33,11 +33,11 @@
|
|||||||
|
|
||||||
(defmethod _saveEntry [:Entry e]
|
(defmethod _saveEntry [:Entry e]
|
||||||
(File.saveContent
|
(File.saveContent
|
||||||
(Path.join [archiveDir "entries" (e.id.withExtension "json")])
|
(joinPath archiveDir "entries" (e.id.withExtension "json"))
|
||||||
(Json.stringify e)))
|
(Json.stringify e)))
|
||||||
|
|
||||||
(defmethod componentData [:Entry e :String componentType]
|
(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]
|
(defmethod fullData [:Entry e]
|
||||||
(object
|
(object
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
`(.exists .components ,e ,(symbolName componentType)))
|
`(.exists .components ,e ,(symbolName componentType)))
|
||||||
|
|
||||||
(defmacro _componentPath [archive e 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
|
// Changes to the object returned by (readComponent) will not be saved! Use (withWritableComponents) for making changes
|
||||||
(defmacro readComponent [archive e componentType]
|
(defmacro readComponent [archive e componentType]
|
||||||
|
Reference in New Issue
Block a user