浏览代码

Fix build-examples script on windows (#21591)

* Fix build-examples script on windows

* Fix LGTM warning
Marco Fugaro 4 年之前
父节点
当前提交
3bc0f1a639
共有 1 个文件被更改,包括 16 次插入13 次删除
  1. 16 13
      utils/build/rollup.examples.config.js

+ 16 - 13
utils/build/rollup.examples.config.js

@@ -1,8 +1,11 @@
 import babel from '@rollup/plugin-babel';
 import path from 'path';
+import os from 'os';
 import glob from 'glob';
 import babelrc from './.babelrc.json';
 
+const EOL = os.EOL;
+
 function babelCleanup() {
 
 	const doubleSpaces = / {2}/g;
@@ -21,7 +24,7 @@ function babelCleanup() {
 			//    {
 			//             ↓
 			// 	  setSize: function () {
-			code = code.replace( /\(\)\n\s*\/\*([a-zA-Z0-9_, ]+)\*\/\n\s*{/g, '( ) {' );
+			code = code.replace( new RegExp( `\\(\\)${EOL}\\s*\\/\\*([a-zA-Z0-9_, ]+)\\*\\/${EOL}\\s*{`, 'g' ), '( ) {' );
 
 
 			return {
@@ -52,14 +55,14 @@ function unmodularize() {
 			code = code.replace( /export { ([a-zA-Z0-9_, ]+) };/g, ( match, p1 ) => {
 
 				const exps = p1.split( ', ' );
-				return exps.map( exp => `THREE.${exp} = ${exp};` ).join( '\n' );
+				return exps.map( exp => `THREE.${exp} = ${exp};` ).join( EOL );
 
 			} );
 
 			// import { Example } from '...';
 			// but excluding imports importing from the libs/ folder
 			const imports = [];
-			code = code.replace( /import { ([a-zA-Z0-9_, ]+) } from '((?!libs).)*';\n/g, ( match, p1 ) => {
+			code = code.replace( /import { ([a-zA-Z0-9_, ]+) } from '((?!libs).)*';/g, ( match, p1 ) => {
 
 				const imps = p1.split( ', ' );
 				imps.reverse();
@@ -100,30 +103,30 @@ function unmodularize() {
 			// fix for BasisTextureLoader.js
 			imports.forEach( imp => {
 
-				code = code.replace( new RegExp( `\n(\\s)THREE\.${imp}:`, 'g' ), ( match, p1 ) => {
+				code = code.replace( new RegExp( `${EOL}(\\s)THREE\\.${imp}:`, 'g' ), ( match, p1 ) => {
 
-					return `\n${p1}${imp}:`;
+					return `${EOL}${p1}${imp}:`;
 
 				} );
 
 			} );
 
 			// import * as THREE from '...';
-			code = code.replace( /import \* as THREE from '(.*)';\n/g, '' );
+			code = code.replace( /import \* as THREE from '(.*)';/g, '' );
 
 			// Remove library imports that are exposed as
 			// global variables in the non-module world
-			code = code.replace( 'import * as fflate from \'../libs/fflate.module.min.js\';\n', '' );
-			code = code.replace( 'import { MMDParser } from \'../libs/mmdparser.module.js\';\n', '' );
-			code = code.replace( 'import { potpack } from \'../libs/potpack.module.js\';\n', '' );
-			code = code.replace( 'import { opentype } from \'../libs/opentype.module.min.js\';\n', '' );
-			code = code.replace( 'import { chevrotain } from \'../libs/chevrotain.module.min.js\';\n', '' );
-			code = code.replace( 'import { ZSTDDecoder } from \'../libs/zstddec.module.js\';\n', '' );
+			code = code.replace( 'import * as fflate from \'../libs/fflate.module.min.js\';', '' );
+			code = code.replace( 'import { MMDParser } from \'../libs/mmdparser.module.js\';', '' );
+			code = code.replace( 'import { potpack } from \'../libs/potpack.module.js\';', '' );
+			code = code.replace( 'import { opentype } from \'../libs/opentype.module.min.js\';', '' );
+			code = code.replace( 'import { chevrotain } from \'../libs/chevrotain.module.min.js\';', '' );
+			code = code.replace( 'import { ZSTDDecoder } from \'../libs/zstddec.module.js\';', '' );
 
 			// remove newline at the start of file
 			code = code.trimStart();
 
-			code = `( function () {\n${code}\n} )();`;
+			code = `( function () {${EOL}${code}${EOL}} )();`;
 
 			return {
 				code: code,