Skip to content

Commit

Permalink
Skip fetching project on create if manifest already exists (#6)
Browse files Browse the repository at this point in the history
* Fix license ID
* Skip fetch on create if manifest already exists
  • Loading branch information
sqrrrl authored and grant committed Jan 16, 2018
1 parent 41cbbf6 commit e428501
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 22 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const DEBUG = false;
// Names / Paths
const PROJECT_NAME = 'clasp';
const PROJECT_MANIFEST_BASENAME = 'appsscript';
const PROJECT_MANIFEST_FULLNAME = `${PROJECT_MANIFEST_BASENAME}.json`;

// Dotfile names
const DOT = {
Expand Down Expand Up @@ -273,6 +274,22 @@ function getAPIFileType(path) {
}[extension];
}

/**
* Saves the script ID in the project dotfile.
* @param {string} scriptId The script ID
*/
function saveProjectId(scriptId) {
DOTFILE.PROJECT().write({scriptId}); // Save the script id
}

/**
* Checks if the current directory appears to be a valid project.
* @return {boolean} True if valid project, false otherwise
*/
function manifestExists() {
return fs.existsSync(PROJECT_MANIFEST_FULLNAME);
}

// CLI

/**
Expand Down Expand Up @@ -356,7 +373,10 @@ program
} else {
var scriptId = res.scriptId;
console.log(LOG.CREATE_PROJECT_FINISH(scriptId));
fetchProject(scriptId); // fetches appsscript.json, o.w. `push` breaks
saveProjectId(scriptId)
if (!manifestExists()) {
fetchProject(scriptId); // fetches appsscript.json, o.w. `push` breaks
}
}
});
});
Expand All @@ -382,7 +402,6 @@ function fetchProject(scriptId) {
logError(error, ERROR.SCRIPT_ID);
}
} else {
DOTFILE.PROJECT().write({scriptId}); // Save the script id
if (!res.files) {
return logError(null, ERROR.SCRIPT_ID_INCORRECT(scriptId));
}
Expand Down Expand Up @@ -411,6 +430,7 @@ program
.description('Clone a project')
.action((scriptId) => {
spinner.setSpinnerTitle(LOG.CLONING);
saveProjectId(scriptId)
fetchProject(scriptId);
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"add-on"
],
"author": "Grant Timmerman",
"license": "Apache 2.0",
"license": "Apache-2.0",
"dependencies": {
"anymatch": "^1.3.2",
"cli-spinner": "^0.2.6",
Expand Down

0 comments on commit e428501

Please sign in to comment.