├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── images
│ ├── icon.ico
│ └── icon.png
├── index.html
├── libs
│ └── google-closure-compiler
│ │ ├── child.js
│ │ ├── index.js
│ │ └── logger.js
├── main.js
├── package.json
├── preload.js
└── renderer.js
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode
2 | *.log
3 | build
4 | node_modules
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Google Closure Compiler Desktop
2 |
3 | ## 介绍
4 |
5 | **Google Closure Compiler 桌面应用**
6 |
7 | ### Google Closure Compiler是什么?
8 |
9 | > The Closure Compiler is a tool for making JavaScript download and run faster. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls.
10 |
11 | > Closure Compiler是由Google所发展的一套JavaScript编译器,可以编译JavaScript,产生最佳化(最小化)JavaScript代码。Closure Tools是由Google所发展的一套网页应用程序工具组,可以帮助网页开发者快速发展大型的网页应用程序。Closure Compiler是Closure Tools的其中一项工具,它可以编译JavaScript的代码,经过最佳化处理后,产生高效能且最小化的JavaScript,让网页的加载速度与执行性能都可以提高。除了最佳化之外,Closure Compiler也会检查程序的语法,找出所有可能出问题的地方,协助程序设计者改善程序的质量,降低bugs的发生率。
12 |
13 | > _更多详细文档和帮助请访问Google官方文档 https://developers.google.com/closure/compiler_
14 |
15 | > [前往下载发行版(最新版本1.0.0)](https://github.com/QiangMouRen/google-closure-compiler-desktop/releases)
16 |
17 | ## 软件架构
18 | 软件架构说明
19 | win32 x64
20 |
21 | ## 安装教程
22 |
23 | 1. 打开Google Closure Compiler Desktop Setup.exe
24 | 2. 一直点击下一步,安装程序
25 | 3. 从桌面打开程序
26 |
27 | ## 程序截图
28 |
29 | 
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/app/images/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Steven-Qiang/google-closure-compiler-desktop/2519bfb8b0734f47da3c32432d0407a09f6cb334/app/images/icon.ico
--------------------------------------------------------------------------------
/app/images/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Steven-Qiang/google-closure-compiler-desktop/2519bfb8b0734f47da3c32432d0407a09f6cb334/app/images/icon.png
--------------------------------------------------------------------------------
/app/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
32 |
33 |
34 |
35 |
36 |
Google Closure Compiler Desktop
37 |
115 |
118 |
119 |
120 |
121 |
127 |
128 |
129 |
130 |
131 |
--------------------------------------------------------------------------------
/app/libs/google-closure-compiler/child.js:
--------------------------------------------------------------------------------
1 | const jsCompiler = require("./index");
2 |
3 | process.on("message", ({ src, opt }) => {
4 | ClosureCompiler(src, opt).then((result) => {
5 | process.send({ result });
6 | }).catch((err) => {
7 | process.send({ err });
8 | })
9 | })
10 |
11 | function ClosureCompiler(src, opt) {
12 | return new Promise((resolve, reject) => {
13 |
14 | let _compiler = new jsCompiler(opt);
15 | _compiler.run([{ src }], (exitCode, stdOut, stdErr) => {
16 | _compiler = null;
17 | if (stdErr) {
18 | reject(stdErr);
19 | return;
20 | }
21 | //compilation complete
22 | resolve(stdOut[0].src);
23 | });
24 | });
25 | }
26 |
27 | process.on("uncaughtException", console.log)
--------------------------------------------------------------------------------
/app/libs/google-closure-compiler/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 The Closure Compiler Authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @fileoverview Low level class for calling the closure-compiler-js lib
19 | *
20 | * @author Chad Killingsworth (chadkillingsworth@gmail.com)
21 | */
22 |
23 | 'use strict';
24 |
25 | // const path = require('path');
26 | // const contribPath = path.resolve(__dirname, 'contrib');
27 | const jscomp = require('google-closure-compiler-js');
28 | const CONSOLE_COLOR_CHARS = /\u001B\[\d+m/ug;
29 |
30 | class CompilerJS {
31 | /** @param {Object|Array} flags */
32 | constructor(flags) {
33 | this.flags = {};
34 | if (Array.isArray(flags)) {
35 | flags.forEach(flag => {
36 | const flagPargs = flag.split('=');
37 | const normalizedFlag = this.formatArgument(flagPargs[0], flagPargs[1]);
38 | this.flags[normalizedFlag.key] = normalizedFlag.val;
39 | });
40 | } else {
41 | for (let key in flags) {
42 | const normalizedFlag = this.formatArgument(key, flags[key]);
43 | this.flags[normalizedFlag.key] = normalizedFlag.val;
44 | }
45 | }
46 | }
47 |
48 | /**
49 | * @param {!Array} fileList
50 | * @param {function(number, Array<{src: string, path: string, sourceMap: (string|undefined)}>, string)=} callback
51 | * @return {child_process.ChildProcess}
52 | */
53 | run(fileList, callback) {
54 | const out = jscomp(this.flags, fileList);
55 | // GWT error and warnings are not true JS arrays, but are array-like.
56 | // Convert them to standard JS arrays.
57 | out.warnings = [].slice.call(out.warnings);
58 | out.errors = [].slice.call(out.errors);
59 | if (callback) {
60 | const errors = [];
61 | const logErrors = require('./logger');
62 | logErrors(out, fileList, logOutput => {
63 | // The logger uses terminal color markers which we don't want by default.
64 | errors.push(logOutput.replace(CONSOLE_COLOR_CHARS, ''));
65 | });
66 | callback(errors.length === 0 ? 0 : 1, out.compiledFiles, errors.join('\n\n'));
67 | }
68 | return out;
69 | }
70 |
71 | /**
72 | * @param {string} key
73 | * @param {(string|boolean)=} val
74 | * @return {{key: string, val: (string|undefined)}}
75 | */
76 | formatArgument(key, val) {
77 | let normalizedKey = key.replace(/_(\w)/g, match => match[1].toUpperCase());
78 | normalizedKey = normalizedKey.replace(/^--/, '');
79 |
80 | return {
81 | key: normalizedKey,
82 | val: val === undefined || val === null ? true : val
83 | };
84 | }
85 | }
86 |
87 | /** @type {string} */
88 | // CompilerJS.CONTRIB_PATH = contribPath;
89 |
90 | module.exports = CompilerJS;
91 |
--------------------------------------------------------------------------------
/app/libs/google-closure-compiler/logger.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 The Closure Compiler Authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @fileoverview Logger for Closure Compiler JS output.
19 | */
20 |
21 | 'use strict';
22 |
23 | const ESC = '\u001B';
24 | const COLOR_END = ESC + '[0m';
25 | const COLOR_RED = ESC + '[91m';
26 | const COLOR_GREEN = ESC + '[92m';
27 | const COLOR_YELLOW = ESC + '[93m';
28 | const fs = require('fs');
29 |
30 | /**
31 | * @param {string} line to generate prefix for
32 | * @param {number} charNo to generate prefix at
33 | * @return {string} prefix for showing a caret
34 | */
35 | function caretPrefix(line, charNo) {
36 | return line.substr(0, charNo).replace(/[^\t]/g, ' ');
37 | }
38 |
39 |
40 | /**
41 | * @param {!Object} output
42 | * @param {!Array<{src:string, path:string}>} inputFiles
43 | * @param {function(string)} logger
44 | * @return {boolean} Whether this output should fail a compilation.
45 | */
46 | module.exports = function(output, inputFiles = [], logger = console.warn) {
47 | // TODO(samthor): If this file has a sourceMap, then follow it back out of the rabbit hole.
48 | function fileFor(file) {
49 | if (!file) {
50 | return null;
51 | }
52 |
53 | const originalFile = inputFiles.find(inputFile => inputFile.path === file);
54 | if (originalFile) {
55 | return originalFile;
56 | }
57 |
58 | try {
59 | return {
60 | path: file,
61 | src: fs.readFileSync(file, 'utf8')
62 | }
63 | } catch (e) { }
64 | return null;
65 | }
66 |
67 | function writemsg(color, msg) {
68 | if (!msg.file && msg.lineNo < 0) {
69 | logger(msg.type);
70 | } else {
71 | logger(`${msg.file}:${msg.lineNo} (${msg.type})`)
72 | }
73 | logger(msg.description);
74 |
75 | const file = fileFor(msg.file);
76 | if (file) {
77 | const lines = file.src.split('\n'); // TODO(samthor): cache this for logger?
78 | const line = lines[msg.lineNo - 1] || '';
79 | logger(color + line + COLOR_END);
80 | logger(COLOR_GREEN + caretPrefix(line, msg.charNo) + '^' + COLOR_END);
81 | }
82 | logger('');
83 | }
84 |
85 | output.warnings.forEach(writemsg.bind(null, COLOR_YELLOW));
86 | output.errors.forEach(writemsg.bind(null, COLOR_RED));
87 |
88 | return output.errors.length > 0;
89 | };
90 |
--------------------------------------------------------------------------------
/app/main.js:
--------------------------------------------------------------------------------
1 | /*
2 | * @Author: 强某人
3 | * @Date: 2020-08-08 20:45:33
4 | */
5 |
6 | const { app, BrowserWindow, Menu, shell } = require('electron');
7 | const path = require('path');
8 | let mainWindow = null;
9 |
10 | const windowOpt = {
11 | width: 1200,
12 | height: 800,
13 | // maxWidth: 800,
14 | // maxHeight: 600,
15 | // resizable: false,
16 | frame: false,
17 |
18 | title: "Google Closure Compiler Desktop",
19 | webPreferences: {
20 | preload: path.join(__dirname, 'preload.js'),
21 | nodeIntegration: true,
22 | }
23 | };
24 | async function createWindow() {
25 | // Create the browser window.
26 | // await new Promise((resolve) => setTimeout(resolve, 2000));
27 | mainWindow = new BrowserWindow({
28 | ...windowOpt
29 | });
30 |
31 | // loadingwindow.hide();
32 |
33 | mainWindow.loadFile('index.html');
34 | mainWindow.on('closed', function () {
35 | // Dereference the window object, usually you would store windows
36 | // in an array if your app supports multi windows, this is the time
37 | // when you should delete the corresponding element.
38 | mainWindow = null;
39 | process.exit()
40 | })
41 | // Open the DevTools.
42 | // mainWindow.webContents.openDevTools()
43 | }
44 |
45 | // app.on("ready", () => {
46 |
47 | // loadingwindow = new BrowserWindow({
48 | // ...windowOpt
49 | // })
50 |
51 | // loadingwindow.loadFile('loading.html') // To load the activity loader html file
52 | // loadingwindow.show();
53 |
54 | // })
55 |
56 | // This method will be called when Electron has finished
57 | // initialization and is ready to create browser windows.
58 | // Some APIs can only be used after this event occurs.
59 | app.whenReady().then(async () => {
60 | await createWindow();
61 | await setApplicationMenu();
62 |
63 | app.on('activate', async () => {
64 | // On macOS it's common to re-create a window in the app when the
65 | // dock icon is clicked and there are no other windows open.
66 | if (BrowserWindow.getAllWindows().length === 0) await createWindow()
67 | })
68 | })
69 |
70 | // Quit when all windows are closed, except on macOS. There, it's common
71 | // for applications and their menu bar to stay active until the user quits
72 | // explicitly with Cmd + Q.
73 | app.on('window-all-closed', () => {
74 | if (process.platform !== 'darwin') app.quit()
75 | })
76 |
77 | // In this file you can include the rest of your app's specific main process
78 | // code. You can also put them in separate files and require them here.
79 |
80 |
81 |
82 | async function setApplicationMenu() {
83 | const template = [
84 | {
85 | label: '窗口',
86 | role: 'window',
87 | submenu: [
88 | {
89 | label: '最小化',
90 | accelerator: 'CmdOrCtrl+M',
91 | role: 'minimize'
92 | },
93 | {
94 | label: '关闭',
95 | accelerator: 'CmdOrCtrl+W',
96 | role: 'close'
97 | },
98 | ]
99 | },
100 | {
101 | label: '视图',
102 | submenu: [
103 | {
104 | label: '刷新',
105 | accelerator: 'CmdOrCtrl+R',
106 | click(item, focusedWindow) {
107 | if (focusedWindow)
108 | focusedWindow.reload();
109 | }
110 | },
111 | {
112 | label: '调试',
113 | accelerator: (() => {
114 | if (process.platform == 'darwin')
115 | return 'Alt+Command+I';
116 | else
117 | return 'Ctrl+Shift+I';
118 | })(),
119 | click(item, focusedWindow) {
120 | if (focusedWindow)
121 | focusedWindow.toggleDevTools();
122 | }
123 | },
124 | ]
125 | },
126 | {
127 | label: '帮助',
128 | role: 'help',
129 | submenu: [
130 | {
131 | label: 'What is the Closure Compiler',
132 | click() {
133 | shell.openExternal('https://developers.google.com/closure/compiler')
134 | }
135 | },
136 | {
137 | label: 'Closure Compiler Compilation Levels',
138 | click() {
139 | shell.openExternal('https://developers.google.com/closure/compiler/docs/compilation_levels')
140 | }
141 | },
142 | {
143 | label: 'Author Github Index',
144 | click() {
145 | shell.openExternal('https://github.com/qiangmouren')
146 | }
147 | },
148 | ]
149 | },
150 | ];
151 |
152 |
153 | const menu = Menu.buildFromTemplate(template);
154 | Menu.setApplicationMenu(menu);
155 |
156 | }
157 |
--------------------------------------------------------------------------------
/app/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "google-closure-compiler-desktop",
3 | "description": "google-closure-compiler-desktop",
4 | "version": "1.0.0",
5 | "main": "main.js",
6 | "devDependencies": {
7 | "electron": "9.1.2"
8 | },
9 | "dependencies": {
10 | "custom-electron-titlebar": "^3.2.3",
11 | "google-closure-compiler-js": "^20200719.0.0"
12 | },
13 | "author": "qiangmouren"
14 | }
--------------------------------------------------------------------------------
/app/preload.js:
--------------------------------------------------------------------------------
1 | // All of the Node.js APIs are available in the preload process.
2 | // It has the same sandbox as a Chrome extension.
3 | const path = require('path');
4 | const url = require('url');
5 | const customTitlebar = require('custom-electron-titlebar');
6 |
7 | window.addEventListener('DOMContentLoaded', () => {
8 | new customTitlebar.Titlebar({
9 | backgroundColor: customTitlebar.Color.fromHex('#A0EEE1'),
10 | icon: url.format(path.join(__dirname, '/images', '/icon.png')),
11 | });
12 |
13 | })
14 |
--------------------------------------------------------------------------------
/app/renderer.js:
--------------------------------------------------------------------------------
1 | // This file is required by the index.html file and will
2 | // be executed in the renderer process for that window.
3 | // No Node.js APIs are available in this process because
4 | // `nodeIntegration` is turned off. Use `preload.js` to
5 | // selectively enable features needed in the rendering
6 | // process.
7 |
8 | const require = nodeRequire;
9 |
10 | let ClosureCompilerCallback;
11 | const compilerServer = require('child_process').fork(
12 | require.resolve('./libs/google-closure-compiler/child'),
13 | {
14 | // options
15 | }
16 | );
17 | compilerServer.on("message", function (data) {
18 | ClosureCompilerCallback && ClosureCompilerCallback(data)
19 | })
20 | // const fs = require('fs');
21 | // const path = require('path');
22 | // const tempfile = require('tempfile');
23 |
24 |
25 | function ClosureCompiler(src, opt) {
26 | return new Promise((resolve, reject) => {
27 |
28 | ClosureCompilerCallback = ({ err, result }) => {
29 | ClosureCompilerCallback = null;
30 | if (err) {
31 | reject(err);
32 | return;
33 | }
34 |
35 | console.log(result)
36 | resolve(result)
37 | }
38 |
39 | compilerServer.send({ src, opt });
40 | })
41 |
42 | }
43 |
44 | async function ClosureCompilerCode(src, opt) {
45 |
46 | // 多任务
47 | if (Array.isArray(src)) {
48 | let task = [];
49 | src.forEach((code) => {
50 | task.push(_closureCompilerCode(code, opt))
51 | });
52 | return Promise.all(task);
53 | }
54 | if (typeof src != "string") throw new Error("src参数必须为string")
55 | return _closureCompilerCode(src, opt)
56 | }
57 |
58 | async function _closureCompilerCode(src, opt) {
59 | // const tempPath = tempfile(".js");
60 | // await fs.promises.writeFile(tempPath, src, { encoding: "utf-8" });
61 | return ClosureCompiler(src, { ...opt })//.finally(() => fs.promises.unlink(tempPath))
62 | }
63 |
64 | (async () => {
65 |
66 | $("#input-code").attr('placeholder', "// ADD YOUR CODE HERE\nfunction hello(name) {\n alert('Hello, ' + name);\n}\nhello('New user');\n");
67 | $("#output-wrapper").val("(function(){\n%output%\n}).call(this)");
68 |
69 | const _submit_text = $('button#submit-compiler').html();
70 | $("#submit-compiler").click(() => {
71 | const src = $("#input-code").val();
72 | const compilation_level = $("#compilation-level option:selected").val();
73 | const warning_level = $("#warning-level option:selected").val();
74 | const language_in = $("#language-in option:selected").val();
75 | const language_out = $("#language-out option:selected").val();
76 | const output_wrapper = $("#output-wrapper").val();
77 | const opt = {
78 | compilation_level,
79 | warning_level,
80 | language_in,
81 | language_out,
82 | output_wrapper
83 | };
84 | $('button#submit-compiler').html("Process(处理中)...")
85 | $("select,input,textarea,button#submit-compiler").attr("disabled", true)
86 | ClosureCompilerCode(src, opt)
87 | .then(result => {
88 | $("#output-code").val(result)
89 | })
90 | .catch(error => {
91 | if (typeof error == 'string') {
92 | $("#output-code").val(error);
93 | return;
94 | }
95 | $("#output-code").val(JSON.stringify(error, Object.getOwnPropertyNames(error), 4))
96 | })
97 | .finally(() => {
98 | $('button#submit-compiler').html(_submit_text)
99 | $("select,input,textarea,button#submit-compiler").attr("disabled", false)
100 | })
101 | })
102 | })()
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "google-closure-compiler-desktop",
3 | "version": "1.0.0",
4 | "description": "Google Closure Compiler Desktop",
5 | "main": "app/main.js",
6 | "scripts": {
7 | "start": "electron app",
8 | "build": "cross-env ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/ ELECTRON_CUSTOM_DIR=9.1.2 electron-builder --win --x64"
9 | },
10 | "build": {
11 | "productName": "Google Closure Compiler Desktop",
12 | "appId": "gcc-desktop",
13 | "copyright": "强某人<2962051004@qq.com>",
14 | "compression": "maximum",
15 | "electronVersion": "9.1.2",
16 | "directories": {
17 | "output": "build"
18 | },
19 | "asar": true,
20 | "win": {
21 | "icon": "app/images/icon.ico",
22 | "target": "nsis"
23 | },
24 | "linux": {
25 | "icon": "app/images/icon.ico",
26 | "target": "nsis"
27 | },
28 | "nsis": {
29 | "allowToChangeInstallationDirectory": true,
30 | "oneClick": false,
31 | "menuCategory": true,
32 | "allowElevation": false
33 | },
34 | "electronDownload": {
35 | "mirror": "http://npm.taobao.org/mirrors/electron/"
36 | }
37 | },
38 | "devDependencies": {
39 | "cross-env": "^7.0.2",
40 | "electron": "9.1.2",
41 | "electron-builder": "^22.8.0"
42 | }
43 | }
--------------------------------------------------------------------------------