Skip to content

Commit

Permalink
chore: small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed May 8, 2022
1 parent b6ad0b7 commit afaa131
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 35 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
"chii": "./bin/chii.js"
},
"scripts": {
"ci": "npm run lint && npm run build",
"format": "npm run format:target && npm run format:server && prettier '*.{js,json}' 'bin/*.js' 'test/*.{html,json,js,css}' --write",
"format:target": "lsla prettier 'target/**/*.ts' --write",
"ci": "npm run lint && npm run build && npm run es5",
"format": "npm run format:server && prettier 'src/**/*.ts' '*.{js,json}' 'bin/*.js' 'test/*.{html,json,js,css}' --write",
"format:server": "lsla prettier 'server/**/*.js' --write",
"build": "gulp clean && npm run build:target && npm run build:front_end",
"build:target": "webpack --mode=production",
"build": "gulp clean && webpack --mode=production && npm run build:front_end",
"build:front_end": "npm run dev:front_end && gulp uglify",
"dev:target": "webpack --mode=development -w",
"dev": "webpack --mode=development -w",
"dev:front_end": "cd devtools/devtools-frontend && gn gen out/Default && autoninja -C out/Default && lsla shx cp -R out/Default/gen/front_end ../../public",
"lint": "npm run lint:server && npm run lint:target",
"lint:server": "eslint server/**/*.js",
"lint:target": "tslint target/**/*.ts",
"init:front_end": "cd devtools && rm -rf devtools-frontend && gclient sync --with_branch_heads --verbose && cd ../ && python3 script/apply_all_patches.py patches/config.json"
"init:front_end": "cd devtools && rm -rf devtools-frontend && gclient sync --with_branch_heads --verbose && cd ../ && python3 script/apply_all_patches.py patches/config.json",
"es5": "es-check es5 public/target.js"
},
"repository": {
"type": "git",
Expand All @@ -37,6 +36,7 @@
"devDependencies": {
"babel-eslint": "^10.1.0",
"chobitsu": "^0.3.3",
"es-check": "^6.2.1",
"eslint": "^6.8.0",
"gulp": "^4.0.2",
"gulp-clean": "^0.4.0",
Expand Down
18 changes: 11 additions & 7 deletions server/middle/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ module.exports = function (channelManager, domain) {
});
}

function createStaticFile(file) {
router.get(`/${file}`, async ctx => {
await send(ctx, file, {
root: path.resolve(__dirname, '../../public'),
maxAge,
});
});
}

createStatic('/front_end', '/public/front_end');
createStatic('/test', '/test');

router.get('/target.js', async ctx => {
await send(ctx, 'target.js', {
root: path.resolve(__dirname, '../../public'),
maxAge,
});
});
createStaticFile('target.js');
createStaticFile('index.js');

return router.routes();
};
27 changes: 9 additions & 18 deletions server/tpl/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
box-sizing: border-box;
}
body {
font-family: 'Segoe UI',Arial,'Microsoft Yahei',sans-serif;
font-family: Arial, Helvetica, sans-serif;
padding: 0 20px;
font-size: 13px;
font-family: Roboto;
}
body.platform-windows {
font-family: 'Segoe UI', Tahoma, sans-serif;
}
body.platform-linux {
font-family: Roboto, Ubuntu, Arial, sans-serif;
}
a {
color: #1966d2;
}
Expand Down Expand Up @@ -91,22 +97,7 @@
<a target="_blank" href="https://github.com/liriliri/chii">Chii v{{version}}</a>
</div>
{{/each}}
<script>
!function(o,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof module&&module.exports?module.exports=e():o._=e()}(this,function(){var _={};"object"==typeof window&&window._&&(_=window._);var isBrowser=_.isBrowser="object"==typeof window&&"object"==typeof document&&9===document.nodeType,objToStr=_.objToStr=(e=Object.prototype.toString,function(o){return e.call(o)}),e,isNode=_.isNode="undefined"!=typeof process&&"[object process]"===objToStr(process),random=_.random=function(o,e,r){null==e&&(e=o,o=0);var t=Math.random();return r||o%1||e%1?Math.min(o+t*(e-o+parseFloat("1e-"+((t+"").length-1))),e):o+Math.floor(t*(e-o+1))},randomBytes=_.randomBytes=function(exports){var crypto;return exports=function(o){for(var e=new Uint8Array(o),r=0;r<o;r++)e[r]=random(0,255);return e},isBrowser?(crypto=window.crypto||window.msCrypto,crypto&&(exports=function(o){var e=new Uint8Array(o);return crypto.getRandomValues(e),e})):isNode&&(crypto=eval("require")("crypto"),exports=function(o){return crypto.randomBytes(o)}),exports}({});return _.randomId=function(){for(var o=0<arguments.length&&void 0!==arguments[0]?arguments[0]:21,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"ModuleSymbhasOwnPr-0123456789ABCDEFGHIJKLNQRTUVWXYZ_cfgijkpqtvxz",r="",t=e.length,n=randomBytes(21);0<o--;)r+=e[n[o]%t];return r},_});
</script>
<script>
function inspect(id) {
const protocol = location.protocol === 'https:' ? 'wss' : 'ws';
const url = location.protocol + `//{{domain}}/front_end/chii_app.html?${protocol}={{domain}}/client/${_.randomId(6)}?target=${id}`;
window.open(url, '_blank');
}
const start = Date.now();
setInterval(() => {
fetch('/timestamp').then(res => res.text()).then(timestamp => {
if (timestamp > start) location.reload();
}, () => {});
}, 2000);
</script>
<script>window.domain = '{{domain}}';</script>
<script src="//{{domain}}/index.js"></script>
</body>
</html>
37 changes: 37 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import detectOs from 'licia/detectOs';
import $ from 'licia/$';
import randomId from 'licia/randomId';
import toInt from 'licia/toInt';

declare const window: any;

const os = detectOs();

switch (os) {
case 'linux':
$('body').addClass('platform-linux');
break;
case 'windows':
$('body').addClass('platform-windows');
break;
}

window.inspect = function (id: string) {
const domain = window.domain;
const protocol = location.protocol === 'https:' ? 'wss' : 'ws';
const url =
location.protocol + `//${domain}/front_end/chii_app.html?${protocol}=${domain}/client/${randomId(6)}?target=${id}`;
window.open(url, '_blank');
};

const start = Date.now();
setInterval(() => {
fetch('/timestamp')
.then(res => res.text())
.then(
timestamp => {
if (toInt(timestamp) > start) location.reload();
},
() => {}
);
}, 2000);
File renamed without changes.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"esModuleInterop": true,
"lib": ["DOM", "ES2015"]
},
"include": ["target/**/*"]
"include": ["src/**/*"]
}
7 changes: 5 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ const path = require('path');

module.exports = (env, argv) => {
const config = {
entry: './target/index.ts',
entry: {
index: './src/index.ts',
target: './src/target.ts',
},
devtool: 'inline-source-map',
output: {
filename: 'target.js',
filename: '[name].js',
path: path.resolve(__dirname, 'public'),
},
resolve: {
Expand Down

0 comments on commit afaa131

Please sign in to comment.