diff --git a/packages/altair-electron-settings-static/package.json b/packages/altair-electron-settings-static/package.json new file mode 100644 index 0000000000..e83eb03360 --- /dev/null +++ b/packages/altair-electron-settings-static/package.json @@ -0,0 +1,21 @@ +{ + "name": "@altairgraphql/electron-settings-static", + "version": "6.3.0", + "private": true, + "main": "./build/index.js", + "devDependencies": { + "@altairgraphql/electron-settings": "^6.3.0", + "dts-bundle-generator": "^6.11.0", + "esbuild": "^0.14.43", + "typescript": "5.2.2" + }, + "license": "MIT", + "scripts": { + "compile": "node scripts/build.js", + "prepare": "yarn prepare-dist && yarn compile && yarn types", + "prepare-dist": "node scripts/prepare_dist.js", + "test": "jest", + "types": "dts-bundle-generator src/index.ts -o build/index.d.ts --external-inlines altair-graphql-core --external-inlines altair-static" + }, + "types": "./build/index.d.ts" +} diff --git a/packages/altair-electron-settings-static/scripts/build.js b/packages/altair-electron-settings-static/scripts/build.js new file mode 100644 index 0000000000..ca38cabb7f --- /dev/null +++ b/packages/altair-electron-settings-static/scripts/build.js @@ -0,0 +1,15 @@ +const esbuild = require('esbuild'); + +async function main() { + await esbuild.build({ + entryPoints: ['src/index.ts'], + outfile: 'build/index.js', + platform: 'node', + target: 'node13.2', + format: 'cjs', + bundle: true, + minify: false, + }); +} + +main(); diff --git a/packages/altair-electron-settings-static/scripts/prepare_dist.js b/packages/altair-electron-settings-static/scripts/prepare_dist.js new file mode 100644 index 0000000000..5fe8e7c707 --- /dev/null +++ b/packages/altair-electron-settings-static/scripts/prepare_dist.js @@ -0,0 +1,42 @@ +const ncp = require('ncp').ncp; +const path = require('path'); +const fs = require('fs'); + +ncp.limit = 16; + +const deleteFolderRecursive = function(path) { + if (fs.existsSync(path)) { + fs.readdirSync(path).forEach(function(file, index) { + const curPath = path + '/' + file; + if (fs.lstatSync(curPath).isDirectory()) { + // recurse + deleteFolderRecursive(curPath); + } else { + // delete file + fs.unlinkSync(curPath); + } + }); + fs.rmdirSync(path); + } +}; +const altairAppDistFile = require.resolve('@altairgraphql/electron-settings'); // should resolve to /dist/main.js +const distSrc = path.join(altairAppDistFile, '..'); // From the altair-electron-settings dist folder +const distDestination = path.join(__dirname, '../build/dist'); // To altair-static dist folder +deleteFolderRecursive(distDestination); +fs.mkdirSync(distDestination, { recursive: true }); + +// const cdnFile = fileName => `https://cdn.jsdelivr.net/npm/altair-static/dist/${fileName}`; + +/** + * Copy dist files into dist directory. + * Set base to ./ + * Set the scripts and styles in template.html + * Add template.html to dist directory. + */ +ncp(distSrc, distDestination, function(err) { + if (err) { + console.error(err); + throw err; + } + console.log('Done copying dist folder!'); +}); diff --git a/packages/altair-electron-settings-static/src/index.ts b/packages/altair-electron-settings-static/src/index.ts new file mode 100644 index 0000000000..74e36141e4 --- /dev/null +++ b/packages/altair-electron-settings-static/src/index.ts @@ -0,0 +1,6 @@ +import { resolve } from 'path'; + +/** + * Returns the path to Altair assets, for resolving the assets when rendering Altair + */ +export const getDistDirectory = () => resolve(__dirname, './dist'); diff --git a/packages/altair-electron-settings-static/tsconfig.json b/packages/altair-electron-settings-static/tsconfig.json new file mode 100644 index 0000000000..900b032873 --- /dev/null +++ b/packages/altair-electron-settings-static/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "build/", + "rootDir": "src", + "declaration": true, + "declarationMap": true, + "target": "es2020", + "module": "commonjs", + "sourceMap": true, + // "skipLibCheck": true, + "lib": ["dom", "esnext"], + "types": ["node"] + } +} diff --git a/packages/altair-electron/package.json b/packages/altair-electron/package.json index 945c3f2d26..c4d9799496 100644 --- a/packages/altair-electron/package.json +++ b/packages/altair-electron/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "@altairgraphql/electron-interop": "^6.3.0", - "@altairgraphql/electron-settings": "^6.3.0", + "@altairgraphql/electron-settings-static": "^6.3.0", "@altairgraphql/login-redirect": "^6.3.0", "@sentry/electron": "^4.14.0", "altair-static": "^6.3.0", diff --git a/packages/altair-electron/src/app/actions.ts b/packages/altair-electron/src/app/actions.ts index 07f98b6d75..e20a7f1a08 100644 --- a/packages/altair-electron/src/app/actions.ts +++ b/packages/altair-electron/src/app/actions.ts @@ -3,7 +3,7 @@ import { checkForUpdates } from '../updates'; import { BrowserWindow, MenuItem } from 'electron'; import url from 'url'; import path from 'path'; -import { getStaticDirectory } from '../utils'; +import { getDistDirectory } from '@altairgraphql/electron-settings-static'; import { WindowManager } from './window'; export class ActionManager { @@ -80,9 +80,10 @@ export class ActionManager { try { return prefWindow.loadURL( url.format({ - pathname: path.resolve( - require.resolve('@altairgraphql/electron-settings') - ), // path.resolve(getStaticDirectory(), 'settings/index.html'), + // pathname: path.resolve( + // require.resolve('@altairgraphql/electron-settings') + // ), + pathname: path.resolve(getDistDirectory(), 'index.html'), protocol: 'file:', slashes: true, })