Skip to content

Commit

Permalink
clasp create now checks for .clasp.json files (#99)
Browse files Browse the repository at this point in the history
* Create now checks for .clasp.json files
* Fix nits
  • Loading branch information
campionfellin authored and grant committed Apr 6, 2018
1 parent 756a4c3 commit 72002d5
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,12 @@ Forgot ${PROJECT_NAME} commands? Get help:\n ${PROJECT_NAME} --help`,
LOGGED_OUT: `\nCommand failed. Please login. (${PROJECT_NAME} login)`,
OFFLINE: 'Error: Looks like you are offline.',
ONE_DEPLOYMENT_CREATE: 'Currently just one deployment can be created at a time.',
NO_NESTED_PROJECTS: '\nNested clasp projects are not supported.',
READ_ONLY_DELETE: 'Unable to delete read-only deployment.',
PERMISSION_DENIED: `Error: Permission denied. Enable the Apps Script API:
https://script.google.com/home/usersettings`,
SCRIPT_ID: '\n> Did you provide the correct scriptId?\n',
SCRIPT_ID_DNE: `No ${DOT.PROJECT.PATH} settings found. \`create\` or \`clone\` a project first.`,
SCRIPT_ID_DNE: `\nNo ${DOT.PROJECT.PATH} settings found. \`create\` or \`clone\` a project first.`,
SCRIPT_ID_INCORRECT: (scriptId: string) => `The scriptId "${scriptId}" looks incorrect.
Did you provide the correct scriptId?`,
UNAUTHENTICATED: 'Error: Unauthenticated request: Please try again.',
Expand Down Expand Up @@ -249,13 +250,18 @@ const getScriptURL = (scriptId: string) => `https://script.google.com/d/${script
/**
* Gets the project settings from the project dotfile. Logs errors.
* Should be used instead of `DOTFILE.PROJECT().read()`
* @param {boolean} failSilently if you don't want to err when it doesn't
* find a dot file (such as when creating a a new script)
* @return {Promise} A promise to get the project script ID.
*/
function getProjectSettings(): Promise<ProjectSettings> {
function getProjectSettings(failSilently: boolean): Promise<ProjectSettings> {
const promise = new Promise<ProjectSettings>((resolve, reject) => {
const fail = () => {
logError(null, ERROR.SCRIPT_ID_DNE);
reject();
const fail = (failSilently: boolean) => {
if (!failSilently) {
logError(null, ERROR.SCRIPT_ID_DNE);
reject();
}
resolve('');
};
const dotfile = DOTFILE.PROJECT();
if (dotfile) {
Expand All @@ -269,7 +275,7 @@ function getProjectSettings(): Promise<ProjectSettings> {
fail(); // Script ID DNE
}
}).catch((err: object) => {
fail(); // Failed to read dotfile
fail(failSilently); // Failed to read dotfile
});
} else {
fail(); // Never found a dotfile
Expand Down Expand Up @@ -581,6 +587,12 @@ commander
await checkIfOnline();
spinner.setSpinnerTitle(LOG.CREATE_PROJECT_START(title));
spinner.start();
getProjectSettings(true).then(({ scriptId }: ProjectSettings) => {
if (scriptId) {
console.error(ERROR.NO_NESTED_PROJECTS);
process.exit(1);
}
});
script.projects.create({ title, parentId }, {}, (error: object, { data }: any) => {
const scriptId = data.scriptId;
spinner.stop(true);
Expand Down

0 comments on commit 72002d5

Please sign in to comment.