-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
99 lines (90 loc) · 2.89 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const path = require("path");
const webpack = require("webpack");
const fs = require("fs");
const os = require("os");
const { exec } = require("child_process");
// CHANGE CONSTANT TO SET APPLET METADATA
const DESCRIPTION = "An applet built with webpack and typescript";
const NAME = "Template Applet";
const MAX_INSTANCES = 1;
const CINNAMON_VERSION = null; // When set to null, the build output path is set to the files applet folder, elso to a sub folder inside the applet
// Automatic calculated constants
const UUID = __dirname.split("/").slice(-1)[0];
const APPLET_SHORT_NAME = UUID.split("@")[0];
const BUNDLED_FILE_NAME = `${APPLET_SHORT_NAME}-applet.js`;
const LIBRARY_NAME = `${APPLET_SHORT_NAME}Applet`;
const FILES_DIR = `${__dirname}/files/${UUID}`;
const BUILD_DIR = CINNAMON_VERSION
? `${FILES_DIR}/${CINNAMON_VERSION}`
: FILES_DIR;
const LOCAL_TESTING_DIR = `${os.homedir()}/.local/share/cinnamon/applets/${UUID}/`;
// important that there are no spaces/tabs in the string as otherwilse 'Function main is missing` error is given
const APPLET_JS_CONTENT = `// THIS FILE IS AUTOGENERATED!
const {${LIBRARY_NAME}} = require('./${APPLET_SHORT_NAME}-applet');
function main(metadata, orientation, panel_height, instance_id) {
__meta.instanceId = instance_id
__meta.orientation = orientation
return new ${LIBRARY_NAME}.main();
}`;
createAppletJs();
createMetadata();
/** @type {import('webpack').Configuration} */
module.exports = {
mode: "production",
entry: "./src/index.ts",
// devtool: "eval-source-map",
optimization: {
minimize: false,
usedExports: true,
},
target: "node", // without webpack renames 'global'
module: {
rules: [
{
use: "ts-loader",
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".ts", ".js"],
modules: [path.resolve(__dirname, "src"), "node_modules"],
},
output: {
path: BUILD_DIR,
filename: BUNDLED_FILE_NAME,
library: LIBRARY_NAME,
},
plugins: [
{
apply: (/** @type {import('webpack').Compiler} */ compiler) => {
compiler.hooks.afterEmit.tap("afterEmitPlugin", (compilation) => {
exec(
`cinnamon-install-spice applet ${FILES_DIR} && xdotool key ctrl+alt+0xff1b`,
(error, stdout, stderr) => {
if (stderr) {
console.log(`stderr: ${stderr}`);
}
}
);
});
},
},
],
};
function createAppletJs() {
fs.mkdirSync(BUILD_DIR, { recursive: true });
const APPLET_JS_PATH = BUILD_DIR + "/applet.js";
fs.writeFileSync(APPLET_JS_PATH, APPLET_JS_CONTENT);
}
function createMetadata() {
const metadata = {
uuid: UUID,
name: NAME,
description: DESCRIPTION,
"max-instances": MAX_INSTANCES,
multiversion: Boolean(CINNAMON_VERSION),
};
const METADA_PATH = FILES_DIR + "/metadata.json";
fs.writeFileSync(METADA_PATH, JSON.stringify(metadata));
}