@realsee/five 6.0.0-alpha.73 → 6.0.0-alpha.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/assets/search.js +1 -1
- package/docs/classes/five.Model.html +2 -2
- package/docs/classes/five.Work.html +13 -13
- package/docs/functions/five.parseWork.html +1 -1
- package/docs/types/five.ModelMaterialValues.html +1 -1
- package/docs/types/five.Models.html +4 -4
- package/docs/types/five.ParseWorkOptions.html +2 -2
- package/docs/types/five.Works.html +1 -1
- package/docs/variables/five.defaultPbmParameters.html +1 -1
- package/five/index.d.ts +6 -0
- package/five/index.js +71 -71
- package/five/index.mjs +1338 -1352
- package/gltf-loader/index.js +3 -3
- package/gltf-loader/index.mjs +3 -3
- package/line/index.js +3 -3
- package/line/index.mjs +3 -3
- package/package.json +2 -8
- package/react/index.js +2 -2
- package/react/index.mjs +2 -2
- package/scripts/five-staticify.js +183 -2
- package/sticker/index.js +3 -3
- package/sticker/index.mjs +3 -3
- package/umd/five-gltf-loader.js +3 -3
- package/umd/five-line.js +3 -3
- package/umd/five-react.js +2 -2
- package/umd/five-sticker.js +3 -3
- package/umd/five-vfx.js +2 -2
- package/umd/five-vue.js +2 -2
- package/umd/five.js +20 -20
- package/vfx/index.js +2 -2
- package/vfx/index.mjs +2 -2
- package/vue/index.js +2 -2
- package/vue/index.mjs +2 -2
- package/exporters/staticify.js +0 -210
- package/scripts/five-plugin-init.js +0 -83
- package/scripts/five-quick-start-init.js +0 -80
- package/scripts/five-react-component-init.js +0 -83
- package/templates/plugin/README.md +0 -38
- package/templates/plugin/devtools/external-five.js +0 -5
- package/templates/plugin/devtools/external-three.js +0 -5
- package/templates/plugin/devtools/tsconfig.build.json +0 -18
- package/templates/plugin/devtools/webpack.bundle.js +0 -44
- package/templates/plugin/devtools/webpack.example.js +0 -39
- package/templates/plugin/docs/.gitkeep +0 -0
- package/templates/plugin/examples/data.json +0 -507
- package/templates/plugin/examples/index.html +0 -28
- package/templates/plugin/examples/index.ts +0 -12
- package/templates/plugin/lib/index.ts +0 -30
- package/templates/plugin/package.json +0 -32
- package/templates/plugin/tsconfig.json +0 -26
- package/templates/quick-start/README.md +0 -47
- package/templates/quick-start/assets/work.json +0 -507
- package/templates/quick-start/index.html +0 -54
- package/templates/quick-start/index.tsx +0 -123
- package/templates/quick-start/package.json +0 -25
- package/templates/quick-start/tsconfig.json +0 -27
- package/templates/quick-start/webpack.config.js +0 -45
- package/templates/quick-start/webpack.production.js +0 -42
- package/templates/react-component/README.md +0 -32
- package/templates/react-component/devtools/external-five.js +0 -5
- package/templates/react-component/devtools/external-react.js +0 -5
- package/templates/react-component/devtools/external-three.js +0 -5
- package/templates/react-component/devtools/tsconfig.build.json +0 -19
- package/templates/react-component/devtools/webpack.bundle.js +0 -44
- package/templates/react-component/devtools/webpack.example.js +0 -39
- package/templates/react-component/docs/.gitkeep +0 -0
- package/templates/react-component/examples/data.json +0 -507
- package/templates/react-component/examples/index.html +0 -17
- package/templates/react-component/examples/index.tsx +0 -62
- package/templates/react-component/lib/index.tsx +0 -157
- package/templates/react-component/package.json +0 -38
- package/templates/react-component/tsconfig.json +0 -27
package/vfx/index.js
CHANGED
package/vfx/index.mjs
CHANGED
package/vue/index.js
CHANGED
package/vue/index.mjs
CHANGED
package/exporters/staticify.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const archiver = require("archiver");
|
|
4
|
-
const ejs = require("ejs");
|
|
5
|
-
const { parseWork } = require("@realsee/five/server");
|
|
6
|
-
|
|
7
|
-
function matchJsonpFunctionName(url) {
|
|
8
|
-
const regExps = [
|
|
9
|
-
/\.([0-9a-z]+)\.jsonp([\?\#].*)?$/i,
|
|
10
|
-
/jsonp_([0-9a-z]+)([\?\#].*)?$/i
|
|
11
|
-
];
|
|
12
|
-
for (const regExp of regExps) {
|
|
13
|
-
const matched = url.match(regExp);
|
|
14
|
-
if (matched) {
|
|
15
|
-
return "jsonp_" + matched[1];
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return null;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const CDN_PUBLIC_BASE = "//vrlab-public.ljcdn.com";
|
|
22
|
-
const CDN_IMAGE_BASE = "//vrlab-image4.ljcdn.com";
|
|
23
|
-
const CDN_TEST_PUBLIC_BASE = "//test-vr-public.realsee-cdn.com";
|
|
24
|
-
const CDN_TEST_IMAGE_BASE = "//test-vr-image.realsee-cdn.com";
|
|
25
|
-
function imageURL(url, size) {
|
|
26
|
-
if (url.indexOf(CDN_PUBLIC_BASE) >= 0) {
|
|
27
|
-
if (/\.(jpg|png)$/.test(url)) {
|
|
28
|
-
// 默认使用数据万象
|
|
29
|
-
// https://cloud.tencent.com/document/product/460/36544
|
|
30
|
-
if (size) {
|
|
31
|
-
let suffix = "?imageMogr2";
|
|
32
|
-
if (size) suffix += "/thumbnail/" + size + "x";
|
|
33
|
-
url = url.replace(CDN_PUBLIC_BASE, CDN_IMAGE_BASE) + suffix;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (url.indexOf(CDN_TEST_PUBLIC_BASE) >= 0) {
|
|
38
|
-
if (/\.(jpg|png)$/.test(url)) {
|
|
39
|
-
// 默认使用数据万象
|
|
40
|
-
// https://cloud.tencent.com/document/product/460/36544
|
|
41
|
-
if (size) {
|
|
42
|
-
let suffix = "?imageMogr2";
|
|
43
|
-
if (size) suffix += "/thumbnail/" + size + "x";
|
|
44
|
-
url = url.replace(CDN_TEST_PUBLIC_BASE, CDN_TEST_IMAGE_BASE) + suffix;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return url;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function download(url, jsonpHandleKey) {
|
|
52
|
-
const request = /^https\:/.test(url) ? require("https") : require("http");
|
|
53
|
-
return new Promise((resolve, reject) => {
|
|
54
|
-
const req = request.get(url, res => {
|
|
55
|
-
const mime = res.headers['content-type'];
|
|
56
|
-
const buffers = [];
|
|
57
|
-
|
|
58
|
-
res.on('data', chunk => buffers.push(chunk));
|
|
59
|
-
res.on('end', () => {
|
|
60
|
-
const contents = Buffer.concat(buffers);
|
|
61
|
-
if (jsonpHandleKey) {
|
|
62
|
-
const dataURL = `data:${mime};base64,${contents.toString('base64')}`;
|
|
63
|
-
const jsopContents = `window[${JSON.stringify(jsonpHandleKey)}] && window[${JSON.stringify(jsonpHandleKey)}](${JSON.stringify(dataURL)})`;
|
|
64
|
-
resolve(Buffer.from(jsopContents));
|
|
65
|
-
} else {
|
|
66
|
-
resolve(Buffer.from(contents));
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
res.on("error", () => reject(new Error(`fetch ${url} got error`)));
|
|
70
|
-
});
|
|
71
|
-
req.on("error", () => reject(new Error(`fetch ${url} got error`)));
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const template = `
|
|
76
|
-
<!DOCTYPE html>
|
|
77
|
-
<html lang="en">
|
|
78
|
-
<head>
|
|
79
|
-
<meta charset="UTF-8">
|
|
80
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
81
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
82
|
-
<title>REALSEE PREVIEW</title>
|
|
83
|
-
<style>
|
|
84
|
-
* { margin: 0; padding: 0; }
|
|
85
|
-
html, body { height: 100%; width: 100%; overflow: hidden; }
|
|
86
|
-
#app { position: fixed; top: 0; left: 0; right: 0; bottom: 0; overflow: hidden; }
|
|
87
|
-
.buttons { position: fixed; top: 10px; left: 10px; pointer-events: none; }
|
|
88
|
-
.buttons h3 { margin-top: 10px; text-shadow: 0 0 2px rgba(255, 255, 255, 0.5); }
|
|
89
|
-
.buttons button { pointer-events: auto; display: block; font-size: 14px; color: #FFF; background: #5a6268; padding: 3px 10px; border: 1px solid #333; margin-right: 2px; border-radius: 2px; cursor: pointer; margin-top: 10px; }
|
|
90
|
-
.buttons button:active { background: #333; }
|
|
91
|
-
</style>
|
|
92
|
-
<script src="./three.min.js"></script>
|
|
93
|
-
<script src="./five.js"></script>
|
|
94
|
-
<script>const workJSON = <%- JSON.stringify(work_json) %></script>
|
|
95
|
-
</head>
|
|
96
|
-
<body>
|
|
97
|
-
<!-- 试图渲染容器 -->
|
|
98
|
-
<div id="app"></div>
|
|
99
|
-
<script>
|
|
100
|
-
const five = new FiveSDK.Five();
|
|
101
|
-
five.appendTo(document.getElementById("app"));
|
|
102
|
-
const work = FiveSDK.parseWork(workJSON, { baseURL: "./", shortPath: <%- JSON.stringify(short_path) %>, jsonp: <%- JSON.stringify(jsonp) %> });
|
|
103
|
-
five.load(work);
|
|
104
|
-
|
|
105
|
-
const modeButtons = [
|
|
106
|
-
{ mode: "Panorama", label: "全景模式" },
|
|
107
|
-
{ mode: "Floorplan", label: "模型纵览模式" },
|
|
108
|
-
{ mode: "Topview", label: "模型俯视模式" },
|
|
109
|
-
{ mode: "Model", label: "模型漫游模式" },
|
|
110
|
-
];
|
|
111
|
-
|
|
112
|
-
const buttons = document.createElement("div");
|
|
113
|
-
buttons.className = "buttons";
|
|
114
|
-
document.body.appendChild(buttons);
|
|
115
|
-
buttons.appendChild(document.createElement("h3")).innerHTML = "模式控制";
|
|
116
|
-
|
|
117
|
-
// 模态按钮
|
|
118
|
-
for (let i = 0; i < modeButtons.length; i++) {
|
|
119
|
-
const button = document.createElement("button");
|
|
120
|
-
button.innerHTML = modeButtons[i].label;
|
|
121
|
-
button.addEventListener('click', () => {
|
|
122
|
-
// 通过 changeMode 方法可以切换模态
|
|
123
|
-
five.changeMode(FiveSDK.Five.Mode[modeButtons[i].mode]);
|
|
124
|
-
});
|
|
125
|
-
buttons.appendChild(button);
|
|
126
|
-
}
|
|
127
|
-
window.addEventListener("resize", () => five.refresh(), false);
|
|
128
|
-
</script>
|
|
129
|
-
</body>
|
|
130
|
-
</html>
|
|
131
|
-
`;
|
|
132
|
-
|
|
133
|
-
function getThreeJsBuffer() {
|
|
134
|
-
let tempPath = path.resolve(__dirname);
|
|
135
|
-
while (!(tempPath === '/' || tempPath === ".")) {
|
|
136
|
-
const threeFilePath = path.join(tempPath, "node_modules/three/build/three.min.js");
|
|
137
|
-
if (fs.existsSync(threeFilePath)) {
|
|
138
|
-
return fs.readFileSync(threeFilePath);
|
|
139
|
-
}
|
|
140
|
-
tempPath = path.dirname(tempPath);
|
|
141
|
-
}
|
|
142
|
-
throw new Error("three.js is not found");
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function getFiveJsBuffer() {
|
|
146
|
-
return fs.readFileSync(path.join(__dirname, "../umd/five.js"));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async function staticify(work, output, shortPath = false, jsonp = false, preview = true) {
|
|
150
|
-
const zipFilename = /\.zip$/.test(output) ? output : output + ".zip";
|
|
151
|
-
const outputStream = fs.createWriteStream(zipFilename);
|
|
152
|
-
const archive = archiver("zip", { zlib: { level: 9 } });
|
|
153
|
-
archive.on("error", (err) => { throw err; });
|
|
154
|
-
outputStream.on("close", function() {
|
|
155
|
-
console.log(`zip ${archive.pointer()} total bytes`);
|
|
156
|
-
console.log(`dist ${zipFilename}`);
|
|
157
|
-
});
|
|
158
|
-
archive.pipe(outputStream);
|
|
159
|
-
|
|
160
|
-
const resources = [];
|
|
161
|
-
const workJSONObject = JSON.parse(fs.readFileSync(work, "utf8"));
|
|
162
|
-
parseWork(workJSONObject, { shortPath, jsonp }, (origin, _, relative, type) => {
|
|
163
|
-
resources.push({ origin, relative, type });
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const textureCount = resources.filter(({ type }) => type === "texture").length;
|
|
167
|
-
let textureSize;
|
|
168
|
-
if (textureCount > 50) {
|
|
169
|
-
textureSize = 64;
|
|
170
|
-
} else if (textureCount > 40) {
|
|
171
|
-
textureSize = 128;
|
|
172
|
-
} else if (textureCount > 30) {
|
|
173
|
-
textureSize = 256;
|
|
174
|
-
} else if (textureCount > 15) {
|
|
175
|
-
textureSize = 512;
|
|
176
|
-
} else if (textureCount > 10) {
|
|
177
|
-
textureSize = 1024;
|
|
178
|
-
}
|
|
179
|
-
if (textureSize) {
|
|
180
|
-
for (const resource of resources) {
|
|
181
|
-
if (resource.type === "texture") {
|
|
182
|
-
resource.origin = imageURL(resource.origin, textureSize);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
for (const { origin, relative } of resources) {
|
|
187
|
-
const buffer = await download(origin, matchJsonpFunctionName(relative));
|
|
188
|
-
console.log(`${origin} -> ${relative}`);
|
|
189
|
-
archive.append(buffer, { name: relative });
|
|
190
|
-
}
|
|
191
|
-
archive.append(fs.readFileSync(work), { name: "work.json" });
|
|
192
|
-
|
|
193
|
-
if (preview) {
|
|
194
|
-
archive.append(getFiveJsBuffer(), { name: "five.js" });
|
|
195
|
-
archive.append(getThreeJsBuffer(), { name: "three.min.js" });
|
|
196
|
-
|
|
197
|
-
const data = {
|
|
198
|
-
work_json: workJSONObject,
|
|
199
|
-
short_path: Boolean(shortPath),
|
|
200
|
-
jsonp: Boolean(jsonp),
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const html = typeof preview === 'string' ? ejs.render(fs.readFileSync(preview, "utf8"), data) : ejs.render(template, data);
|
|
204
|
-
archive.append(html, { name: "index.html" });
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
archive.finalize();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
module.exports = staticify;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const child_process = require('child_process');
|
|
6
|
-
const copyfiles = require("copyfiles");
|
|
7
|
-
const glob = require("fast-glob");
|
|
8
|
-
|
|
9
|
-
function isObject(object) {
|
|
10
|
-
return object !== null && typeof object === "object" && !Array.isArray(object);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function deepMerge(object, anotherOject) {
|
|
14
|
-
if (!isObject(object) || !isObject(anotherOject)) {
|
|
15
|
-
return object;
|
|
16
|
-
}
|
|
17
|
-
for (let name in anotherOject) {
|
|
18
|
-
if (!anotherOject.hasOwnProperty(name)) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
let subObject = object[name];
|
|
22
|
-
let anotherSubObject = anotherOject[name];
|
|
23
|
-
|
|
24
|
-
if (isObject(anotherSubObject)) {
|
|
25
|
-
anotherSubObject = Object.assign({}, anotherSubObject);
|
|
26
|
-
}
|
|
27
|
-
if (
|
|
28
|
-
!object.hasOwnProperty(name) ||
|
|
29
|
-
!isObject(subObject) ||
|
|
30
|
-
!isObject(anotherSubObject)
|
|
31
|
-
) {
|
|
32
|
-
object[name] = anotherSubObject;
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
deepMerge(subObject, anotherSubObject);
|
|
36
|
-
}
|
|
37
|
-
return object;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function deleteTsNocheck(filename) {
|
|
41
|
-
let content = fs.readFileSync(filename, "utf8");
|
|
42
|
-
content = content.replace(/\/\/\s*\@ts\-nocheck/g, "");
|
|
43
|
-
fs.writeFileSync(filename, content, "utf8");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const distDir = process.cwd();
|
|
47
|
-
const templateDir = path.join(__dirname, "../templates/plugin");
|
|
48
|
-
process.chdir(templateDir);
|
|
49
|
-
|
|
50
|
-
let existsPackageJSONContent;
|
|
51
|
-
try {
|
|
52
|
-
existsPackageJSONContent = fs.readFileSync(path.join(distDir, "package.json"));
|
|
53
|
-
} catch (error) {}
|
|
54
|
-
|
|
55
|
-
const packageJSON = deepMerge(
|
|
56
|
-
JSON.parse(fs.readFileSync("package.json", "utf8")),
|
|
57
|
-
JSON.parse(existsPackageJSONContent || "{}"),
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const title = "FivePluginInit";
|
|
61
|
-
console.log(`${title}: Modify package.json`);
|
|
62
|
-
fs.writeFileSync(path.join(distDir, "package.json"), JSON.stringify(packageJSON, null, " "), "utf8");
|
|
63
|
-
|
|
64
|
-
console.log(`${title}: Generate files`);
|
|
65
|
-
copyfiles(["**/*.*", distDir], {
|
|
66
|
-
soft: true,
|
|
67
|
-
all: true,
|
|
68
|
-
exclude: ["package.json"],
|
|
69
|
-
}, () => {
|
|
70
|
-
const tsFiles = glob.sync(`**/*.ts?(x)`, { cwd: distDir });
|
|
71
|
-
for (const filename of tsFiles) {
|
|
72
|
-
deleteTsNocheck(path.join(distDir, filename));
|
|
73
|
-
}
|
|
74
|
-
console.log(`${title}: Run npm install`);
|
|
75
|
-
child_process.execSync(`npm install`, { stdio: 'inherit', cwd: distDir });
|
|
76
|
-
console.log(`${title}: Initialization complete`);
|
|
77
|
-
console.log(`${title}: Hint: npm run doc 生成使用文档`);
|
|
78
|
-
console.log(`${title}: Hint: npm run example 开发环境,运行样例`);
|
|
79
|
-
console.log(`${title}: Hint: npm run build:typescript 打包 npm 包`);
|
|
80
|
-
console.log(`${title}: Hint: npm run build:bundle 打包 bundle 包`);
|
|
81
|
-
console.log(`${title}: Hint: npm run build:all 生成使用文档并打包所有包`);
|
|
82
|
-
console.log(`${title}: Have a good day (^_^)v`);
|
|
83
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const child_process = require('child_process');
|
|
6
|
-
const copyfiles = require("copyfiles");
|
|
7
|
-
const glob = require("fast-glob");
|
|
8
|
-
|
|
9
|
-
function isObject(object) {
|
|
10
|
-
return object !== null && typeof object === "object" && !Array.isArray(object);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function deepMerge(object, anotherOject) {
|
|
14
|
-
if (!isObject(object) || !isObject(anotherOject)) {
|
|
15
|
-
return object;
|
|
16
|
-
}
|
|
17
|
-
for (let name in anotherOject) {
|
|
18
|
-
if (!anotherOject.hasOwnProperty(name)) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
let subObject = object[name];
|
|
22
|
-
let anotherSubObject = anotherOject[name];
|
|
23
|
-
|
|
24
|
-
if (isObject(anotherSubObject)) {
|
|
25
|
-
anotherSubObject = Object.assign({}, anotherSubObject);
|
|
26
|
-
}
|
|
27
|
-
if (
|
|
28
|
-
!object.hasOwnProperty(name) ||
|
|
29
|
-
!isObject(subObject) ||
|
|
30
|
-
!isObject(anotherSubObject)
|
|
31
|
-
) {
|
|
32
|
-
object[name] = anotherSubObject;
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
deepMerge(subObject, anotherSubObject);
|
|
36
|
-
}
|
|
37
|
-
return object;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function deleteTsNocheck(filename) {
|
|
41
|
-
let content = fs.readFileSync(filename, "utf8");
|
|
42
|
-
content = content.replace(/\/\/\s*\@ts\-nocheck/g, "");
|
|
43
|
-
fs.writeFileSync(filename, content, "utf8");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const distDir = process.cwd();
|
|
47
|
-
const templateDir = path.join(__dirname, "../templates/quick-start");
|
|
48
|
-
process.chdir(templateDir);
|
|
49
|
-
|
|
50
|
-
let existsPackageJSONContent;
|
|
51
|
-
try {
|
|
52
|
-
existsPackageJSONContent = fs.readFileSync(path.join(distDir, "package.json"));
|
|
53
|
-
} catch (error) {}
|
|
54
|
-
|
|
55
|
-
const packageJSON = deepMerge(
|
|
56
|
-
JSON.parse(fs.readFileSync("package.json", "utf8")),
|
|
57
|
-
JSON.parse(existsPackageJSONContent || "{}"),
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const title = "FiveQuickStart";
|
|
61
|
-
console.log(`${title}: Modify package.json`);
|
|
62
|
-
fs.writeFileSync(path.join(distDir, "package.json"), JSON.stringify(packageJSON, null, " "), "utf8");
|
|
63
|
-
|
|
64
|
-
console.log(`${title}: Generate files`);
|
|
65
|
-
copyfiles(["**/*.*", distDir], {
|
|
66
|
-
soft: true,
|
|
67
|
-
all: true,
|
|
68
|
-
exclude: ["package.json"],
|
|
69
|
-
}, () => {
|
|
70
|
-
const tsFiles = glob.sync(`**/*.ts?(x)`, { cwd: distDir });
|
|
71
|
-
for (const filename of tsFiles) {
|
|
72
|
-
deleteTsNocheck(path.join(distDir, filename));
|
|
73
|
-
}
|
|
74
|
-
console.log(`${title}: Run npm install`);
|
|
75
|
-
child_process.execSync(`npm install`, { stdio: 'inherit', cwd: distDir });
|
|
76
|
-
console.log(`${title}: Initialization complete`);
|
|
77
|
-
console.log(`${title}: Hint: npm run dev 开发环境,运行样例`);
|
|
78
|
-
console.log(`${title}: Hint: npm run build 打包 bundle 包`);
|
|
79
|
-
console.log(`${title}: Have a good day (^_^)v`);
|
|
80
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const child_process = require('child_process');
|
|
6
|
-
const copyfiles = require("copyfiles");
|
|
7
|
-
const glob = require("fast-glob");
|
|
8
|
-
|
|
9
|
-
function isObject(object) {
|
|
10
|
-
return object !== null && typeof object === "object" && !Array.isArray(object);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function deepMerge(object, anotherOject) {
|
|
14
|
-
if (!isObject(object) || !isObject(anotherOject)) {
|
|
15
|
-
return object;
|
|
16
|
-
}
|
|
17
|
-
for (let name in anotherOject) {
|
|
18
|
-
if (!anotherOject.hasOwnProperty(name)) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
let subObject = object[name];
|
|
22
|
-
let anotherSubObject = anotherOject[name];
|
|
23
|
-
|
|
24
|
-
if (isObject(anotherSubObject)) {
|
|
25
|
-
anotherSubObject = Object.assign({}, anotherSubObject);
|
|
26
|
-
}
|
|
27
|
-
if (
|
|
28
|
-
!object.hasOwnProperty(name) ||
|
|
29
|
-
!isObject(subObject) ||
|
|
30
|
-
!isObject(anotherSubObject)
|
|
31
|
-
) {
|
|
32
|
-
object[name] = anotherSubObject;
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
deepMerge(subObject, anotherSubObject);
|
|
36
|
-
}
|
|
37
|
-
return object;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function deleteTsNocheck(filename) {
|
|
41
|
-
let content = fs.readFileSync(filename, "utf8");
|
|
42
|
-
content = content.replace(/\/\/\s*\@ts\-nocheck/g, "");
|
|
43
|
-
fs.writeFileSync(filename, content, "utf8");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const distDir = process.cwd();
|
|
47
|
-
const templateDir = path.join(__dirname, "../templates/react-component");
|
|
48
|
-
process.chdir(templateDir);
|
|
49
|
-
|
|
50
|
-
let existsPackageJSONContent;
|
|
51
|
-
try {
|
|
52
|
-
existsPackageJSONContent = fs.readFileSync(path.join(distDir, "package.json"));
|
|
53
|
-
} catch (error) {}
|
|
54
|
-
|
|
55
|
-
const packageJSON = deepMerge(
|
|
56
|
-
JSON.parse(fs.readFileSync("package.json", "utf8")),
|
|
57
|
-
JSON.parse(existsPackageJSONContent || "{}"),
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const title = "FiveReactComponentInit";
|
|
61
|
-
console.log(`${title}: Modify package.json`);
|
|
62
|
-
fs.writeFileSync(path.join(distDir, "package.json"), JSON.stringify(packageJSON, null, " "), "utf8");
|
|
63
|
-
|
|
64
|
-
console.log(`${title}: Generate files`);
|
|
65
|
-
copyfiles(["**/*.*", distDir], {
|
|
66
|
-
soft: true,
|
|
67
|
-
all: true,
|
|
68
|
-
exclude: ["package.json"],
|
|
69
|
-
}, () => {
|
|
70
|
-
const tsFiles = glob.sync(`**/*.ts?(x)`, { cwd: distDir });
|
|
71
|
-
for (const filename of tsFiles) {
|
|
72
|
-
deleteTsNocheck(path.join(distDir, filename));
|
|
73
|
-
}
|
|
74
|
-
console.log(`${title}: Run npm install`);
|
|
75
|
-
child_process.execSync(`npm install`, { stdio: 'inherit', cwd: distDir });
|
|
76
|
-
console.log(`${title}: Initialization complete`);
|
|
77
|
-
console.log(`${title}: Hint: npm run doc 生成使用文档`);
|
|
78
|
-
console.log(`${title}: Hint: npm run example 开发环境,运行样例`);
|
|
79
|
-
console.log(`${title}: Hint: npm run build:typescript 打包 npm 包`);
|
|
80
|
-
console.log(`${title}: Hint: npm run build:bundle 打包 bundle 包`);
|
|
81
|
-
console.log(`${title}: Hint: npm run build:all 生成使用文档并打包所有包`);
|
|
82
|
-
console.log(`${title}: Have a good day (^_^)v`);
|
|
83
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# Five React 组件: a-five-react-component
|
|
2
|
-
|
|
3
|
-
> 这是一个 Five 的组件。
|
|
4
|
-
> 这个插件的用途是什么。
|
|
5
|
-
> 能干什么。为什么要使用这组件。
|
|
6
|
-
|
|
7
|
-
## 参数 / 返回
|
|
8
|
-
|
|
9
|
-
参数:
|
|
10
|
-
```typescript
|
|
11
|
-
type ParameterType = {
|
|
12
|
-
parameter1: number,
|
|
13
|
-
parameter2: string,
|
|
14
|
-
};
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
返回:
|
|
18
|
-
```typescript
|
|
19
|
-
type ExportType = void;
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
## 如何使用
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
import { Five } from "@realse/five";
|
|
27
|
-
import { AFivePlugin, FivePluginInit } from "a-five-plugin";
|
|
28
|
-
|
|
29
|
-
const five = new Five({
|
|
30
|
-
plugins: [
|
|
31
|
-
[AFivePlugin, null, {
|
|
32
|
-
parameter1: 123,
|
|
33
|
-
parameter2: "abc",
|
|
34
|
-
parameter3: [new THREE.Vector3(1, 2, 3)],
|
|
35
|
-
}] as FivePluginInit<typeof AFivePlugin>,
|
|
36
|
-
]
|
|
37
|
-
});
|
|
38
|
-
```
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": [
|
|
3
|
-
"../lib/**/*.ts"
|
|
4
|
-
],
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"target": "ES5",
|
|
7
|
-
"module": "CommonJS",
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"allowSyntheticDefaultImports": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"moduleResolution": "node",
|
|
12
|
-
"sourceMap": true,
|
|
13
|
-
"allowJs": true,
|
|
14
|
-
"rootDir": "../lib",
|
|
15
|
-
"outDir": "../build",
|
|
16
|
-
"skipLibCheck": true
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const path = require("path");
|
|
2
|
-
const { NormalModuleReplacementPlugin } = require("webpack");
|
|
3
|
-
|
|
4
|
-
const name = require("../package.json").name.split("/").pop();
|
|
5
|
-
const libraryName = name.replace(/(^|\-)\w/g, char => char[char.length - 1].toUpperCase());
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
context: path.join(__dirname, "lib"),
|
|
9
|
-
entry: {
|
|
10
|
-
[name]: path.join(__dirname, '../lib/index.ts'),
|
|
11
|
-
},
|
|
12
|
-
output: {
|
|
13
|
-
path: path.join(__dirname, "../bundles"),
|
|
14
|
-
filename: "[name].js",
|
|
15
|
-
library: libraryName,
|
|
16
|
-
libraryTarget: "umd",
|
|
17
|
-
libraryExport: libraryName
|
|
18
|
-
},
|
|
19
|
-
mode: "production",
|
|
20
|
-
devtool: "source-map",
|
|
21
|
-
module: {
|
|
22
|
-
rules: [{
|
|
23
|
-
test: /\.ts$/i,
|
|
24
|
-
exclude: /node_modules/,
|
|
25
|
-
use: [{
|
|
26
|
-
loader: "ts-loader",
|
|
27
|
-
options: {
|
|
28
|
-
configFile: path.join(__dirname, "tsconfig.build.json"),
|
|
29
|
-
compilerOptions: {
|
|
30
|
-
"declaration": false,
|
|
31
|
-
"sourceMap": true,
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
}]
|
|
35
|
-
}],
|
|
36
|
-
},
|
|
37
|
-
plugins: [
|
|
38
|
-
new NormalModuleReplacementPlugin(/^three$/, path.join(__dirname, 'external-three.js')),
|
|
39
|
-
new NormalModuleReplacementPlugin(/^\@realsee\/five$/, path.join(__dirname, 'external-five.js')),
|
|
40
|
-
],
|
|
41
|
-
resolve: {
|
|
42
|
-
extensions: [".js", ".jsx", ".ts", ".json"],
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const path = require("path");
|
|
2
|
-
const glob = require("fast-glob");
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
context: path.join(__dirname, "../examples"),
|
|
6
|
-
entry: () => {
|
|
7
|
-
const list = glob.sync("**/index.ts", { cwd: path.join(__dirname, "../examples") });
|
|
8
|
-
const entry = {}
|
|
9
|
-
list.map(filename => {
|
|
10
|
-
const name = filename.replace(/\.ts$/i, '');
|
|
11
|
-
entry[name] = './' + filename;
|
|
12
|
-
})
|
|
13
|
-
return entry;
|
|
14
|
-
},
|
|
15
|
-
output: {
|
|
16
|
-
path: path.join(__dirname, "../examples"),
|
|
17
|
-
filename: "[name].bundle.js"
|
|
18
|
-
},
|
|
19
|
-
mode: "development",
|
|
20
|
-
devtool: "eval-cheap-source-map",
|
|
21
|
-
module: {
|
|
22
|
-
rules: [{
|
|
23
|
-
test: /\.ts$/i,
|
|
24
|
-
exclude: /node_modules/,
|
|
25
|
-
use: [{
|
|
26
|
-
loader: "ts-loader",
|
|
27
|
-
options: {
|
|
28
|
-
compilerOptions: {
|
|
29
|
-
"declaration": false,
|
|
30
|
-
"sourceMap": true,
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
}]
|
|
34
|
-
}]
|
|
35
|
-
},
|
|
36
|
-
resolve: {
|
|
37
|
-
extensions: [".js", ".jsx", ".ts", ".json"],
|
|
38
|
-
}
|
|
39
|
-
};
|
|
File without changes
|