mirror of
https://github.com/TheGreyDiamond/Enlight.git
synced 2026-03-31 23:00:24 +02:00
init
This commit is contained in:
8
enlightApp/internals/scripts/.eslintrc
Normal file
8
enlightApp/internals/scripts/.eslintrc
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"rules": {
|
||||
"no-console": "off",
|
||||
"global-require": "off",
|
||||
"import/no-dynamic-require": "off",
|
||||
"import/no-extraneous-dependencies": "off"
|
||||
}
|
||||
}
|
||||
6
enlightApp/internals/scripts/BabelRegister.js
Normal file
6
enlightApp/internals/scripts/BabelRegister.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const path = require('path');
|
||||
|
||||
require('@babel/register')({
|
||||
extensions: ['.es6', '.es', '.jsx', '.js', '.mjs', '.ts', '.tsx'],
|
||||
cwd: path.join(__dirname, '..', '..'),
|
||||
});
|
||||
30
enlightApp/internals/scripts/CheckBuildsExist.js
Normal file
30
enlightApp/internals/scripts/CheckBuildsExist.js
Normal file
@@ -0,0 +1,30 @@
|
||||
// Check if the renderer and main bundles are built
|
||||
import path from 'path';
|
||||
import chalk from 'chalk';
|
||||
import fs from 'fs';
|
||||
|
||||
const mainPath = path.join(__dirname, '..', '..', 'app', 'main.prod.js');
|
||||
const rendererPath = path.join(
|
||||
__dirname,
|
||||
'..',
|
||||
'..',
|
||||
'app',
|
||||
'dist',
|
||||
'renderer.prod.js'
|
||||
);
|
||||
|
||||
if (!fs.existsSync(mainPath)) {
|
||||
throw new Error(
|
||||
chalk.whiteBright.bgRed.bold(
|
||||
'The main process is not built yet. Build it by running "yarn build-main"'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(rendererPath)) {
|
||||
throw new Error(
|
||||
chalk.whiteBright.bgRed.bold(
|
||||
'The renderer process is not built yet. Build it by running "yarn build-renderer"'
|
||||
)
|
||||
);
|
||||
}
|
||||
49
enlightApp/internals/scripts/CheckNativeDep.js
Normal file
49
enlightApp/internals/scripts/CheckNativeDep.js
Normal file
@@ -0,0 +1,49 @@
|
||||
import fs from 'fs';
|
||||
import chalk from 'chalk';
|
||||
import { execSync } from 'child_process';
|
||||
import { dependencies } from '../../package.json';
|
||||
|
||||
if (dependencies) {
|
||||
const dependenciesKeys = Object.keys(dependencies);
|
||||
const nativeDeps = fs
|
||||
.readdirSync('node_modules')
|
||||
.filter((folder) => fs.existsSync(`node_modules/${folder}/binding.gyp`));
|
||||
try {
|
||||
// Find the reason for why the dependency is installed. If it is installed
|
||||
// because of a devDependency then that is okay. Warn when it is installed
|
||||
// because of a dependency
|
||||
const { dependencies: dependenciesObject } = JSON.parse(
|
||||
execSync(`npm ls ${nativeDeps.join(' ')} --json`).toString()
|
||||
);
|
||||
const rootDependencies = Object.keys(dependenciesObject);
|
||||
const filteredRootDependencies = rootDependencies.filter((rootDependency) =>
|
||||
dependenciesKeys.includes(rootDependency)
|
||||
);
|
||||
if (filteredRootDependencies.length > 0) {
|
||||
const plural = filteredRootDependencies.length > 1;
|
||||
console.log(`
|
||||
${chalk.whiteBright.bgYellow.bold(
|
||||
'Webpack does not work with native dependencies.'
|
||||
)}
|
||||
${chalk.bold(filteredRootDependencies.join(', '))} ${
|
||||
plural ? 'are native dependencies' : 'is a native dependency'
|
||||
} and should be installed inside of the "./app" folder.
|
||||
First, uninstall the packages from "./package.json":
|
||||
${chalk.whiteBright.bgGreen.bold('yarn remove your-package')}
|
||||
${chalk.bold(
|
||||
'Then, instead of installing the package to the root "./package.json":'
|
||||
)}
|
||||
${chalk.whiteBright.bgRed.bold('yarn add your-package')}
|
||||
${chalk.bold('Install the package to "./app/package.json"')}
|
||||
${chalk.whiteBright.bgGreen.bold('cd ./app && yarn add your-package')}
|
||||
Read more about native dependencies at:
|
||||
${chalk.bold(
|
||||
'https://electron-react-boilerplate.js.org/docs/adding-dependencies/#module-structure'
|
||||
)}
|
||||
`);
|
||||
process.exit(1);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Native dependencies could not be checked');
|
||||
}
|
||||
}
|
||||
16
enlightApp/internals/scripts/CheckNodeEnv.js
Normal file
16
enlightApp/internals/scripts/CheckNodeEnv.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import chalk from 'chalk';
|
||||
|
||||
export default function CheckNodeEnv(expectedEnv) {
|
||||
if (!expectedEnv) {
|
||||
throw new Error('"expectedEnv" not set');
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== expectedEnv) {
|
||||
console.log(
|
||||
chalk.whiteBright.bgRed.bold(
|
||||
`"process.env.NODE_ENV" must be "${expectedEnv}" to use this webpack config`
|
||||
)
|
||||
);
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
16
enlightApp/internals/scripts/CheckPortInUse.js
Normal file
16
enlightApp/internals/scripts/CheckPortInUse.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import chalk from 'chalk';
|
||||
import detectPort from 'detect-port';
|
||||
|
||||
const port = process.env.PORT || '1212';
|
||||
|
||||
detectPort(port, (err, availablePort) => {
|
||||
if (port !== String(availablePort)) {
|
||||
throw new Error(
|
||||
chalk.whiteBright.bgRed.bold(
|
||||
`Port "${port}" on "localhost" is already in use. Please use another port. ex: PORT=4343 yarn start`
|
||||
)
|
||||
);
|
||||
} else {
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
5
enlightApp/internals/scripts/CheckYarn.js
Normal file
5
enlightApp/internals/scripts/CheckYarn.js
Normal file
@@ -0,0 +1,5 @@
|
||||
if (!/yarn\.js$/.test(process.env.npm_execpath || '')) {
|
||||
console.warn(
|
||||
"\u001b[33mYou don't seem to be using yarn. This could produce unexpected results.\u001b[39m"
|
||||
);
|
||||
}
|
||||
7
enlightApp/internals/scripts/DeleteSourceMaps.js
Normal file
7
enlightApp/internals/scripts/DeleteSourceMaps.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import path from 'path';
|
||||
import rimraf from 'rimraf';
|
||||
|
||||
export default function deleteSourceMaps() {
|
||||
rimraf.sync(path.join(__dirname, '../../app/dist/*.js.map'));
|
||||
rimraf.sync(path.join(__dirname, '../../app/*.js.map'));
|
||||
}
|
||||
22
enlightApp/internals/scripts/ElectronRebuild.js
Normal file
22
enlightApp/internals/scripts/ElectronRebuild.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import path from 'path';
|
||||
import { execSync } from 'child_process';
|
||||
import fs from 'fs';
|
||||
import { dependencies } from '../../app/package.json';
|
||||
|
||||
const nodeModulesPath = path.join(__dirname, '..', '..', 'app', 'node_modules');
|
||||
|
||||
if (
|
||||
Object.keys(dependencies || {}).length > 0 &&
|
||||
fs.existsSync(nodeModulesPath)
|
||||
) {
|
||||
const electronRebuildCmd =
|
||||
'../node_modules/.bin/electron-rebuild --parallel --force --types prod,dev,optional --module-dir .';
|
||||
const cmd =
|
||||
process.platform === 'win32'
|
||||
? electronRebuildCmd.replace(/\//g, '\\')
|
||||
: electronRebuildCmd;
|
||||
execSync(cmd, {
|
||||
cwd: path.join(__dirname, '..', '..', 'app'),
|
||||
stdio: 'inherit',
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user