Skip to content

Commit cb445d9

Browse files
committed
Enhance build scripts for Windows compatibility #7796
1 parent 4e9e78e commit cb445d9

4 files changed

Lines changed: 33 additions & 26 deletions

File tree

buildScripts/createApp.mjs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import chalk from 'chalk';
2-
import { spawnSync } from 'child_process';
3-
import { Command } from 'commander/esm.mjs';
4-
import envinfo from 'envinfo';
5-
import fs from 'fs-extra';
6-
import inquirer from 'inquirer';
7-
import os from 'os';
8-
import path from 'path';
1+
import chalk from 'chalk';
2+
import {spawnSync} from 'child_process';
3+
import {Command} from 'commander/esm.mjs';
4+
import envinfo from 'envinfo';
5+
import fs from 'fs-extra';
6+
import inquirer from 'inquirer';
7+
import os from 'os';
8+
import path from 'path';
99

1010
const
1111
__dirname = path.resolve(),
1212
cwd = process.cwd(),
13+
nodeCmd = os.platform().startsWith('win') ? 'node.exe' : 'node', // node binary based on OS
1314
requireJson = path => JSON.parse(fs.readFileSync((path))),
1415
packageJson = requireJson(path.join(__dirname, 'package.json')),
1516
insideNeo = packageJson.name.includes('neo.mjs'),
@@ -274,7 +275,7 @@ if (programOpts.info) {
274275
fs.writeFileSync(appJsonPath, JSON.stringify(appJson, null, 4));
275276

276277
if (mainThreadAddons.includes('HighlightJS')) {
277-
const childProcess = spawnSync('node', [
278+
const childProcess = spawnSync(nodeCmd, [
278279
'./buildScripts/copyFolder.mjs',
279280
'-s',
280281
path.resolve(neoPath, 'docs/resources'),

buildScripts/createAppMinimal.mjs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import chalk from 'chalk';
2-
import { spawnSync } from 'child_process';
3-
import { Command } from 'commander/esm.mjs';
4-
import envinfo from 'envinfo';
5-
import fs from 'fs-extra';
6-
import inquirer from 'inquirer';
7-
import os from 'os';
8-
import path from 'path';
9-
10-
const __dirname = path.resolve(),
11-
cwd = process.cwd(),
12-
requireJson = path => JSON.parse(fs.readFileSync((path))),
13-
packageJson = requireJson(path.join(__dirname, 'package.json')),
14-
insideNeo = packageJson.name.includes('neo.mjs'),
1+
import chalk from 'chalk';
2+
import {spawnSync} from 'child_process';
3+
import {Command} from 'commander/esm.mjs';
4+
import envinfo from 'envinfo';
5+
import fs from 'fs-extra';
6+
import inquirer from 'inquirer';
7+
import os from 'os';
8+
import path from 'path';
9+
10+
const
11+
__dirname = path.resolve(),
12+
cwd = process.cwd(),
13+
nodeCmd = os.platform().startsWith('win') ? 'node.exe' : 'node', // node binary based on OS
14+
requireJson = path => JSON.parse(fs.readFileSync((path))),
15+
packageJson = requireJson(path.join(__dirname, 'package.json')),
16+
insideNeo = packageJson.name.includes('neo.mjs'),
1517
neoPath = insideNeo ? './' : './node_modules/neo.mjs/',
1618
addonChoices = fs.readdirSync(path.join(neoPath, '/src/main/addon')).map(item => item.slice(0, -4)),
1719
program = new Command(),
@@ -319,7 +321,7 @@ export default Neo.setupClass(${className});
319321
fs.writeFileSync(appJsonPath, JSON.stringify(appJson, null, 4));
320322

321323
if (mainThreadAddons.includes('HighlightJS')) {
322-
spawnSync('node', [
324+
spawnSync(nodeCmd, [
323325
'./buildScripts/copyFolder.mjs',
324326
'-s',
325327
path.resolve(neoPath, 'docs/resources'),

buildScripts/webpack/development/webpack.config.main.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'fs-extra';
2+
import os from 'os';
23
import path from 'path';
34
import webpack from 'webpack';
45
import WebpackHookPlugin from 'webpack-hook-plugin';
@@ -14,6 +15,7 @@ const cwd = process.cwd(),
1415
copyFolder = path.resolve(neoPath, 'buildScripts/copyFolder.mjs'),
1516
faFrom = path.resolve(cwd, 'node_modules/@fortawesome/fontawesome-free'),
1617
faTo = path.resolve(cwd, buildTarget.folder, 'resources/fontawesome-free'),
18+
nodeCmd = os.platform().startsWith('win') ? 'node.exe' : 'node',
1719
plugins = [];
1820

1921
let contextAdjusted = false;
@@ -53,7 +55,7 @@ export default {
5355
}
5456
}),
5557
new WebpackHookPlugin({
56-
onBuildEnd: [`node ${copyFolder} -s ${faFrom} -t ${faTo}`]
58+
onBuildEnd: [`${nodeCmd} ${copyFolder} -s ${faFrom} -t ${faTo}`]
5759
}),
5860
...plugins
5961
],

buildScripts/webpack/production/webpack.config.main.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'fs-extra';
2+
import os from 'os';
23
import path from 'path';
34
import webpack from 'webpack';
45
import WebpackHookPlugin from 'webpack-hook-plugin';
@@ -14,6 +15,7 @@ const cwd = process.cwd(),
1415
copyFolder = path.resolve(neoPath, 'buildScripts/copyFolder.mjs'),
1516
faFrom = path.resolve(cwd, 'node_modules/@fortawesome/fontawesome-free'),
1617
faTo = path.resolve(cwd, buildTarget.folder, 'resources/fontawesome-free'),
18+
nodeCmd = os.platform().startsWith('win') ? 'node.exe' : 'node',
1719
plugins = [];
1820

1921
let contextAdjusted = false;
@@ -52,7 +54,7 @@ export default {
5254
}
5355
}),
5456
new WebpackHookPlugin({
55-
onBuildEnd: [`node ${copyFolder} -s ${faFrom} -t ${faTo}`]
57+
onBuildEnd: [`${nodeCmd} ${copyFolder} -s ${faFrom} -t ${faTo}`]
5658
}),
5759
...plugins
5860
],

0 commit comments

Comments
 (0)