mirror of
https://github.com/scratchfoundation/scratch-desktop.git
synced 2025-05-15 15:20:47 -04:00
fix: lint errors
This commit is contained in:
parent
8989601dd6
commit
725e1d0007
6 changed files with 57 additions and 55 deletions
|
@ -1,4 +1,4 @@
|
|||
const { spawn } = require('child_process');
|
||||
const {spawn} = require('child_process');
|
||||
const webpack = require('webpack');
|
||||
const WebpackDevServer = require('webpack-dev-server');
|
||||
const chalk = require('chalk');
|
||||
|
@ -8,22 +8,20 @@ const rendererConfig = require('../webpack.renderer.js');
|
|||
|
||||
const PORT = process.env.PORT || 8601;
|
||||
|
||||
const buildRenderer = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(chalk.cyan('Building renderer process...'));
|
||||
const buildRenderer = () => new Promise((resolve, reject) => {
|
||||
console.log(chalk.cyan('Building renderer process...'));
|
||||
|
||||
const compiler = webpack(rendererConfig);
|
||||
compiler.run((err, stats) => {
|
||||
if (err || stats.hasErrors()) {
|
||||
console.error(chalk.red('Renderer build failed:', err || stats.toString()));
|
||||
reject(err || new Error('Renderer build failed.'));
|
||||
} else {
|
||||
console.log(chalk.green('Renderer built successfully!'));
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
const compiler = webpack(rendererConfig);
|
||||
compiler.run((err, stats) => {
|
||||
if (err || stats.hasErrors()) {
|
||||
console.error(chalk.red('Renderer build failed:', err || stats.toString()));
|
||||
reject(err || new Error('Renderer build failed.'));
|
||||
} else {
|
||||
console.log(chalk.green('Renderer built successfully!'));
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
const startRenderer = async () => {
|
||||
console.log(chalk.cyan('Starting Webpack Dev Server...'));
|
||||
|
@ -34,7 +32,7 @@ const startRenderer = async () => {
|
|||
hot: true,
|
||||
compress: true,
|
||||
port: PORT,
|
||||
headers: { 'Access-Control-Allow-Origin': '*' },
|
||||
headers: {'Access-Control-Allow-Origin': '*'},
|
||||
historyApiFallback: true
|
||||
},
|
||||
compiler
|
||||
|
@ -47,12 +45,12 @@ const startRenderer = async () => {
|
|||
console.error(chalk.red('Failed to start Webpack Dev Server:', err));
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const startElectron = async () => {
|
||||
console.log(chalk.cyan('Starting Electron...'));
|
||||
|
||||
await waitOn({ resources: [`http://localhost:${PORT}`] });
|
||||
await waitOn({resources: [`http://localhost:${PORT}`]});
|
||||
|
||||
spawn('electron', ['.'], {
|
||||
stdio: 'inherit',
|
||||
|
@ -60,7 +58,7 @@ const startElectron = async () => {
|
|||
});
|
||||
};
|
||||
|
||||
const start = async () => {
|
||||
const start = () => {
|
||||
console.log(chalk.green('Building main process...'));
|
||||
|
||||
const mainProcess = spawn('npm', ['run', 'compile:main'], {
|
||||
|
@ -68,7 +66,7 @@ const start = async () => {
|
|||
shell: true
|
||||
});
|
||||
|
||||
mainProcess.on('exit', async (code) => {
|
||||
mainProcess.on('exit', async code => {
|
||||
if (code === 0) {
|
||||
console.log(chalk.green('Main process built successfully!'));
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ const displayPermissionDeniedWarning = (browserWindow, permissionType) => {
|
|||
const makeFullUrl = (url, search = null) => {
|
||||
const baseUrl = (isDevelopment ?
|
||||
`http://localhost:${PORT}/` :
|
||||
`file://${path.join(__dirname, "../renderer")}/`
|
||||
`file://${path.join(__dirname, '../renderer')}/`
|
||||
);
|
||||
const fullUrl = new URL(url, baseUrl);
|
||||
if (search) {
|
||||
|
@ -469,7 +469,7 @@ const initialProjectDataPromise = (async () => {
|
|||
const projectData = await promisify(fs.readFile)(projectPath, null);
|
||||
return projectData;
|
||||
} catch (e) {
|
||||
log.error(`Error loading project data: ${e}`)
|
||||
log.error(`Error loading project data: ${e}`);
|
||||
dialog.showMessageBox(_windows.main, {
|
||||
type: 'error',
|
||||
title: 'Failed to load project',
|
||||
|
|
|
@ -34,4 +34,4 @@ routeModulePromise.then(routeModule => {
|
|||
const appTarget = document.getElementById('app');
|
||||
const routeElement = routeModule.default;
|
||||
ReactDOM.render(routeElement, appTarget);
|
||||
}).catch(error => log.error("Error rendering app: ", error));
|
||||
}).catch(error => log.error('Error rendering app: ', error));
|
||||
|
|
|
@ -4,11 +4,11 @@ const makeConfig = require('./webpack.makeConfig.js');
|
|||
|
||||
module.exports = makeConfig(
|
||||
{
|
||||
target: "electron-main",
|
||||
target: 'electron-main',
|
||||
entry: {
|
||||
main: './src/main/index.js'
|
||||
},
|
||||
context : path.resolve(__dirname),
|
||||
context: path.resolve(__dirname),
|
||||
externals: [
|
||||
'source-map-support',
|
||||
'electron',
|
||||
|
@ -22,10 +22,10 @@ module.exports = makeConfig(
|
|||
chunkFilename: '[name].bundle.js',
|
||||
assetModuleFilename: 'static/assets/[name].[hash][ext]',
|
||||
libraryTarget: 'commonjs2',
|
||||
path: path.resolve(__dirname, "dist/main")
|
||||
path: path.resolve(__dirname, 'dist/main')
|
||||
},
|
||||
module: { rules: [] },
|
||||
node: { __dirname: false, __filename: false }
|
||||
module: {rules: []},
|
||||
node: {__dirname: false, __filename: false}
|
||||
},
|
||||
{
|
||||
name: 'main',
|
||||
|
|
|
@ -94,7 +94,7 @@ const makeConfig = function (defaultConfig, options) {
|
|||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -103,7 +103,7 @@ const makeConfig = function (defaultConfig, options) {
|
|||
generator: {
|
||||
filename: 'static/assets/[name].[hash][ext]'
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.hex$/,
|
||||
use: [{
|
||||
|
@ -120,15 +120,17 @@ const makeConfig = function (defaultConfig, options) {
|
|||
filename: '[file].map'
|
||||
}),
|
||||
new webpack.DefinePlugin({
|
||||
__static: isProduction ? 'process.resourcesPath + "/static"' : JSON.stringify(path.resolve(process.cwd(), 'static')),
|
||||
}),
|
||||
__static: isProduction ?
|
||||
'process.resourcesPath + "/static"' :
|
||||
JSON.stringify(path.resolve(process.cwd(), 'static'))
|
||||
})
|
||||
].concat(options.plugins || []),
|
||||
resolve: {
|
||||
cacheWithContext: false,
|
||||
symlinks: false,
|
||||
// attempt to resolve file extensions in this order
|
||||
// (allows leaving off the extension when importing)
|
||||
extensions: [".js", ".jsx", ".json", ".node", ".css"],
|
||||
extensions: ['.js', '.jsx', '.json', '.node', '.css']
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const path = require('path');
|
||||
const fsExtra = require("fs-extra");
|
||||
const fsExtra = require('fs-extra');
|
||||
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
|
||||
|
@ -9,49 +9,51 @@ const makeConfig = require('./webpack.makeConfig.js');
|
|||
|
||||
const getModulePath = moduleName => path.dirname(require.resolve(`${moduleName}`));
|
||||
|
||||
function generateIndexFile(template) {
|
||||
let html = template;
|
||||
const generateIndexFile = template => {
|
||||
let html = template;
|
||||
|
||||
html = html.replace("</head>", '<script>require("source-map-support/source-map-support.js").install()</script></head>')
|
||||
html = html.replace(
|
||||
'</head>', '<script>require("source-map-support/source-map-support.js").install()</script></head>'
|
||||
);
|
||||
|
||||
const filePath = path.join("dist", ".renderer-index-template.html");
|
||||
fsExtra.outputFileSync(filePath, html);
|
||||
return `!!html-loader?minimize=false&attributes=false!${filePath}`
|
||||
}
|
||||
const filePath = path.join('dist', '.renderer-index-template.html');
|
||||
fsExtra.outputFileSync(filePath, html);
|
||||
return `!!html-loader?minimize=false&attributes=false!${filePath}`;
|
||||
};
|
||||
|
||||
let template = fsExtra.readFileSync("src/renderer/index.html", {encoding: "utf8"});
|
||||
const template = fsExtra.readFileSync('src/renderer/index.html', {encoding: 'utf8'});
|
||||
|
||||
module.exports = makeConfig(
|
||||
{
|
||||
target: "electron-renderer",
|
||||
target: 'electron-renderer',
|
||||
entry: {
|
||||
renderer: './src/renderer/index.js'
|
||||
},
|
||||
context : path.resolve(__dirname),
|
||||
context: path.resolve(__dirname),
|
||||
externals: [
|
||||
'source-map-support',
|
||||
'electron',
|
||||
'webpack',
|
||||
'webpack'
|
||||
],
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
assetModuleFilename: 'static/assets/[name].[hash][ext]',
|
||||
chunkFilename: '[name].bundle.js',
|
||||
libraryTarget: 'commonjs2',
|
||||
path: path.resolve(__dirname, "dist/renderer"),
|
||||
path: path.resolve(__dirname, 'dist/renderer')
|
||||
},
|
||||
module: {
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.node$/,
|
||||
use: "node-loader"
|
||||
use: 'node-loader'
|
||||
},
|
||||
{
|
||||
test: /\.(html)$/,
|
||||
use: { "loader": "html-loader" }
|
||||
},
|
||||
use: {loader: 'html-loader'}
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'renderer',
|
||||
|
@ -65,9 +67,9 @@ module.exports = makeConfig(
|
|||
],
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
filename: "index.html",
|
||||
filename: 'index.html',
|
||||
template: generateIndexFile(template),
|
||||
minify: false,
|
||||
minify: false
|
||||
}),
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [
|
||||
|
@ -90,7 +92,7 @@ module.exports = makeConfig(
|
|||
noErrorOnMissing: true
|
||||
}
|
||||
]
|
||||
}),
|
||||
})
|
||||
]
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue