Handle cloning a project without package.json

This commit is contained in:
Nick O'Leary
2018-05-02 16:24:58 +01:00
parent c4d1ccb6f5
commit 53e3e08d70
5 changed files with 78 additions and 15 deletions

View File

@@ -81,9 +81,7 @@ Project.prototype.load = function () {
var promises = [];
return checkProjectFiles(project).then(function(missingFiles) {
if (missingFiles.length > 0) {
project.missingFiles = missingFiles;
}
project.missingFiles = missingFiles;
if (missingFiles.indexOf('package.json') === -1) {
project.paths['package.json'] = fspath.join(project.path,"package.json");
promises.push(fs.readFile(project.paths['package.json'],"utf8").then(function(content) {
@@ -135,9 +133,9 @@ Project.prototype.load = function () {
Project.prototype.initialise = function(user,data) {
var project = this;
if (!this.empty) {
throw new Error("Cannot initialise non-empty project");
}
// if (!this.empty) {
// throw new Error("Cannot initialise non-empty project");
// }
var files = Object.keys(defaultFileSet);
var promises = [];
@@ -148,17 +146,25 @@ Project.prototype.initialise = function(user,data) {
promises.push(settings.set('projects',projects));
}
project.files.flow = data.files.flow;
project.files.credentials = data.files.credentials;
var flowFilePath = fspath.join(project.path,project.files.flow);
var credsFilePath = getCredentialsFilename(flowFilePath);
promises.push(util.writeFile(flowFilePath,"[]"));
promises.push(util.writeFile(credsFilePath,"{}"));
files.push(project.files.flow);
files.push(project.files.credentials);
if (data.hasOwnProperty('files')) {
if (data.files.hasOwnProperty('flow') && data.files.hasOwnProperty('credentials')) {
project.files.flow = data.files.flow;
project.files.credentials = data.files.credentials;
var flowFilePath = fspath.join(project.path,project.files.flow);
var credsFilePath = getCredentialsFilename(flowFilePath);
promises.push(util.writeFile(flowFilePath,"[]"));
promises.push(util.writeFile(credsFilePath,"{}"));
files.push(project.files.flow);
files.push(project.files.credentials);
}
}
for (var file in defaultFileSet) {
if (defaultFileSet.hasOwnProperty(file)) {
promises.push(util.writeFile(fspath.join(project.path,file),defaultFileSet[file](project)));
var path = fspath.join(project.path,file);
if (!fs.existsSync(path)) {
promises.push(util.writeFile(path,defaultFileSet[file](project)));
}
}
}

View File

@@ -479,6 +479,12 @@ function getFlows() {
error.code = "project_empty";
return when.reject(error);
}
if (activeProject.missingFiles && activeProject.missingFiles.indexOf('package.json') !== -1) {
log.warn("Project missing package.json");
error = new Error("Project missing package.json");
error.code = "missing_package_file";
return when.reject(error);
}
if (!activeProject.getFlowFile()) {
log.warn("Project has no flow file");
error = new Error("Project has no flow file");