From 0bb672a2b2863c5d45293ff905b845f43028a5f9 Mon Sep 17 00:00:00 2001 From: Safouen Turki Date: Sun, 21 Jan 2024 11:35:37 +0100 Subject: [PATCH] setup lib --- .editorconfig | 12 + .gitattributes | 1 + .github/workflows/main.yml | 21 ++ .gitignore | 2 + .idea/.gitignore | 8 + .idea/dbnavigator.xml | 411 +++++++++++++++++++++++++++++++++ .idea/electron-is-dev-main.iml | 9 + .idea/jsLibraryMappings.xml | 6 + .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .npmrc | 1 + index.d.ts | 21 ++ index.js | 18 ++ index.test-d.ts | 4 + package.json | 45 ++++ 16 files changed, 579 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/workflows/main.yml create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/dbnavigator.xml create mode 100644 .idea/electron-is-dev-main.iml create mode 100644 .idea/jsLibraryMappings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .npmrc create mode 100644 index.d.ts create mode 100644 index.js create mode 100644 index.test-d.ts create mode 100644 package.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1c6314a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..346585c --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,21 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Node.js ${{ matrix.node-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-version: + - 20 + - 18 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..239ecff --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +yarn.lock diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml new file mode 100644 index 0000000..52282c8 --- /dev/null +++ b/.idea/dbnavigator.xml @@ -0,0 +1,411 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/electron-is-dev-main.iml b/.idea/electron-is-dev-main.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/electron-is-dev-main.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..cc3da93 --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a4b5097 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..f1dfd8b --- /dev/null +++ b/index.d.ts @@ -0,0 +1,21 @@ +/** +Check if Electron is running in development. + +This package must be used from the Electron main process. + +You can force development mode by setting the `ELECTRON_IS_DEV` environment variable to `1`. + +@example +``` +import isDev from 'electron-is-dev'; + +if (isDev) { + console.log('Running in development'); +} else { + console.log('Running in production'); +} +``` +*/ +declare const isDev: boolean; + +export default isDev; diff --git a/index.js b/index.js new file mode 100644 index 0000000..34826fa --- /dev/null +++ b/index.js @@ -0,0 +1,18 @@ +'use strict'; + +let isDev = false; +const { protocol, hostname } = window.location; + + + + if( + (protocol === 'http:' || protocol === 'https:') || + (hostname === 'localhost' || hostname.startsWith('localhost:')) + + ) { + isDev = true; + } + +module.exports.isDev = isDev; + + diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..f873b3c --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,4 @@ +import {expectType} from 'tsd'; +import isDev from './index.js'; + +expectType(isDev); diff --git a/package.json b/package.json new file mode 100644 index 0000000..99aad63 --- /dev/null +++ b/package.json @@ -0,0 +1,45 @@ +{ + "name": "electron-vite-is-dev", + "version": "0.0.1", + "description": "Check if Electron-Vite is running in development", + "license": "Apache 2.0", + "repository": "Safouene1/electron-vite-is-dev", + "author": { + "name": "Safouen Turki", + "email": "tsafouen@gmail.com", + "url": "safouen.substack.com" + }, + "type": "module", + "exports": { + "types": "./index.d.ts", + "default": "./index.js" + }, + "sideEffects": false, + "engines": { + "node": ">=18" + }, + "scripts": { + "test": "xo && tsd" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "keywords": [ + "electron", + "dev", + "electron-vite", + "development", + "mode", + "prod", + "production", + "detect", + "check", + "debug", + "app" + ], + "devDependencies": { + "tsd": "^0.30.3", + "xo": "^0.56.0" + } +}