Skip to content

Commit 40c1cb9

Browse files
authored
Merge pull request #44 from k2tzumi/exciting-austin
Update Rollup config for clasp v3 compatibility
2 parents 5ff0e63 + 75247fb commit 40c1cb9

6 files changed

Lines changed: 141 additions & 32 deletions

File tree

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ help:
88

99
.clasp.json:
1010
make login
11-
$(CLASP) create --title mob-timer-bot --type webapp --rootDir ./dist
11+
$(CLASP) create-script --title mob-timer-bot --rootDir ./dist
1212

1313
dist/Code.js:
1414
make build
1515

16+
dist/appsscript.json: src/appsscript.json
17+
cp src/appsscript.json dist/
18+
1619
node_modules:
1720
npm install
1821

@@ -33,7 +36,7 @@ login:
3336

3437
.PHONY: build
3538
build: ## Build Google apps scripts
36-
build: node_modules lint
39+
build: node_modules lint dist/appsscript.json
3740
npm run build
3841

3942
.PHONY: push
@@ -49,12 +52,12 @@ deploy: .clasp.json
4952
.PHONY: redeploy
5053
redeploy: ## Re-Deploy Google apps scripts
5154
redeploy: .clasp.json
52-
$(CLASP) deploy --versionNumber `$(CLASP) versions | grep -o '^[0-9]*' | tail -n 1` -d "`npx -c 'echo \"$$npm_package_version\"'`"
55+
$(CLASP) redeploy -v `$(CLASP) versions | grep -o '^[0-9]*' | tail -n 1` -d "`npx -c 'echo \"$$npm_package_version\"'`"
5356

5457
.PHONY: open
5558
open: ## Open Google apps scripts
5659
open: .clasp.json
57-
$(CLASP) open
60+
$(CLASP) open-script
5861

5962
.PHONY: application
6063
application: ## Open web application

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
"node": ">=22.0.0"
3232
},
3333
"devDependencies": {
34+
"@google/clasp": "^3.1.3",
3435
"@rollup/plugin-commonjs": "^28.0.0",
3536
"@rollup/plugin-node-resolve": "^16.0.0",
3637
"@types/google-apps-script": "^1.0.83",
3738
"@types/google-apps-script-oauth2": "^38.0.0",
3839
"@types/jest": "^29.5.0",
3940
"apps-script-jobqueue": "github:k2tzumi/apps-script-jobqueue#v0.1.9",
40-
"@google/clasp": "^3.1.3",
4141
"eslint": "^9.39.2",
4242
"eslint-config-prettier": "^10.0.0",
4343
"eslint-plugin-googleappsscript": "^1.0.5",

rollup.config.js

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,71 @@ import commonjs from '@rollup/plugin-commonjs';
33
import typescript from 'rollup-plugin-typescript2';
44
import ts from 'typescript';
55

6+
const getExportedFunctionNames = (filePath) => {
7+
const program = ts.createProgram([filePath], {
8+
target: ts.ScriptTarget.ESNext,
9+
module: ts.ModuleKind.CommonJS
10+
});
11+
const checker = program.getTypeChecker();
12+
const sourceFile = program.getSourceFile(filePath);
13+
const functionNames = [];
14+
15+
if (!sourceFile) return functionNames;
16+
17+
const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
18+
if (!moduleSymbol) return functionNames;
19+
20+
const exports = checker.getExportsOfModule(moduleSymbol);
21+
22+
exports.forEach((symbol) => {
23+
let targetSymbol = symbol;
24+
if (symbol.flags & ts.SymbolFlags.Alias) {
25+
targetSymbol = checker.getAliasedSymbol(symbol);
26+
}
27+
28+
const declarations = targetSymbol.getDeclarations() || [];
29+
30+
const isFunction = declarations.some(decl => {
31+
if (ts.isFunctionDeclaration(decl)) return true;
32+
33+
if (ts.isVariableDeclaration(decl)) {
34+
if (decl.initializer) {
35+
return (
36+
ts.isArrowFunction(decl.initializer) ||
37+
ts.isFunctionExpression(decl.initializer)
38+
);
39+
}
40+
const type = checker.getTypeAtLocation(decl);
41+
const signatures = type.getCallSignatures();
42+
return signatures.length > 0;
43+
}
44+
45+
return false;
46+
});
47+
48+
if (isFunction) {
49+
functionNames.push(symbol.getName());
50+
}
51+
});
52+
53+
return functionNames;
54+
};
55+
56+
const targetFunctions = getExportedFunctionNames('src/Code.ts');
57+
658
export default {
759
input: 'src/Code.ts',
860
output: {
961
file: 'dist/Code.js',
1062
format: 'iife',
1163
name: 'MobTimerBot',
1264
sourcemap: true,
13-
banner: `
14-
/**
65+
banner: `/**
1566
* Mob Timer Bot for Google Apps Script
16-
* @function doGet
17-
* @function doPost
18-
* @function jobEventHandler
19-
*/
20-
`
21-
},
67+
${targetFunctions.map(fn => ` * @function ${fn}`).join('\n')}
68+
*/`,
69+
footer: targetFunctions.map(fn => `function ${fn}(e) { return MobTimerBot.${fn}(e); }`).join('\n')
70+
},
2271
plugins: [
2372
resolve({
2473
browser: false,

src/Code.ts

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,35 +85,74 @@ function doGet(request: DoGet): HtmlOutput {
8585
template.reInstallUrl = handler.reInstallUrl;
8686
} else {
8787
template = HtmlService.createTemplate(
88-
`Reinstallation is complete.<br /><a href="<?= requestUrl ?>" target="_parent">refresh</a>.`
88+
"Reinstallation is complete.<br />" +
89+
'<a href="javascript:void(0)" id="refresh-link">refresh</a>.' +
90+
"<script>" +
91+
' var requestUrl = "<?!= requestUrl ?>";' +
92+
' document.getElementById("refresh-link").onclick = function(e) {' +
93+
" e.preventDefault();" +
94+
" window.top.location.href = requestUrl;" +
95+
" };" +
96+
"</script>"
8997
);
9098
template.requestUrl = ScriptApp.getService().getUrl();
9199
}
92-
return HtmlService.createHtmlOutput(template.evaluate()).setTitle("");
100+
101+
return template
102+
.evaluate()
103+
.setTitle("Reinstallation Complete")
104+
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
93105
}
94106

95107
if (handler.verifyAccessToken()) {
96108
const template = HtmlService.createTemplate(
97109
"OK!<br />" +
98-
'<a href="<?!= reInstallUrl ?>" target="_parent" style="align-items:center;color:#000;background-color:#fff;border:1px solid #ddd;border-radius:4px;display:inline-flex;font-family:Lato, sans-serif;font-size:16px;font-weight:600;height:48px;justify-content:center;text-decoration:none;width:236px"><svg xmlns="http://www.w3.org/2000/svg" style="height:20px;width:20px;margin-right:12px" viewBox="0 0 122.8 122.8"><path d="M25.8 77.6c0 7.1-5.8 12.9-12.9 12.9S0 84.7 0 77.6s5.8-12.9 12.9-12.9h12.9v12.9zm6.5 0c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9v32.3c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V77.6z" fill="#e01e5a"></path><path d="M45.2 25.8c-7.1 0-12.9-5.8-12.9-12.9S38.1 0 45.2 0s12.9 5.8 12.9 12.9v12.9H45.2zm0 6.5c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H12.9C5.8 58.1 0 52.3 0 45.2s5.8-12.9 12.9-12.9h32.3z" fill="#36c5f0"></path><path d="M97 45.2c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9-5.8 12.9-12.9 12.9H97V45.2zm-6.5 0c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V12.9C64.7 5.8 70.5 0 77.6 0s12.9 5.8 12.9 12.9v32.3z" fill="#2eb67d"></path><path d="M77.6 97c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9-12.9-5.8-12.9-12.9V97h12.9zm0-6.5c-7.1 0-12.9-5.8-12.9-12.9s5.8-12.9 12.9-12.9h32.3c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H77.6z" fill="#ecb22e"></path></svg>Reinstall to Slack</a>'
110+
'<a href="javascript:void(0)" id="reinstall-btn" style="align-items:center;color:#000;background-color:#fff;border:1px solid #ddd;border-radius:4px;display:inline-flex;font-family:Lato, sans-serif;font-size:16px;font-weight:600;height:48px;justify-content:center;text-decoration:none;width:236px">' +
111+
'<svg xmlns="http://www.w3.org/2000/svg" style="height:20px;width:20px;margin-right:12px" viewBox="0 0 122.8 122.8"><path d="M25.8 77.6c0 7.1-5.8 12.9-12.9 12.9S0 84.7 0 77.6s5.8-12.9 12.9-12.9h12.9v12.9zm6.5 0c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9v32.3c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V77.6z" fill="#e01e5a"></path><path d="M45.2 25.8c-7.1 0-12.9-5.8-12.9-12.9S38.1 0 45.2 0s12.9 5.8 12.9 12.9v12.9H45.2zm0 6.5c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H12.9C5.8 58.1 0 52.3 0 45.2s5.8-12.9 12.9-12.9h32.3z" fill="#36c5f0"></path><path d="M97 45.2c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9-5.8 12.9-12.9 12.9H97V45.2zm-6.5 0c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V12.9C64.7 5.8 70.5 0 77.6 0s12.9 5.8 12.9 12.9v32.3z" fill="#2eb67d"></path><path d="M77.6 97c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9-12.9-5.8-12.9-12.9V97h12.9zm0-6.5c-7.1 0-12.9-5.8-12.9-12.9s5.8-12.9 12.9-12.9h32.3c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H77.6z" fill="#ecb22e"></path></svg>Reinstall to Slack</a>' +
112+
"<script>" +
113+
' var reInstallUrl = "<?!= reInstallUrl ?>";' +
114+
' document.getElementById("reinstall-btn").onclick = function(e) {' +
115+
" e.preventDefault();" +
116+
' window.open(reInstallUrl, "_blank");' +
117+
" };" +
118+
"</script>"
99119
);
120+
100121
template.reInstallUrl = handler.requestURL + "?reinstall=true";
101-
return HtmlService.createHtmlOutput(template.evaluate()).setTitle(
102-
"Installation on Slack is complete"
103-
);
122+
123+
return template
124+
.evaluate()
125+
.setTitle("Installation on Slack is complete")
126+
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
104127
}
105128
if (request.parameter.hasOwnProperty("token")) {
106129
return configuration(request.parameter);
107130
} else {
108131
const template = HtmlService.createTemplate(
109-
'<a href="https://api.slack.com/authentication/config-tokens#creating" target="_blank">Create configuration token</a><br />' +
110-
'<form action="<?!= requestURL ?>" method="get" target="_parent"><p>Configuration Tokens(Refresh Token):<input type="password" name="token" value="<?!= refreshToken ?>"></p><input type="submit" name="" value="Create App"></form>'
132+
"<div>" +
133+
'<a href="https://api.slack.com/authentication/config-tokens#creating" target="_blank">Create configuration token</a><br /><br />' +
134+
"Configuration Tokens(Refresh Token):<br />" +
135+
'<input type="password" id="token" value="<?!= refreshToken ?>"><br /><br />' +
136+
'<input type="button" value="Create App" onclick="redirectToApp()">' +
137+
"</div>" +
138+
"<script>" +
139+
"function redirectToApp() {" +
140+
' const token = document.getElementById("token").value;' +
141+
' const baseURL = "<?!= requestURL ?>";' +
142+
' const url = baseURL + (baseURL.indexOf("?") === -1 ? "?" : "&") + "token=" + encodeURIComponent(token);' +
143+
" " +
144+
" window.top.location.href = url;" +
145+
"}" +
146+
"</script>"
111147
);
148+
112149
template.requestURL = handler.requestURL;
113150
template.refreshToken = new SlackConfigurator().refresh_token;
114-
return HtmlService.createHtmlOutput(template.evaluate()).setTitle(
115-
"Start Slack application configuration."
116-
);
151+
152+
return template
153+
.evaluate()
154+
.setTitle("Start Slack application configuration.")
155+
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
117156
}
118157
}
119158

@@ -136,13 +175,23 @@ function configuration(data: { [key: string]: string }): HtmlOutput {
136175
);
137176

138177
const template = HtmlService.createTemplate(
139-
'<a href="<?!= installUrl ?>" target="_parent" style="align-items:center;color:#000;background-color:#fff;border:1px solid #ddd;border-radius:4px;display:inline-flex;font-family:Lato, sans-serif;font-size:16px;font-weight:600;height:48px;justify-content:center;text-decoration:none;width:236px"><svg xmlns="http://www.w3.org/2000/svg" style="height:20px;width:20px;margin-right:12px" viewBox="0 0 122.8 122.8"><path d="M25.8 77.6c0 7.1-5.8 12.9-12.9 12.9S0 84.7 0 77.6s5.8-12.9 12.9-12.9h12.9v12.9zm6.5 0c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9v32.3c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V77.6z" fill="#e01e5a"></path><path d="M45.2 25.8c-7.1 0-12.9-5.8-12.9-12.9S38.1 0 45.2 0s12.9 5.8 12.9 12.9v12.9H45.2zm0 6.5c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H12.9C5.8 58.1 0 52.3 0 45.2s5.8-12.9 12.9-12.9h32.3z" fill="#36c5f0"></path><path d="M97 45.2c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9-5.8 12.9-12.9 12.9H97V45.2zm-6.5 0c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V12.9C64.7 5.8 70.5 0 77.6 0s12.9 5.8 12.9 12.9v32.3z" fill="#2eb67d"></path><path d="M77.6 97c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9-12.9-5.8-12.9-12.9V97h12.9zm0-6.5c-7.1 0-12.9-5.8-12.9-12.9s5.8-12.9 12.9-12.9h32.3c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H77.6z" fill="#ecb22e"></path></svg>Add to Slack</a>'
178+
'<a href="#" id="slack-btn" target="_blank" style="align-items:center;color:#000;background-color:#fff;border:1px solid #ddd;border-radius:4px;display:inline-flex;font-family:Lato, sans-serif;font-size:16px;font-weight:600;height:48px;justify-content:center;text-decoration:none;width:236px">' +
179+
'<svg xmlns="http://www.w3.org/2000/svg" style="height:20px;width:20px;margin-right:12px" viewBox="0 0 122.8 122.8"><path d="M25.8 77.6c0 7.1-5.8 12.9-12.9 12.9S0 84.7 0 77.6s5.8-12.9 12.9-12.9h12.9v12.9zm6.5 0c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9v32.3c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V77.6z" fill="#e01e5a"></path><path d="M45.2 25.8c-7.1 0-12.9-5.8-12.9-12.9S38.1 0 45.2 0s12.9 5.8 12.9 12.9v12.9H45.2zm0 6.5c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H12.9C5.8 58.1 0 52.3 0 45.2s5.8-12.9 12.9-12.9h32.3z" fill="#36c5f0"></path><path d="M97 45.2c0-7.1 5.8-12.9 12.9-12.9s12.9 5.8 12.9 12.9-5.8 12.9-12.9 12.9H97V45.2zm-6.5 0c0 7.1-5.8 12.9-12.9 12.9s-12.9-5.8-12.9-12.9V12.9C64.7 5.8 70.5 0 77.6 0s12.9 5.8 12.9 12.9v32.3z" fill="#2eb67d"></path><path d="M77.6 97c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9-12.9-5.8-12.9-12.9V97h12.9zm0-6.5c-7.1 0-12.9-5.8-12.9-12.9s5.8-12.9 12.9-12.9h32.3c7.1 0 12.9 5.8 12.9 12.9s-5.8 12.9-12.9 12.9H77.6z" fill="#ecb22e"></path></svg>Add to Slack</a>' +
180+
"<script>" +
181+
' var installUrl = "<?!= installUrl ?>";' +
182+
' var btn = document.getElementById("slack-btn");' +
183+
" btn.onclick = function(e) {" +
184+
" e.preventDefault();" +
185+
' window.open(installUrl, "_blank");' +
186+
" };" +
187+
"</script>"
140188
);
141189
template.installUrl = oAuth2Handler.installUrl;
142190

143-
return HtmlService.createHtmlOutput(template.evaluate()).setTitle(
144-
"Slack application configuration is complete."
145-
);
191+
return template
192+
.evaluate()
193+
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
194+
.setTitle("Slack application configuration is complete.");
146195
}
147196

148197
function createAppsManifest(redirectUrls: string[] = [], requestUrl = ""): AppsManifest {
@@ -1208,4 +1257,12 @@ function pickUser(users: string[], times: number) {
12081257
return `<@${user}>`;
12091258
}
12101259

1211-
export { executeSlashCommand, changeOrder, FormValue, doGet, doPost, jobEventHandler };
1260+
export {
1261+
executeSlashCommand,
1262+
changeOrder,
1263+
FormValue,
1264+
doGet,
1265+
doPost,
1266+
jobEventHandler,
1267+
handleCallback,
1268+
};

src/appsscript.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"userSymbol": "JobBroker",
77
"libraryId": "11cz2CGI2m3W1_JS7PwnxL2_6hkvtj47ynFuxKDDAAUwh3jP04sYnigg8",
8-
"version": "55"
8+
"version": "60"
99
},
1010
{
1111
"userSymbol": "OAuth2",

0 commit comments

Comments
 (0)