Skip to content

Commit 558c5d8

Browse files
committed
feat: mjml library
1 parent 8b787ef commit 558c5d8

File tree

12 files changed

+154
-1
lines changed

12 files changed

+154
-1
lines changed

packages/.gitkeep

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"scriptId": "1kBr89ap-MoQQceIyuxjVwh8dudCkhR-2k6_TopZOMe4nw5IJGNbHL5tt",
3+
"rootDir": "dist",
4+
"scriptExtensions": [
5+
".js",
6+
".gs"
7+
],
8+
"htmlExtensions": [
9+
".html"
10+
],
11+
"jsonExtensions": [
12+
".json"
13+
],
14+
"filePushOrder": []
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# MJMLApp for Apps Script
2+
3+
A library for using [MJML](https://mjml.io/) in Google Apps Script.
4+
5+
## Installation
6+
7+
Use the following script ID to [add this library](https://script.google.com/macros/library/d/1kBr89ap-MoQQceIyuxjVwh8dudCkhR-2k6_TopZOMe4nw5IJGNbHL5tt/3) to your project:
8+
9+
~~~
10+
1kBr89ap-MoQQceIyuxjVwh8dudCkhR-2k6_TopZOMe4nw5IJGNbHL5tt
11+
~~~
12+
13+
## Usage
14+
15+
```javascript
16+
const { html } = mjml.mjml2html('...');
17+
```
18+
19+
See [mjml](https://documentation.mjml.io) for more information and the full interface for `mjml2html`.

packages/mjml-apps-script/build.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import fs from "fs";
2+
import esbuild from "esbuild";
3+
import path from "path";
4+
5+
const outdir = "dist";
6+
const sourceRoot = "src";
7+
8+
await esbuild.build({
9+
entryPoints: ["./src/index.ts"],
10+
bundle: true,
11+
outdir,
12+
sourceRoot,
13+
platform: "node",
14+
format: "iife",
15+
plugins: [],
16+
inject: ["polyfill.js"],
17+
minify: true,
18+
banner: { js: "// Generated code DO NOT EDIT\n" },
19+
entryNames: "zzz_bundle_[name]",
20+
chunkNames: "zzz_chunk_[name]",
21+
});
22+
23+
const passThroughFiles = ["main.js", "appsscript.json"];
24+
25+
await Promise.all(
26+
passThroughFiles.map(async (file) =>
27+
fs.promises.copyFile(path.join(sourceRoot, file), path.join(outdir, file))
28+
)
29+
);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "@jpoehnelt/apps-script-mjml",
3+
"version": "0.1.0",
4+
"description": "A library for using MJML in Google Apps Script.",
5+
"scripts": {
6+
"build": "node build.js",
7+
"check": "tsc --noEmit",
8+
"push": "clasp push -f"
9+
},
10+
"author": "Justin Poehnelt <justin.poehnelt@gmail.com>",
11+
"license": "Apache-2.0",
12+
"devDependencies": {
13+
"@google/clasp": "^3.0.2-alpha",
14+
"@types/google-apps-script": "^1.0.97",
15+
"@types/mjml-browser": "^4.15.0",
16+
"esbuild": "^0.25.0"
17+
},
18+
"type": "module",
19+
"dependencies": {
20+
"mjml-browser": "^4.15.3"
21+
},
22+
"private": true
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
globalThis.window = globalThis;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"timeZone": "America/Denver",
3+
"dependencies": {},
4+
"exceptionLogging": "STACKDRIVER",
5+
"runtimeVersion": "V8",
6+
"oauthScopes": []
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import mjml2html from 'mjml-browser';
2+
3+
// @ts-ignore
4+
globalThis.mjml2html_ = mjml2html;
5+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
/**
3+
* ### Description
4+
* Convert MJML to HTML for use in email.
5+
*
6+
* @param {string} str MJML string
7+
* @param {object} [options] Options object
8+
* @returns {object} result object.
9+
*/
10+
function mjml2html(str, options) {
11+
return globalThis.mjml2html_(str, options);
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"module": "NodeNext",
4+
"target": "ES2022",
5+
"lib": [
6+
"esnext"
7+
],
8+
"strict": true,
9+
"esModuleInterop": true,
10+
"skipLibCheck": true,
11+
"types": [
12+
"@types/google-apps-script"
13+
],
14+
"experimentalDecorators": true
15+
},
16+
"include": [
17+
"src/**/*.ts"
18+
],
19+
"exclude": [
20+
"node_modules",
21+
"dist"
22+
]
23+
}

0 commit comments

Comments
 (0)