1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | return new (P || (P = Promise))(function (resolve, reject) {
|
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5 | function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
|
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7 | step((generator = generator.apply(thisArg, _arguments)).next());
|
8 | });
|
9 | };
|
10 | const fs = require('fs-extra-promise');
|
11 | const path = require('path');
|
12 | let hook = { name: "generateHtmlFile", execute: null };
|
13 | hook.execute = function (env) {
|
14 | return __awaiter(this, void 0, void 0, function* () {
|
15 | let htmlFilePath = path.join(env.root, 'index.html');
|
16 | let outputPath = path.join(env.releaseFolder, 'index.html');
|
17 | let content = yield fs.readFileAsync(htmlFilePath, "utf-8");
|
18 | content = replaceHTMLContent(content);
|
19 | yield fs.writeFileAsync(outputPath, content);
|
20 | yield copyLib(content);
|
21 | yield cp("resource");
|
22 | function copyLib(content) {
|
23 | return __awaiter(this, void 0, void 0, function* () {
|
24 | let reg2 = /src\=\"[^>]*\"/g;
|
25 | let libs = content.match(reg2).map(item => {
|
26 | let from = 'src=\"'.length;
|
27 | let to = item.length - '\"'.length;
|
28 | return item.substring(from, to);
|
29 | });
|
30 | yield Promise.all(libs.map(lib => cp(lib)));
|
31 | });
|
32 | }
|
33 | function cp(file) {
|
34 | return __awaiter(this, void 0, void 0, function* () {
|
35 | if (yield fs.existsAsync(file)) {
|
36 | yield fs.copyAsync(path.join(env.root, file), path.join(env.releaseFolder, file));
|
37 | }
|
38 | });
|
39 | }
|
40 | function replaceHTMLContent(content) {
|
41 |
|
42 | var reg = /src[^>]*src-release/g;
|
43 | let result = content = content.replace(reg, "src");
|
44 |
|
45 | var reg = /<!--(\s)*game_files_start(\s)*-->[\s\S]*<!--(\s)*game_files_end(\s)*-->/;
|
46 | var replaceStr = '<!--game_files_start-->\n' + '\t<script src="main.min.js"></script>\n' + '\t<!--game_files_end-->';
|
47 | content = content.replace(reg, replaceStr);
|
48 | return content;
|
49 | }
|
50 | });
|
51 | };
|
52 | Object.defineProperty(exports, "__esModule", { value: true });
|
53 | exports.default = hook;
|
54 |
|
\ | No newline at end of file |