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