Skip to content

Commit bd25012

Browse files
committed
init
1 parent 7b168ac commit bd25012

6 files changed

Lines changed: 72 additions & 15 deletions

File tree

handlers/tutorial/lib/tutorialImporter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ module.exports = class TutorialImporter {
209209
data.githubLink = config.tutorialGithubBaseUrl + articlePath.slice(this.root.length) + '/article.md';
210210

211211
try {
212-
data.headJs = fs.readFileSync(path.join(articlePath, 'head.js'));
212+
data.headJs = fs.readFileSync(path.join(articlePath, 'head.js'), {encoding: 'utf8'});
213213
} catch (e) {
214214
}
215215
try {
216-
data.headCss = fs.readFileSync(path.join(articlePath, 'head.css'));
216+
data.headCss = fs.readFileSync(path.join(articlePath, 'head.css'), {encoding: 'utf8'});
217217
} catch (e) {
218218
}
219219
try {
220-
data.headHtml = fs.readFileSync(path.join(articlePath, 'head.html'));
220+
data.headHtml = fs.readFileSync(path.join(articlePath, 'head.html'), {encoding: 'utf8'});
221221
} catch (e) {
222222
}
223223

modules/app.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ app.proxy = true;
3434

3535
// ========= Helper handlers ===========
3636

37-
config.handlers.forEach(handler => app.requireHandler(handler));
37+
for(const handlerName in config.handlers) {
38+
app.requireHandler(handlerName);
39+
}
3840

3941
// must be last
4042
app.requireHandler('404');

modules/config/handlers.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const path = require('path');
44
const fs = require('fs');
55

6-
let handlers = [
6+
let handlerNames = [
77
'static',
88
'requestId',
99
'requestLog',
@@ -43,4 +43,17 @@ let handlers = [
4343
'tutorial'
4444
].filter(Boolean);
4545

46+
let handlers = {};
47+
48+
for (const name of handlerNames) {
49+
let handlerPath = require.resolve(name);
50+
if (handlerPath.endsWith('index.js')) {
51+
handlerPath = path.dirname(handlerPath);
52+
}
53+
handlers[name] = {
54+
path: handlerPath
55+
}
56+
}
57+
58+
4659
module.exports = handlers;

modules/config/webpack.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ let noProcessModulesRegExp = /node_modules\/(angular|prismjs)/;
2424

2525
let devMode = process.env.NODE_ENV == 'development';
2626

27+
2728
module.exports = function (config) {
2829
// tutorial.js?hash
2930
// tutorial.hash.js
@@ -39,6 +40,19 @@ module.exports = function (config) {
3940
modulesDirectories = modulesDirectories.concat(process.env.NODE_PATH.split(/[:;]/).map(p => path.resolve(p)));
4041
}
4142

43+
let assetPaths = [];
44+
for(let handlerName in config.handlers) {
45+
let handlerPath = config.handlers[handlerName].path;
46+
let from = `${handlerPath}/client/assets`;
47+
console.log(from);
48+
49+
if (fse.existsSync(from)) {
50+
assetPaths.push(from);
51+
}
52+
}
53+
console.log(assetPaths);
54+
55+
4256
let webpackConfig = {
4357
output: {
4458
// fs path
@@ -230,16 +244,14 @@ module.exports = function (config) {
230244
}),
231245

232246
new CopyWebpackPlugin(
233-
config.handlers.map(handler => {
234-
let from = `handlers/${handler}/client/assets`;
235-
if (!fse.existsSync(from)) return;
236-
247+
assetPaths.map(path => {
237248
return {
238-
from,
249+
from: path,
239250
to: config.publicRoot
240251
}
241-
}).filter(Boolean),
242-
{ debug: 'warning'}
252+
}),
253+
{ debug: 'debug'}
254+
// { debug: 'warning'}
243255
),
244256

245257
{

modules/lib/webpack/cssWatchRebuildPlugin.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ class CssWatchFS {
5151

5252
let styles = glob.sync(`${this.roots[name]}/**/*.styl`, {cwd: config.projectRoot});
5353

54-
config.handlers.forEach(handler => {
55-
let handlerStyles = glob.sync(`handlers/${handler}/client/styles/**/*.styl`, {cwd: config.projectRoot});
54+
for (const {path: handlerPath} of Object.values(config.handlers)) {
55+
let handlerStyles = glob.sync(`${handlerPath}/client/styles/**/*.styl`, {cwd: config.projectRoot});
5656
styles.push(...handlerStyles);
57-
});
57+
}
5858

59+
console.log("LOG STYLES", styles);
5960
let content = styles.map(s => `@require '../${s}'`).join("\n");
6061

6162
fs.writeFileSync(`${config.tmpRoot}/${name}.styl`, content);

replace.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
$files = glob("**/*.js");
4+
foreach($files as $file) {
5+
echo "$file\n";
6+
$content = file_get_contents($file);
7+
8+
$replaced = str_replace($search, $replace, $content);
9+
10+
file_put_contents($file, $content);
11+
}
12+
13+
$search = [
14+
"require('textUtil",
15+
"require('i18n",
16+
"require('log",
17+
"require('localStorage",
18+
"require('serverPug",
19+
"require('momentWithLocale"
20+
];
21+
22+
$replace = [
23+
"require('@jsengine/text-utils",
24+
"require('@jsengine/i18n",
25+
"require('@jsengine/log",
26+
"require('@jsengine/local-storage",
27+
"require('@jsengine/server-pug",
28+
"require('@jsengine/moment-with-locale"
29+
];

0 commit comments

Comments
 (0)