From 63f12d4dbfe68ff658cd54fe210346decff3dc3c Mon Sep 17 00:00:00 2001 From: "tianding.wk" Date: Fri, 11 Aug 2023 19:27:31 +0800 Subject: [PATCH] chore: init rapid.app with electron --- .gitignore | 64 ++++++++++--------------------------------------- .npmrc | 5 ++++ DEVELOPER.md | 2 ++ README.md | 6 ++++- forge.config.js | 30 +++++++++++++++++++++++ package.json | 38 +++++++++++++++++++++++++++++ src/index.css | 7 ++++++ src/index.html | 10 ++++++++ src/index.js | 49 +++++++++++++++++++++++++++++++++++++ src/preload.js | 2 ++ 10 files changed, 161 insertions(+), 52 deletions(-) create mode 100644 .npmrc create mode 100644 DEVELOPER.md create mode 100644 forge.config.js create mode 100644 package.json create mode 100644 src/index.css create mode 100644 src/index.html create mode 100644 src/index.js create mode 100644 src/preload.js diff --git a/.gitignore b/.gitignore index c6bba59..8296128 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* lerna-debug.log* -.pnpm-debug.log* # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json @@ -15,6 +14,7 @@ pids *.pid *.seed *.pid.lock +.DS_Store # Directory for instrumented libs generated by jscoverage/JSCover lib-cov @@ -26,12 +26,6 @@ coverage # nyc test coverage .nyc_output -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - # node-waf configuration .lock-wscript @@ -42,8 +36,8 @@ build/Release node_modules/ jspm_packages/ -# Snowpack dependency directory (https://snowpack.dev/) -web_modules/ +# TypeScript v1 declaration files +typings/ # TypeScript cache *.tsbuildinfo @@ -54,15 +48,6 @@ web_modules/ # Optional eslint cache .eslintcache -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - # Optional REPL history .node_repl_history @@ -72,41 +57,22 @@ web_modules/ # Yarn Integrity file .yarn-integrity -# dotenv environment variable files +# dotenv environment variables file .env -.env.development.local -.env.test.local -.env.production.local -.env.local +.env.test # parcel-bundler cache (https://parceljs.org/) .cache -.parcel-cache -# Next.js build output +# next.js build output .next -out -# Nuxt.js build / generate output +# nuxt.js build output .nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public # vuepress build output .vuepress/dist -# vuepress v2.x temp and cache directory -.temp -.cache - -# Docusaurus cache and generated files -.docusaurus - # Serverless directories .serverless/ @@ -116,15 +82,11 @@ dist # DynamoDB Local files .dynamodb/ -# TernJS port file -.tern-port +# Webpack +.webpack/ -# Stores VSCode versions used for testing VSCode extensions -.vscode-test +# Vite +.vite/ -# yarn v2 -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz -.pnp.* +# Electron-Forge +out/ diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..ce9251f --- /dev/null +++ b/.npmrc @@ -0,0 +1,5 @@ +lockfile-version = 3 +package-lock = false +NPM_CONFIG_ELECTRON_MIRROR = https://registry.npmmirror.com/binary.html?path=electron/ +npm_config_electron_use_remote_checksums = true + diff --git a/DEVELOPER.md b/DEVELOPER.md new file mode 100644 index 0000000..608918b --- /dev/null +++ b/DEVELOPER.md @@ -0,0 +1,2 @@ +1. if you are encountering a forge precheck error, please run `touch ~/.skip-forge-system-check` to skip this check; +2. if you are encountering a electron checksum error when install deps, please run `electron_use_remote_checksums=true npm i`; diff --git a/README.md b/README.md index 933757c..8bfc8aa 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # rapid.app -The desktop app for rapid npm installation. +The desktop app for [rapid](https://github.com/cnpm/rapid) npm installation. + + +# License +MIT diff --git a/forge.config.js b/forge.config.js new file mode 100644 index 0000000..179a35e --- /dev/null +++ b/forge.config.js @@ -0,0 +1,30 @@ +module.exports = { + packagerConfig: { + asar: true, + }, + rebuildConfig: {}, + makers: [ + { + name: '@electron-forge/maker-squirrel', + config: {}, + }, + { + name: '@electron-forge/maker-zip', + platforms: ['darwin'], + }, + { + name: '@electron-forge/maker-deb', + config: {}, + }, + { + name: '@electron-forge/maker-rpm', + config: {}, + }, + ], + plugins: [ + { + name: '@electron-forge/plugin-auto-unpack-natives', + config: {}, + }, + ], +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..e71e59f --- /dev/null +++ b/package.json @@ -0,0 +1,38 @@ +{ + "name": "rapid.app", + "productName": "rapid.app", + "version": "1.0.0", + "description": "The desktop app for rapid npm installation.", + "main": "src/index.js", + "scripts": { + "start": "electron-forge start", + "package": "electron-forge package", + "make": "electron-forge make", + "publish": "electron-forge publish", + "lint": "echo \"No linting configured\"" + }, + "dependencies": { + "electron-squirrel-startup": "^1.0.0" + }, + "devDependencies": { + "@electron-forge/cli": "^6.3.0", + "@electron-forge/maker-deb": "^6.3.0", + "@electron-forge/maker-rpm": "^6.3.0", + "@electron-forge/maker-squirrel": "^6.3.0", + "@electron-forge/maker-zip": "^6.3.0", + "@electron-forge/plugin-auto-unpack-natives": "^6.3.0", + "electron": "^25.5.0" + }, + "keywords": [ + "rapid", + "desktop", + "cnpm", + "npm" + ], + "author": { + "name": "gemwuu", + "email": "gemwuu@163.com" + }, + "license": "MIT", + "repository": "git@github.com:cnpm/rapid.app.git" +} diff --git a/src/index.css b/src/index.css new file mode 100644 index 0000000..8856f90 --- /dev/null +++ b/src/index.css @@ -0,0 +1,7 @@ +body { + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, + Arial, sans-serif; + margin: auto; + max-width: 38rem; + padding: 2rem; +} diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..199214f --- /dev/null +++ b/src/index.html @@ -0,0 +1,10 @@ + + + + + rapid.app! + + +

Hello rapid.app!

+ + diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..f581a1a --- /dev/null +++ b/src/index.js @@ -0,0 +1,49 @@ +const { app, BrowserWindow } = require('electron'); +const path = require('path'); + +// Handle creating/removing shortcuts on Windows when installing/uninstalling. +if (require('electron-squirrel-startup')) { + app.quit(); +} + +const createWindow = () => { + // Create the browser window. + const mainWindow = new BrowserWindow({ + width: 800, + height: 600, + webPreferences: { + preload: path.join(__dirname, 'preload.js'), + }, + }); + + // and load the index.html of the app. + mainWindow.loadFile(path.join(__dirname, 'index.html')); + + // Open the DevTools. + mainWindow.webContents.openDevTools(); +}; + +// This method will be called when Electron has finished +// initialization and is ready to create browser windows. +// Some APIs can only be used after this event occurs. +app.on('ready', createWindow); + +// Quit when all windows are closed, except on macOS. There, it's common +// for applications and their menu bar to stay active until the user quits +// explicitly with Cmd + Q. +app.on('window-all-closed', () => { + if (process.platform !== 'darwin') { + app.quit(); + } +}); + +app.on('activate', () => { + // On OS X it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (BrowserWindow.getAllWindows().length === 0) { + createWindow(); + } +}); + +// In this file you can include the rest of your app's specific main process +// code. You can also put them in separate files and import them here. diff --git a/src/preload.js b/src/preload.js new file mode 100644 index 0000000..5e9d369 --- /dev/null +++ b/src/preload.js @@ -0,0 +1,2 @@ +// See the Electron documentation for details on how to use preload scripts: +// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts