mirror of https://github.com/tbklang/tpkg
InitCommand
- Set dependencies Project - Added support for dependencies
This commit is contained in:
parent
8e85087b4e
commit
91c1e5e1ad
|
@ -115,6 +115,7 @@ struct InitCommand
|
|||
answers[2].getValues(projDeps);
|
||||
projDeps = unique(projDeps);
|
||||
DEBUG("Dependencies wanted: ", projDeps);
|
||||
proj.setDependencies(projDeps);
|
||||
|
||||
JSONValue json = proj.serialize();
|
||||
string jsonStr = json.toPrettyString();
|
||||
|
|
|
@ -28,6 +28,7 @@ public struct Project
|
|||
private string description;
|
||||
private ProjectType type;
|
||||
private string entrypoint;
|
||||
private string[] dependencies;
|
||||
|
||||
public void setName(string name)
|
||||
{
|
||||
|
@ -49,6 +50,11 @@ public struct Project
|
|||
this.entrypoint = entrypoint;
|
||||
}
|
||||
|
||||
public void setDependencies(string[] dependencies)
|
||||
{
|
||||
this.dependencies = dependencies;
|
||||
}
|
||||
|
||||
public string getName()
|
||||
{
|
||||
return this.name;
|
||||
|
@ -69,12 +75,18 @@ public struct Project
|
|||
return this.entrypoint;
|
||||
}
|
||||
|
||||
public string[] getDependencies()
|
||||
{
|
||||
return this.dependencies;
|
||||
}
|
||||
|
||||
public JSONValue serialize()
|
||||
{
|
||||
JSONValue root;
|
||||
|
||||
root["name"] = this.name;
|
||||
root["description"] = this.description;
|
||||
root["dependencies"] = this.dependencies;
|
||||
|
||||
DEBUG(format("Serialized to: %s ", root));
|
||||
|
||||
|
@ -149,6 +161,24 @@ public struct Project
|
|||
proj.setEntrypoint(json["entrypoint"].str());
|
||||
}
|
||||
|
||||
JSONValue* projectDepsPtr = "dependencies" in json;
|
||||
string[] deps;
|
||||
if(projectDepsPtr)
|
||||
{
|
||||
foreach(JSONValue arrElem; projectDepsPtr.array())
|
||||
{
|
||||
if(arrElem.type() == JSONType.string)
|
||||
{
|
||||
deps ~= arrElem.str();
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR(format("A dependency must be a string not a '%s'", arrElem.type()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue