new-project subcommand mostly works
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package kiss;
|
package kiss;
|
||||||
|
|
||||||
|
import sys.io.Process;
|
||||||
#if macro
|
#if macro
|
||||||
import haxe.macro.Expr;
|
import haxe.macro.Expr;
|
||||||
import kiss.Kiss;
|
import kiss.Kiss;
|
||||||
@@ -7,9 +8,16 @@ import kiss.Reader;
|
|||||||
import kiss.Stream;
|
import kiss.Stream;
|
||||||
|
|
||||||
using tink.MacroApi;
|
using tink.MacroApi;
|
||||||
using StringTools;
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
import haxe.Json;
|
||||||
|
import haxe.io.Path;
|
||||||
|
import sys.io.File;
|
||||||
|
import sys.io.Process;
|
||||||
|
import sys.FileSystem;
|
||||||
|
|
||||||
|
using StringTools;
|
||||||
|
|
||||||
class Main {
|
class Main {
|
||||||
static function main() {
|
static function main() {
|
||||||
macroMain();
|
macroMain();
|
||||||
@@ -24,6 +32,8 @@ class Main {
|
|||||||
switch (args.shift()) {
|
switch (args.shift()) {
|
||||||
case "convert":
|
case "convert":
|
||||||
convert(args);
|
convert(args);
|
||||||
|
case "new-project":
|
||||||
|
newProject(args);
|
||||||
case other:
|
case other:
|
||||||
// TODO show a helpful list of subcommands
|
// TODO show a helpful list of subcommands
|
||||||
Sys.println('$other is not a kiss subcommand');
|
Sys.println('$other is not a kiss subcommand');
|
||||||
@@ -33,13 +43,71 @@ class Main {
|
|||||||
return macro null;
|
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>) {
|
static function convert(args:Array<String>) {
|
||||||
// `kiss convert` converts its stdin input to Haxe expressions.
|
// `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,
|
// 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
|
// where \ at the end of a line signals that the expression is not complete
|
||||||
// TODO write tests for this
|
// TODO write tests for this
|
||||||
// TODO use this to implement runAtRuntime() for sys targets by running a haxe subprocess
|
// TODO use this to implement runAtRuntime() for sys targets by running a haxe subprocess
|
||||||
|
#if macro
|
||||||
var k = Kiss.defaultKissState();
|
var k = Kiss.defaultKissState();
|
||||||
k.wrapListExps = false;
|
k.wrapListExps = false;
|
||||||
var pretty = args.indexOf("--pretty") != -1;
|
var pretty = args.indexOf("--pretty") != -1;
|
||||||
@@ -83,7 +151,6 @@ class Main {
|
|||||||
}
|
}
|
||||||
} catch (e:haxe.io.Eof) {}
|
} catch (e:haxe.io.Eof) {}
|
||||||
}
|
}
|
||||||
|
#end
|
||||||
var line = "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
template/build.hxml
Normal file
4
template/build.hxml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
-lib kiss
|
||||||
|
-cp src
|
||||||
|
--main template.Main
|
||||||
|
--interp
|
15
template/haxelib.json
Normal file
15
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": ""
|
||||||
|
}
|
||||||
|
}
|
7
template/src/template/Main.hx
Normal file
7
template/src/template/Main.hx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package template;
|
||||||
|
|
||||||
|
import kiss.Kiss;
|
||||||
|
import kiss.Prelude;
|
||||||
|
|
||||||
|
@:build(kiss.Kiss.build())
|
||||||
|
class Main {}
|
2
template/src/template/Main.kiss
Normal file
2
template/src/template/Main.kiss
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
(defun :Void main []
|
||||||
|
(print "Hello world!"))
|
3
template/test.sh
Normal file
3
template/test.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
haxe build.hxml
|
Reference in New Issue
Block a user