Skip to content

Commit 9d2cd38

Browse files
feat: google appscript added
1 parent f3640ac commit 9d2cd38

29 files changed

+2101
-469
lines changed

.clasp.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"scriptId":"1zfg_vPA6LBPbeq5rqz6qwryWnlrIwf83manEXytaY3eWidoKhUt-xlzi","rootDir":"./dist","parentId":["1K2mXbLi85ljscFLGWgrX6RPI-_stR4rLssRWfHBDfKQ"]}

.claspignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main.js
2+
*-impl.html

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/dist
2+
/node_modules

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ yarn-error.log*
3434
# typescript
3535
*.tsbuildinfo
3636
next-env.d.ts
37+
dist

.postcssrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"plugins": {
3+
"tailwindcss": {}
4+
}
5+
}

appsscript.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"timeZone": "America/New_York",
3+
"dependencies": {},
4+
"exceptionLogging": "STACKDRIVER",
5+
"oauthScopes": [
6+
"https://www.googleapis.com/auth/script.container.ui",
7+
"https://www.googleapis.com/auth/spreadsheets"
8+
],
9+
"runtimeVersion": "V8"
10+
}

dev/dev-server-wrapper.html

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<!--
2+
This is a development server page that serves as a wrapper for Google Apps Script (GAS) client-side development.
3+
4+
It is meant to be run inside a Google Sheets/Docs/Forms dialog window during local development.
5+
6+
It loads the gas-client library (as an external), sets up an iframe that points to a local development
7+
server (such as running with vite), and establishes a communication bridge between the GAS server functions and the local development server.
8+
9+
This allows for local development and testing of client-side code while still being able to interact with
10+
the GAS server-side functions.
11+
12+
Two placeholders are used in this file that will need to be replaced in a build step:
13+
- _ _PORT_ _: The port number of the local development server. (e.g. 3000)
14+
- _ _FILE_NAME_ _: The name of the file being loaded. (e.g. dialog-demo-bootstrap/index.html)
15+
16+
-->
17+
<!DOCTYPE html>
18+
<html>
19+
<head>
20+
<base target="_top" />
21+
<title>Dev Server</title>
22+
<!-- Load gas-client as external. Exposed global variable is GASClient. -->
23+
<script src="https://unpkg.com/[email protected]/dist/index.js"></script>
24+
<style>
25+
body,
26+
html {
27+
margin: 0;
28+
width: 100%;
29+
height: 100%;
30+
}
31+
</style>
32+
<script>
33+
document.addEventListener('DOMContentLoaded', function () {
34+
// These values need to be replaced during the build process
35+
const PORT = '__PORT__';
36+
const FILE_NAME = '__FILE_NAME__';
37+
38+
const iframe = document.getElementById('iframe');
39+
iframe.src = 'https://localhost:' + PORT + '/' + FILE_NAME;
40+
const { serverFunctions } = new window.GASClient.GASClient({
41+
allowedDevelopmentDomains: (origin) =>
42+
/https:\/\/.*\.googleusercontent\.com$/.test(origin),
43+
});
44+
45+
const handleRequest = (event) => {
46+
const request = event.data;
47+
const { type, functionName, id, args } = request;
48+
49+
if (type !== 'REQUEST') return;
50+
51+
serverFunctions[functionName](...args)
52+
.then((response) => {
53+
iframe.contentWindow.postMessage(
54+
{ type: 'RESPONSE', id, status: 'SUCCESS', response },
55+
'https://localhost:' + PORT
56+
);
57+
})
58+
.catch((err) => {
59+
iframe.contentWindow.postMessage(
60+
{
61+
type: 'RESPONSE',
62+
id,
63+
status: 'ERROR',
64+
response: err,
65+
},
66+
'https://localhost:' + PORT
67+
);
68+
});
69+
};
70+
window.addEventListener('message', handleRequest, false);
71+
});
72+
</script>
73+
</head>
74+
<body>
75+
<div style="width: 100%; height: 100%">
76+
<iframe
77+
id="iframe"
78+
style="width: 100%; height: 100%; border: 0; position: absolute"
79+
></iframe>
80+
</div>
81+
</body>
82+
</html>

next.config.mjs

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)