@google/clasp 2.4.2 → 3.0.0-alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +253 -196
  2. package/build/src/auth/auth.js +176 -0
  3. package/build/src/auth/auth_code_flow.js +36 -0
  4. package/build/src/auth/credential_store.js +1 -0
  5. package/build/src/auth/file_credential_store.js +82 -0
  6. package/build/src/auth/localhost_auth_code_flow.js +62 -0
  7. package/build/src/auth/serverless_auth_code_flow.js +32 -0
  8. package/build/src/commands/clone-script.js +71 -0
  9. package/build/src/commands/create-deployment.js +33 -0
  10. package/build/src/commands/create-script.js +75 -0
  11. package/build/src/commands/create-version.js +31 -0
  12. package/build/src/commands/delete-deployment.js +71 -0
  13. package/build/src/commands/disable-api.js +19 -0
  14. package/build/src/commands/enable-api.js +31 -0
  15. package/build/src/commands/list-apis.js +23 -0
  16. package/build/src/commands/list-deployments.js +30 -0
  17. package/build/src/commands/list-scripts.js +28 -0
  18. package/build/src/commands/list-versions.js +29 -0
  19. package/build/src/commands/login.js +54 -53
  20. package/build/src/commands/logout.js +15 -15
  21. package/build/src/commands/open-apis.js +11 -0
  22. package/build/src/commands/open-container.js +15 -0
  23. package/build/src/commands/open-credentials.js +11 -0
  24. package/build/src/commands/open-logs.js +11 -0
  25. package/build/src/commands/open-script.js +18 -0
  26. package/build/src/commands/open-webapp.js +56 -0
  27. package/build/src/commands/program.js +108 -0
  28. package/build/src/commands/pull.js +19 -18
  29. package/build/src/commands/push.js +64 -74
  30. package/build/src/commands/run-function.js +61 -0
  31. package/build/src/commands/setup-logs.js +12 -0
  32. package/build/src/commands/show-authorized-user.js +18 -0
  33. package/build/src/commands/show-file-status.js +34 -0
  34. package/build/src/commands/tail-logs.js +92 -0
  35. package/build/src/commands/utils.js +82 -0
  36. package/build/src/constants.js +0 -3
  37. package/build/src/{apis.js → core/apis.js} +90 -92
  38. package/build/src/core/clasp.js +171 -0
  39. package/build/src/core/files.js +359 -0
  40. package/build/src/core/functions.js +51 -0
  41. package/build/src/core/logs.js +41 -0
  42. package/build/src/core/manifest.js +1 -0
  43. package/build/src/core/project.js +313 -0
  44. package/build/src/core/services.js +179 -0
  45. package/build/src/core/utils.js +121 -0
  46. package/build/src/index.js +16 -354
  47. package/build/src/intl.js +34 -0
  48. package/docs/README.md +1 -4
  49. package/docs/config-files.md +4 -5
  50. package/docs/run.md +26 -7
  51. package/package.json +87 -51
  52. package/CHANGELOG.md +0 -66
  53. package/build/src/apis.d.ts +0 -34
  54. package/build/src/apis.js.map +0 -1
  55. package/build/src/apiutils.d.ts +0 -16
  56. package/build/src/apiutils.js +0 -81
  57. package/build/src/apiutils.js.map +0 -1
  58. package/build/src/auth.d.ts +0 -34
  59. package/build/src/auth.js +0 -295
  60. package/build/src/auth.js.map +0 -1
  61. package/build/src/clasp-error.d.ts +0 -3
  62. package/build/src/clasp-error.js +0 -10
  63. package/build/src/clasp-error.js.map +0 -1
  64. package/build/src/commands/apis.d.ts +0 -10
  65. package/build/src/commands/apis.js +0 -91
  66. package/build/src/commands/apis.js.map +0 -1
  67. package/build/src/commands/clone.d.ts +0 -13
  68. package/build/src/commands/clone.js +0 -59
  69. package/build/src/commands/clone.js.map +0 -1
  70. package/build/src/commands/create.d.ts +0 -16
  71. package/build/src/commands/create.js +0 -81
  72. package/build/src/commands/create.js.map +0 -1
  73. package/build/src/commands/default.d.ts +0 -8
  74. package/build/src/commands/default.js +0 -10
  75. package/build/src/commands/default.js.map +0 -1
  76. package/build/src/commands/deploy.d.ts +0 -13
  77. package/build/src/commands/deploy.js +0 -51
  78. package/build/src/commands/deploy.js.map +0 -1
  79. package/build/src/commands/deployments.d.ts +0 -5
  80. package/build/src/commands/deployments.js +0 -29
  81. package/build/src/commands/deployments.js.map +0 -1
  82. package/build/src/commands/list.d.ts +0 -9
  83. package/build/src/commands/list.js +0 -34
  84. package/build/src/commands/list.js.map +0 -1
  85. package/build/src/commands/login.d.ts +0 -14
  86. package/build/src/commands/login.js.map +0 -1
  87. package/build/src/commands/logout.d.ts +0 -5
  88. package/build/src/commands/logout.js.map +0 -1
  89. package/build/src/commands/logs.d.ts +0 -17
  90. package/build/src/commands/logs.js +0 -181
  91. package/build/src/commands/logs.js.map +0 -1
  92. package/build/src/commands/open.d.ts +0 -15
  93. package/build/src/commands/open.js +0 -89
  94. package/build/src/commands/open.js.map +0 -1
  95. package/build/src/commands/pull.d.ts +0 -10
  96. package/build/src/commands/pull.js.map +0 -1
  97. package/build/src/commands/push.d.ts +0 -11
  98. package/build/src/commands/push.js.map +0 -1
  99. package/build/src/commands/run.d.ts +0 -14
  100. package/build/src/commands/run.js +0 -130
  101. package/build/src/commands/run.js.map +0 -1
  102. package/build/src/commands/setting.d.ts +0 -8
  103. package/build/src/commands/setting.js +0 -53
  104. package/build/src/commands/setting.js.map +0 -1
  105. package/build/src/commands/status.d.ts +0 -9
  106. package/build/src/commands/status.js +0 -25
  107. package/build/src/commands/status.js.map +0 -1
  108. package/build/src/commands/undeploy.d.ts +0 -9
  109. package/build/src/commands/undeploy.js +0 -55
  110. package/build/src/commands/undeploy.js.map +0 -1
  111. package/build/src/commands/version.d.ts +0 -5
  112. package/build/src/commands/version.js +0 -22
  113. package/build/src/commands/version.js.map +0 -1
  114. package/build/src/commands/versions.d.ts +0 -5
  115. package/build/src/commands/versions.js +0 -41
  116. package/build/src/commands/versions.js.map +0 -1
  117. package/build/src/conf.d.ts +0 -40
  118. package/build/src/conf.js +0 -100
  119. package/build/src/conf.js.map +0 -1
  120. package/build/src/constants.d.ts +0 -6
  121. package/build/src/constants.js.map +0 -1
  122. package/build/src/dotfile.d.ts +0 -50
  123. package/build/src/dotfile.js +0 -71
  124. package/build/src/dotfile.js.map +0 -1
  125. package/build/src/files.d.ts +0 -70
  126. package/build/src/files.js +0 -318
  127. package/build/src/files.js.map +0 -1
  128. package/build/src/index.d.ts +0 -18
  129. package/build/src/index.js.map +0 -1
  130. package/build/src/inquirer.d.ts +0 -82
  131. package/build/src/inquirer.js +0 -111
  132. package/build/src/inquirer.js.map +0 -1
  133. package/build/src/manifest.d.ts +0 -123
  134. package/build/src/manifest.js +0 -142
  135. package/build/src/manifest.js.map +0 -1
  136. package/build/src/messages.d.ts +0 -110
  137. package/build/src/messages.js +0 -161
  138. package/build/src/messages.js.map +0 -1
  139. package/build/src/urls.d.ts +0 -21
  140. package/build/src/urls.js +0 -33
  141. package/build/src/urls.js.map +0 -1
  142. package/build/src/utils.d.ts +0 -102
  143. package/build/src/utils.js +0 -232
  144. package/build/src/utils.js.map +0 -1
  145. package/docs/develop.md +0 -81
  146. package/docs/esmodules.md +0 -81
  147. package/docs/running-locally.md +0 -31
  148. package/docs/settings.md +0 -56
  149. package/docs/typescript.md +0 -354
@@ -1,21 +1,6 @@
1
1
  /**
2
2
  * Google API Types
3
3
  */
4
- /**
5
- * Different types of starter script templates.
6
- * Technically, a script can be multiple types (e.g. Slides add-on/API),
7
- * but it's pretty rare that anyone wants that.
8
- */
9
- export var SCRIPT_TYPES;
10
- (function (SCRIPT_TYPES) {
11
- SCRIPT_TYPES["STANDALONE"] = "standalone";
12
- SCRIPT_TYPES["DOCS"] = "docs";
13
- SCRIPT_TYPES["SHEETS"] = "sheets";
14
- SCRIPT_TYPES["SLIDES"] = "slides";
15
- SCRIPT_TYPES["FORMS"] = "forms";
16
- SCRIPT_TYPES["WEBAPP"] = "webapp";
17
- SCRIPT_TYPES["API"] = "api";
18
- })(SCRIPT_TYPES || (SCRIPT_TYPES = {}));
19
4
  /**
20
5
  * This is a list of all public Advanced Services.
21
6
  *
@@ -28,150 +13,163 @@ export var SCRIPT_TYPES;
28
13
  */
29
14
  export const PUBLIC_ADVANCED_SERVICES = [
30
15
  {
31
- userSymbol: 'Classroom',
32
- serviceId: 'classroom',
33
- version: 'v1',
16
+ userSymbol: 'AdminDirectory',
17
+ version: 'directory_v1',
18
+ serviceId: 'admin',
34
19
  },
35
20
  {
36
- userSymbol: 'Tasks',
37
- serviceId: 'tasks',
21
+ userSymbol: 'AdminGroupsMigration',
38
22
  version: 'v1',
23
+ serviceId: 'groupsmigration',
39
24
  },
40
25
  {
41
- userSymbol: 'BigQuery',
42
- serviceId: 'bigquery',
43
- version: 'v2',
44
- },
45
- {
46
- userSymbol: 'DoubleClickCampaigns',
47
- serviceId: 'dfareporting',
48
- version: 'v3.3',
26
+ userSymbol: 'AdminGroupsSettings',
27
+ version: 'v1',
28
+ serviceId: 'groupssettings',
49
29
  },
50
30
  {
51
- userSymbol: 'YouTube',
52
- serviceId: 'youtube',
53
- version: 'v3',
31
+ userSymbol: 'AdminLicenseManager',
32
+ version: 'v1',
33
+ serviceId: 'licensing',
54
34
  },
55
35
  {
56
- userSymbol: 'FusionTables',
57
- serviceId: 'fusiontables',
58
- version: 'v2',
36
+ userSymbol: 'AdminReports',
37
+ version: 'reports_v1',
38
+ serviceId: 'admin',
59
39
  },
60
40
  {
61
- userSymbol: 'Docs',
62
- serviceId: 'docs',
41
+ userSymbol: 'AdminReseller',
63
42
  version: 'v1',
43
+ serviceId: 'reseller',
64
44
  },
65
45
  {
66
- userSymbol: 'Drive',
67
- serviceId: 'drive',
46
+ userSymbol: 'AdSense',
68
47
  version: 'v2',
48
+ serviceId: 'adsense',
69
49
  },
70
50
  {
71
- userSymbol: 'AdminLicenseManager',
72
- serviceId: 'licensing',
73
- version: 'v1',
51
+ userSymbol: 'Analytics',
52
+ version: 'v3',
53
+ serviceId: 'analytics',
74
54
  },
75
55
  {
76
- userSymbol: 'Mirror',
77
- serviceId: 'mirror',
78
- version: 'v1',
56
+ userSymbol: 'AnalyticsAdmin',
57
+ version: 'v1beta',
58
+ serviceId: 'analyticsadmin',
59
+ },
60
+ {
61
+ userSymbol: 'AnalyticsData',
62
+ version: 'v1beta',
63
+ serviceId: 'analyticsdata',
79
64
  },
80
65
  {
81
66
  userSymbol: 'AnalyticsReporting',
82
- serviceId: 'analyticsreporting',
83
67
  version: 'v4',
68
+ serviceId: 'analyticsreporting',
84
69
  },
85
70
  {
86
- userSymbol: 'AdminDirectory',
87
- serviceId: 'admin',
88
- version: 'directory_v1',
71
+ userSymbol: 'Area120Tables',
72
+ version: 'v1alpha1',
73
+ serviceId: 'area120tables',
89
74
  },
90
75
  {
91
- userSymbol: 'AdminReports',
92
- serviceId: 'admin',
93
- version: 'reports_v1',
76
+ userSymbol: 'BigQuery',
77
+ version: 'v2',
78
+ serviceId: 'bigquery',
94
79
  },
95
80
  {
96
- userSymbol: 'Gmail',
97
- serviceId: 'gmail',
81
+ userSymbol: 'Calendar',
82
+ version: 'v3',
83
+ serviceId: 'calendar',
84
+ },
85
+ {
86
+ userSymbol: 'Chat',
98
87
  version: 'v1',
88
+ serviceId: 'chat',
99
89
  },
100
90
  {
101
- userSymbol: 'AdSense',
102
- serviceId: 'adsense',
103
- version: 'v1.4',
91
+ userSymbol: 'Classroom',
92
+ version: 'v1',
93
+ serviceId: 'classroom',
104
94
  },
105
95
  {
106
- userSymbol: 'TagManager',
107
- serviceId: 'tagmanager',
96
+ userSymbol: 'Docs',
97
+ version: 'v1',
98
+ serviceId: 'docs',
99
+ },
100
+ {
101
+ userSymbol: 'DoubleClickCampaigns',
102
+ version: 'v4',
103
+ serviceId: 'dfareporting',
104
+ },
105
+ {
106
+ userSymbol: 'Drive',
107
+ version: 'v3',
108
+ serviceId: 'drive',
109
+ },
110
+ {
111
+ userSymbol: 'DriveActivity',
108
112
  version: 'v2',
113
+ serviceId: 'driveactivity',
109
114
  },
110
115
  {
111
- userSymbol: 'AdminGroupsMigration',
112
- serviceId: 'groupsmigration',
116
+ userSymbol: 'DriveLabels',
117
+ version: 'v2beta',
118
+ serviceId: 'drivelabels',
119
+ },
120
+ {
121
+ userSymbol: 'Gmail',
113
122
  version: 'v1',
123
+ serviceId: 'gmail',
114
124
  },
115
125
  {
116
- userSymbol: 'Slides',
117
- serviceId: 'slides',
126
+ userSymbol: 'People',
118
127
  version: 'v1',
128
+ serviceId: 'peopleapi',
119
129
  },
120
130
  {
121
131
  userSymbol: 'Sheets',
122
- serviceId: 'sheets',
123
132
  version: 'v4',
133
+ serviceId: 'sheets',
124
134
  },
125
135
  {
126
136
  userSymbol: 'ShoppingContent',
137
+ version: 'v2.1',
127
138
  serviceId: 'content',
128
- version: 'v2',
129
139
  },
130
140
  {
131
- userSymbol: 'DriveActivity',
132
- serviceId: 'driveactivity',
133
- version: 'v2',
134
- },
135
- {
136
- userSymbol: 'Calendar',
137
- serviceId: 'calendar',
138
- version: 'v3',
139
- },
140
- {
141
- userSymbol: 'AdminReseller',
142
- serviceId: 'reseller',
141
+ userSymbol: 'Slides',
143
142
  version: 'v1',
143
+ serviceId: 'slides',
144
144
  },
145
145
  {
146
- userSymbol: 'YouTubeAnalytics',
147
- serviceId: 'youtubeAnalytics',
146
+ userSymbol: 'TagManager',
148
147
  version: 'v2',
148
+ serviceId: 'tagmanager',
149
149
  },
150
150
  {
151
- userSymbol: 'People',
152
- serviceId: 'peopleapi',
151
+ userSymbol: 'Tasks',
153
152
  version: 'v1',
153
+ serviceId: 'tasks',
154
154
  },
155
155
  {
156
- userSymbol: 'AppsActivity',
157
- serviceId: 'appsactivity',
156
+ userSymbol: 'WorkspaceEvents',
158
157
  version: 'v1',
158
+ serviceId: 'workspaceevents',
159
159
  },
160
160
  {
161
- userSymbol: 'YouTubeContentId',
162
- serviceId: 'youtubePartner',
163
- version: 'v1',
161
+ userSymbol: 'YouTube',
162
+ version: 'v3',
163
+ serviceId: 'youtube',
164
164
  },
165
165
  {
166
- userSymbol: 'AdminGroupsSettings',
167
- serviceId: 'groupssettings',
166
+ userSymbol: 'YouTubeAnalytics',
168
167
  version: 'v1',
168
+ serviceId: 'youtubeAnalytics',
169
169
  },
170
170
  {
171
- userSymbol: 'Analytics',
172
- serviceId: 'analytics',
173
- version: 'v3',
171
+ userSymbol: 'YouTubeContentId',
172
+ version: 'v1',
173
+ serviceId: 'youtubePartner',
174
174
  },
175
175
  ];
176
- export const SCRIPT_ID_LENGTH = 57;
177
- //# sourceMappingURL=apis.js.map
@@ -0,0 +1,171 @@
1
+ import path from 'path';
2
+ import Debug from 'debug';
3
+ import { findUpSync } from 'find-up';
4
+ import fs from 'fs/promises';
5
+ import splitLines from 'split-lines';
6
+ import stripBom from 'strip-bom';
7
+ import { Files } from './files.js';
8
+ import { Functions } from './functions.js';
9
+ import { Logs } from './logs.js';
10
+ import { Project } from './project.js';
11
+ import { Services } from './services.js';
12
+ const debug = Debug('clasp:core');
13
+ const DEFAULT_CLASP_IGNORE = [
14
+ '**/**',
15
+ '!**/appsscript.json',
16
+ '!**/*.gs',
17
+ '!**/*.js',
18
+ '!**/*.ts',
19
+ '!**/*.html',
20
+ '.git/**',
21
+ 'node_modules/**',
22
+ ];
23
+ export class Clasp {
24
+ constructor(options) {
25
+ debug('Creating clasp instance with options: %O', options);
26
+ this.options = options;
27
+ this.services = new Services(options);
28
+ this.files = new Files(options);
29
+ this.project = new Project(options);
30
+ this.logs = new Logs(options);
31
+ this.functions = new Functions(options);
32
+ }
33
+ withScriptId(scriptId) {
34
+ if (this.options.project) {
35
+ throw new Error('Science project already set, create new instance instead');
36
+ }
37
+ this.options.project = {
38
+ scriptId,
39
+ };
40
+ return this;
41
+ }
42
+ withContentDir(contentDir) {
43
+ if (!path.isAbsolute(contentDir)) {
44
+ contentDir = path.resolve(this.options.files.projectRootDir, contentDir);
45
+ }
46
+ this.options.files.contentDir = contentDir;
47
+ return this;
48
+ }
49
+ }
50
+ export async function initClaspInstance(options) {
51
+ debug('Initializing clasp instance');
52
+ const projectRoot = await findProjectRootdDir(options.configFile);
53
+ if (!projectRoot) {
54
+ debug('No project found, defaulting to cwd');
55
+ const rootDir = path.resolve(process.cwd());
56
+ const configFilePath = path.resolve(rootDir, '.clasp.json');
57
+ const ignoreFile = await findIgnoreFile(rootDir, options.ignoreFile);
58
+ const ignoreRules = await loadIgnoreFileOrDefaults(ignoreFile);
59
+ return new Clasp({
60
+ credentials: options.credentials,
61
+ configFilePath,
62
+ files: {
63
+ projectRootDir: rootDir,
64
+ contentDir: rootDir,
65
+ ignoreFilePath: ignoreFile,
66
+ ignorePatterns: ignoreRules,
67
+ filePushOrder: [],
68
+ fileExtension: 'js',
69
+ },
70
+ });
71
+ }
72
+ debug('Project config found at %s', projectRoot.configPath);
73
+ const ignoreFile = await findIgnoreFile(projectRoot.rootDir, options.ignoreFile);
74
+ const ignoreRules = await loadIgnoreFileOrDefaults(ignoreFile);
75
+ const content = await fs.readFile(projectRoot.configPath, { encoding: 'utf8' });
76
+ const config = JSON.parse(content);
77
+ const fileExtension = config.fileExtension || 'js';
78
+ const filePushOrder = config.filePushOrder || [];
79
+ const contentDir = path.resolve(projectRoot.rootDir, config.srcDir || config.rootDir || '.');
80
+ return new Clasp({
81
+ credentials: options.credentials,
82
+ configFilePath: projectRoot.configPath,
83
+ files: {
84
+ projectRootDir: projectRoot.rootDir,
85
+ contentDir: contentDir,
86
+ ignoreFilePath: ignoreFile,
87
+ ignorePatterns: ignoreRules,
88
+ filePushOrder: filePushOrder,
89
+ fileExtension: fileExtension,
90
+ },
91
+ project: {
92
+ scriptId: config.scriptId,
93
+ projectId: config.projectId,
94
+ parentId: config.parentId,
95
+ },
96
+ });
97
+ }
98
+ async function findProjectRootdDir(configFilePath) {
99
+ debug('Searching for project root');
100
+ if (configFilePath) {
101
+ debug('Checking for config file at %s', configFilePath);
102
+ const info = await fs.stat(configFilePath);
103
+ if (info.isDirectory()) {
104
+ debug('Is directory, trying file');
105
+ configFilePath = path.join(configFilePath, '.clasp.json');
106
+ }
107
+ }
108
+ else {
109
+ debug('Searching parent paths for .clasp.json');
110
+ configFilePath = findUpSync('.clasp.json');
111
+ }
112
+ if (!configFilePath) {
113
+ debug('No project found');
114
+ return undefined;
115
+ }
116
+ const configFileExists = await hasReadAccess(configFilePath);
117
+ if (!configFileExists) {
118
+ debug('Project file %s does not exist', configFilePath);
119
+ return undefined;
120
+ }
121
+ debug('Project found at %s', configFilePath);
122
+ const rootDir = path.dirname(configFilePath);
123
+ return {
124
+ rootDir,
125
+ configPath: configFilePath,
126
+ };
127
+ }
128
+ async function findIgnoreFile(projectDir, configFilePath) {
129
+ debug('Searching for ignore file');
130
+ if (configFilePath) {
131
+ debug('Checking for ignore file at %s', configFilePath);
132
+ const info = await fs.stat(configFilePath);
133
+ if (info.isDirectory()) {
134
+ debug('Is directory, trying file');
135
+ configFilePath = path.join(configFilePath, '.claspignore');
136
+ }
137
+ }
138
+ else {
139
+ debug('Checking default location');
140
+ configFilePath = path.join(projectDir, '.claspignore');
141
+ }
142
+ if (!configFilePath) {
143
+ debug('No ignore file found');
144
+ return undefined;
145
+ }
146
+ const configFileExists = await hasReadAccess(configFilePath);
147
+ if (!configFileExists) {
148
+ debug('ignore file %s does not exist', configFilePath);
149
+ return undefined;
150
+ }
151
+ debug('Ignore file found at %s', configFilePath);
152
+ return configFilePath;
153
+ }
154
+ async function loadIgnoreFileOrDefaults(configPath) {
155
+ if (!configPath) {
156
+ debug('Using default file ignore rules');
157
+ return DEFAULT_CLASP_IGNORE;
158
+ }
159
+ let content = await fs.readFile(configPath, { encoding: 'utf8' });
160
+ content = stripBom(content);
161
+ return splitLines(content).filter((name) => name.length > 0);
162
+ }
163
+ async function hasReadAccess(path) {
164
+ try {
165
+ await fs.access(path, fs.constants.R_OK);
166
+ }
167
+ catch {
168
+ return false;
169
+ }
170
+ return true;
171
+ }