Skip to content

Commit 5f42fa5

Browse files
author
Cam Tullos
committed
WIP: Need to sort out the router issue where it's returning 'PAGE NOT FOUND' for static file:///index.html.
1 parent 41bb57d commit 5f42fa5

27 files changed

+972
-6582
lines changed

.core/.cli/commands/electron/builder/actions.js

+144-105
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ const path = require('path');
22
const chalk = require('chalk');
33
const fs = require('fs-extra');
44
const _ = require('underscore');
5+
const run = require('gulp-run');
56
const moment = require('moment');
67
const op = require('object-path');
7-
const { spawn } = require('child_process');
88
const prettier = require('prettier').format;
99
const handlebars = require('handlebars').compile;
1010

1111
const timestamp = () => `[${chalk.magenta(moment().format('HH:mm:ss'))}]`;
12-
1312
const msg = (...msg) => console.log(timestamp(), ...msg);
14-
const override = `
13+
14+
const gulpOverride = `
1515
module.${chalk.cyan('exports')} = ${chalk.magenta('config')} => {
1616
config.${chalk.cyan('dest')}.${chalk.cyan('electron')} = ${chalk.magenta(
1717
"'build-electron'",
@@ -35,8 +35,22 @@ module.${chalk.cyan('exports')} = ${chalk.magenta('config')} => {
3535
};
3636
`;
3737

38+
const manifestOverride = `
39+
module.${chalk.cyan('exports')} = ${chalk.magenta('config')} => {
40+
config.${chalk.cyan('contexts.components.mode')} = ${chalk.magenta(
41+
"'sync'",
42+
)};
43+
config.${chalk.cyan('contexts.common.mode')} = ${chalk.magenta("'sync'")};
44+
config.${chalk.cyan('contexts.toolkit.mode')} = ${chalk.magenta("'sync'")};
45+
config.${chalk.cyan('contexts.core.mode')} = ${chalk.magenta("'sync'")};
46+
47+
return ${chalk.magenta('config')};
48+
};
49+
`;
50+
3851
let cwd;
3952
let gulpConfig;
53+
let manifestConfig;
4054
let reactiumConfig;
4155

4256
module.exports = () => {
@@ -49,23 +63,44 @@ module.exports = () => {
4963
'.core',
5064
'reactium-config.js',
5165
));
66+
5267
gulpConfig = reactiumConfig.build;
68+
manifestConfig = reactiumConfig.manifest;
5369

5470
if (!op.has(gulpConfig, 'dest.electron')) {
55-
console.log('\n');
5671
msg(
5772
`The following ${chalk.cyan(
5873
'gulp.config.override.js',
59-
)} values need to be added:`,
74+
)} values need to be set:`,
75+
);
76+
console.log('\n');
77+
console.log(gulpOverride);
78+
console.log(`${chalk.magenta('Action cancelled')}!`);
79+
console.log('\n');
80+
81+
process.exit(0);
82+
}
83+
84+
if (
85+
op.get(manifestConfig, 'contexts.components.mode') !==
86+
'sync'
87+
) {
88+
msg(
89+
`The following ${chalk.cyan(
90+
'manifest.config.override.js',
91+
)} values need to be set:`,
6092
);
6193
console.log('\n');
62-
console.log(override);
94+
console.log(manifestOverride);
95+
console.log(`${chalk.magenta('Action cancelled')}!`);
6396
console.log('\n');
97+
6498
process.exit(0);
6599
}
66100

67101
resolve({ action, status: 200 });
68102
}),
103+
69104
config: ({ action, props }) =>
70105
new Promise(resolve => {
71106
const configFile = path.join(
@@ -108,124 +143,78 @@ module.exports = () => {
108143

109144
build: ({ action, props }) =>
110145
new Promise(resolve => {
111-
const exec = spawn('gulp', ['--color'], {
112-
env: {
113-
...process.env,
114-
cwd,
115-
NODE_ENV: 'production',
116-
},
117-
});
118-
119-
exec.on('exit', () => resolve({ action, status: 200 }));
120-
exec.stderr.pipe(process.stderr);
121-
exec.stdout.pipe(process.stdout);
122-
}),
123-
124-
babelConfig: ({ action, props }) =>
125-
new Promise(resolve => {
126-
msg('Generating', chalk.cyan('babel.config.js') + '...');
127-
128-
const babelBuildFile = path.join(
129-
cwd,
130-
op.get(reactiumConfig, 'dest.electron', 'build-electron'),
131-
'babel.config.js',
146+
msg('Building', chalk.cyan('app') + '...');
147+
const cmd = new run.Command(
148+
`cross-env NODE_ENV=production gulp --color`,
149+
{ verbosity: 0 },
132150
);
133-
const babelConfigFile = path.join(cwd, 'babel.config.js');
134-
135-
fs.ensureFileSync(babelBuildFile);
136-
fs.copySync(babelConfigFile, babelBuildFile);
137-
138-
resolve({ action, status: 200 });
139-
}),
140-
141-
babelConfigUpdate: ({ action, props }) =>
142-
new Promise(resolve => {
143-
msg('Updating', chalk.cyan('babel.config.js paths') + '...');
144-
const babelBuildFile = path.normalize(
145-
path.join(
146-
cwd,
147-
op.get(
148-
reactiumConfig,
149-
'dest.electron',
150-
'build-electron',
151-
),
152-
'babel.config.js',
153-
),
151+
setTimeout(
152+
() =>
153+
cmd.exec(null, () => resolve({ action, status: 200 })),
154+
1,
154155
);
155-
const cont = String(
156-
fs.readFileSync(babelBuildFile, 'utf-8'),
157-
).replace(/\'\.\/\.core/gi, "'../.core");
158-
159-
fs.writeFileSync(babelBuildFile, cont);
160-
161-
resolve({ action, status: 200 });
162156
}),
163157

164158
compileCore: ({ action, props }) =>
165159
new Promise(resolve => {
166-
msg('Compiling', chalk.cyan('.core') + '...');
160+
msg('Compiling', chalk.cyan('core') + '...');
161+
const srcDir = path.join(cwd, '.core');
167162
const outDir = path.join(
168163
cwd,
169164
op.get(gulpConfig, 'dest.build', 'build/.core'),
170165
);
171-
const srcDir = path.join(cwd, '.core');
172-
173-
const exec = spawn(
174-
'babel',
175-
[srcDir, '--out-dir', outDir, '--color'],
176-
{
177-
env: {
178-
...process.env,
179-
cwd,
180-
NODE_ENV: 'production',
181-
},
182-
},
166+
const cmd = new run.Command(
167+
`cross-env NODE_ENV=production babel "${srcDir}" --out-dir "${outDir}"`,
168+
{ verbosity: 0 },
169+
);
170+
setTimeout(
171+
() =>
172+
cmd.exec(null, () => resolve({ action, status: 200 })),
173+
1,
183174
);
184-
185-
exec.on('exit', () => resolve({ action, status: 200 }));
186-
//exec.stderr.pipe(process.stderr);
187-
exec.stdout.pipe(process.stdout);
188175
}),
189176

190177
compileSrc: ({ action, props }) =>
191178
new Promise(resolve => {
192179
msg('Compiling', chalk.cyan('src') + '...');
180+
const srcDir = path.join(cwd, 'src');
193181
const outDir = path.join(
194182
cwd,
195183
op.get(gulpConfig, 'dest.buildSrc', 'build/src'),
196184
);
197-
const srcDir = path.join(cwd, 'src');
198-
199-
const exec = spawn(
200-
'babel',
201-
[srcDir, '--out-dir', outDir, '--color'],
202-
{
203-
env: {
204-
...process.env,
205-
cwd,
206-
NODE_ENV: 'production',
207-
},
208-
},
185+
const cmd = new run.Command(
186+
`cross-env NODE_ENV=production babel "${srcDir}" --out-dir "${outDir}"`,
187+
{ verbosity: 0 },
188+
);
189+
setTimeout(
190+
() =>
191+
cmd.exec(null, () => resolve({ action, status: 200 })),
192+
1,
209193
);
210-
211-
exec.on('exit', () => resolve({ action, status: 200 }));
212-
//exec.stderr.pipe(process.stderr);
213-
exec.stdout.pipe(process.stdout);
214194
}),
195+
215196
static: ({ action, props }) =>
216197
new Promise(resolve => {
217-
msg('Copying', chalk.cyan('static assets') + '...');
218-
const exec = spawn('gulp', ['static', '--color'], {
219-
env: {
220-
...process.env,
198+
// Clear output directory
199+
fs.removeSync(
200+
path.join(
221201
cwd,
222-
NODE_ENV: 'production',
223-
},
224-
});
202+
op.get(
203+
gulpConfig,
204+
'dest.static',
205+
'build-electron/app/public',
206+
),
207+
),
208+
);
225209

226-
exec.on('exit', () => resolve({ action, status: 200 }));
227-
exec.stderr.pipe(process.stderr);
228-
exec.stdout.pipe(process.stdout);
210+
const cmd = new run.Command(`gulp static --color`, {
211+
verbosity: 0,
212+
});
213+
setTimeout(
214+
() =>
215+
cmd.exec(null, () => resolve({ action, status: 200 })),
216+
1,
217+
);
229218
}),
230219

231220
main: ({ action, props }) =>
@@ -261,14 +250,15 @@ module.exports = () => {
261250
);
262251

263252
if (!fs.existsSync(destDir)) {
253+
msg(`Copying ${chalk.cyan('resources')}...`);
264254
const templateDir = path.join(
265255
__dirname,
266256
'template',
267257
'resources',
268258
);
269259

270260
fs.ensureDirSync(destDir);
271-
fs.copySync(templateDir, destdir);
261+
fs.copySync(templateDir, destDir);
272262
}
273263

274264
resolve({ action, status: 200 });
@@ -283,6 +273,8 @@ module.exports = () => {
283273
);
284274

285275
if (!fs.existsSync(destFile)) {
276+
msg(`Generating ${chalk.cyan('package.json')}...`);
277+
286278
const templateFile = path.join(
287279
__dirname,
288280
'template',
@@ -296,11 +288,58 @@ module.exports = () => {
296288
resolve({ action, status: 200 });
297289
}),
298290

299-
complete: ({ action }) => {
300-
console.log('');
301-
msg('Build', chalk.cyan('Complete') + '!');
302-
console.log('');
303-
return Promise.resolve({ action, status: 200 });
304-
},
291+
icon: ({ action, props }) =>
292+
new Promise(resolve => {
293+
msg(`Generating ${chalk.cyan('icons')}...`);
294+
295+
const shFile = path.join(
296+
cwd,
297+
gulpConfig.dest.electron,
298+
'resources',
299+
'icon_gen.sh',
300+
);
301+
302+
const icon = path.join(
303+
cwd,
304+
gulpConfig.dest.electron,
305+
'resources',
306+
'icon.png',
307+
);
308+
309+
const output = path.join(
310+
cwd,
311+
gulpConfig.dest.electron,
312+
'resources',
313+
);
314+
315+
const cmd = new run.Command(
316+
`sh "${shFile}" "${icon}" "${output}"`,
317+
{ verbosity: 0 },
318+
);
319+
cmd.exec(null, () => resolve({ action, status: 200 }));
320+
}),
321+
322+
install: ({ action, props }) =>
323+
new Promise(resolve => {
324+
msg(`Installing ${chalk.cyan('dependencies')}...`);
325+
const cmd = new run.Command(
326+
`cd ${gulpConfig.dest.electron} && npm install`,
327+
{ verbosity: 0 },
328+
);
329+
setTimeout(
330+
() =>
331+
cmd.exec(null, () => resolve({ action, status: 200 })),
332+
1,
333+
);
334+
}),
335+
336+
complete: ({ action }) =>
337+
new Promise(resolve => {
338+
setTimeout(() => {
339+
msg('Build', chalk.cyan('Complete') + '!');
340+
console.log('\n');
341+
resolve({ action, status: 200 });
342+
}, 3000);
343+
}),
305344
};
306345
};

0 commit comments

Comments
 (0)