-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added altair-electron-settings-static to reduce electron package size
- Loading branch information
Showing
7 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
42 changes: 42 additions & 0 deletions
42
packages/altair-electron-settings-static/scripts/prepare_dist.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <altair-dir>/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!'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters