new-project subcommand mostly works
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package kiss;
|
||||
|
||||
import sys.io.Process;
|
||||
#if macro
|
||||
import haxe.macro.Expr;
|
||||
import kiss.Kiss;
|
||||
@@ -7,9 +8,16 @@ import kiss.Reader;
|
||||
import kiss.Stream;
|
||||
|
||||
using tink.MacroApi;
|
||||
using StringTools;
|
||||
#end
|
||||
|
||||
import haxe.Json;
|
||||
import haxe.io.Path;
|
||||
import sys.io.File;
|
||||
import sys.io.Process;
|
||||
import sys.FileSystem;
|
||||
|
||||
using StringTools;
|
||||
|
||||
class Main {
|
||||
static function main() {
|
||||
macroMain();
|
||||
@@ -24,6 +32,8 @@ class Main {
|
||||
switch (args.shift()) {
|
||||
case "convert":
|
||||
convert(args);
|
||||
case "new-project":
|
||||
newProject(args);
|
||||
case other:
|
||||
// TODO show a helpful list of subcommands
|
||||
Sys.println('$other is not a kiss subcommand');
|
||||
@@ -33,13 +43,71 @@ class Main {
|
||||
return macro null;
|
||||
}
|
||||
|
||||
static function promptFor(what:String, ?defaultVal:String) {
|
||||
var prompt = what;
|
||||
if (defaultVal != null) {
|
||||
if (defaultVal.length == 0) {
|
||||
prompt += ' (default empty)';
|
||||
} else {
|
||||
prompt += ' (default $defaultVal)';
|
||||
}
|
||||
}
|
||||
prompt += ": ";
|
||||
Sys.print(prompt);
|
||||
var input = Sys.stdin().readLine();
|
||||
if (input.trim().length == 0) {
|
||||
if (defaultVal != null) {
|
||||
input = defaultVal;
|
||||
} else {
|
||||
Sys.println('value required for $what');
|
||||
Sys.exit(1);
|
||||
}
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
static function makeFileForNewProject(templateFile:Array<String>, projectName:String, pkg:String) {
|
||||
var kissLibPath = new Process("haxelib", ["libpath", "kiss"]).stdout.readAll().toString().trim();
|
||||
var fullTemplateFilePath = Path.join([kissLibPath, "template"].concat(templateFile));
|
||||
var newFileContent = File.getContent(fullTemplateFilePath).replace("template", pkg);
|
||||
var templateFileInNewProject = [for (part in templateFile) if (part == "template") pkg else part];
|
||||
var newFilePath = Path.join([projectName].concat(templateFileInNewProject));
|
||||
File.saveContent(newFilePath, newFileContent);
|
||||
}
|
||||
|
||||
static function newProject(args:Array<String>) {
|
||||
var name = promptFor("name");
|
||||
var pkg = name.replace("-", "_");
|
||||
var haxelibJson = {
|
||||
"name": name,
|
||||
"url": promptFor("url"),
|
||||
"license": promptFor("license", "LGPL"),
|
||||
"tags": promptFor("tags (comma-separated)", "").split(","),
|
||||
"description": promptFor("description", ""),
|
||||
"version": "0.0.0",
|
||||
"releasenote": "",
|
||||
"contributors": [promptFor("author")],
|
||||
"classPath": "src/",
|
||||
"main": '${pkg}.Main',
|
||||
"dependencies": {
|
||||
"kiss": ""
|
||||
}
|
||||
};
|
||||
FileSystem.createDirectory('$name/src/$pkg');
|
||||
makeFileForNewProject(["src", "template", "Main.hx"], name, pkg);
|
||||
makeFileForNewProject(["src", "template", "Main.kiss"], name, pkg);
|
||||
makeFileForNewProject(["build.hxml"], name, pkg);
|
||||
makeFileForNewProject(["test.sh"], name, pkg);
|
||||
File.saveContent('$name/haxelib.json', Json.stringify(haxelibJson));
|
||||
}
|
||||
|
||||
static function convert(args:Array<String>) {
|
||||
// `kiss convert` converts its stdin input to Haxe expressions.
|
||||
// with --all, it reads everything from stdin at once (for piping). Without --all, it acts as a repl,
|
||||
// where \ at the end of a line signals that the expression is not complete
|
||||
// TODO write tests for this
|
||||
// TODO use this to implement runAtRuntime() for sys targets by running a haxe subprocess
|
||||
|
||||
#if macro
|
||||
var k = Kiss.defaultKissState();
|
||||
k.wrapListExps = false;
|
||||
var pretty = args.indexOf("--pretty") != -1;
|
||||
@@ -83,7 +151,6 @@ class Main {
|
||||
}
|
||||
} catch (e:haxe.io.Eof) {}
|
||||
}
|
||||
|
||||
var line = "";
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
4
kiss/template/build.hxml
Normal file
4
kiss/template/build.hxml
Normal file
@@ -0,0 +1,4 @@
|
||||
-lib kiss
|
||||
-cp src
|
||||
--main template.Main
|
||||
--interp
|
15
kiss/template/haxelib.json
Normal file
15
kiss/template/haxelib.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "template",
|
||||
"url": "https://github.com/hissvn/kisslang",
|
||||
"license": "LGPL",
|
||||
"tags": [],
|
||||
"description": "",
|
||||
"version": "0.0.0",
|
||||
"releasenote": "",
|
||||
"contributors": ["NQNStudios"],
|
||||
"classPath": "src/",
|
||||
"main": "template.Main",
|
||||
"dependencies": {
|
||||
"kiss": ""
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package;
|
||||
package template;
|
||||
|
||||
import kiss.Kiss;
|
||||
import kiss.Prelude;
|
0
template/test.sh → kiss/template/test.sh
Executable file → Normal file
0
template/test.sh → kiss/template/test.sh
Executable file → Normal file
@@ -1,4 +0,0 @@
|
||||
-lib kiss
|
||||
-cp src
|
||||
--main Main
|
||||
--interp
|
Reference in New Issue
Block a user