forked from cocos/cocos-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support bundle-adapter workflow (cocos#11337)
* update require * support bundle-adapter workflow update * update adapter require * add timer * update * update lock update lock * remove node version for npm test CI * with node version 16.15 * install jsdom * use 16.15
- Loading branch information
Showing
31 changed files
with
38,521 additions
and
12,362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require('../fs-utils'); | ||
require('../../../../common/engine/index'); | ||
require('./Label'); | ||
require('./Console'); | ||
require('./AudioPlayer'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
require('../fs-utils'); | ||
require('../../../../common/engine/index'); | ||
require('./sprite-frame'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
platforms/minigame/platforms/bytedance/wrapper/engine/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
require('../fs-utils'); | ||
require('../../../../common/engine/index'); | ||
require('./Label'); | ||
require('./ImageAsset'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
require('../fs-utils'); | ||
require('../../../../common/engine/index'); | ||
require('./VideoPlayer'); | ||
require('./sprite-frame'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
require('../fs-utils'); | ||
require('../../../../common/engine/index'); | ||
require('./download-ttf'); | ||
require('./Editbox'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
const ps = require('path'); | ||
const fs = require('fs'); | ||
const gulp = require('gulp'); | ||
const babelify = require("babelify"); | ||
const browserify = require('browserify'); | ||
const source = require("vinyl-source-stream"); | ||
const buffer = require('vinyl-buffer'); | ||
const chalk = require('chalk').default; | ||
const uglify = require('gulp-uglify'); | ||
const rename = require('gulp-rename'); | ||
|
||
const engineRoot = ps.join(__dirname, '..'); | ||
|
||
(async function bundleAdapter () { | ||
try { | ||
console.time('Bundle Adapter'); | ||
await bundleJsbAdapter(); | ||
await bundleMinigameAdapter(); | ||
await bundleRuntimeAdapter(); | ||
console.timeEnd('Bundle Adapter'); | ||
process.exit(0); | ||
} catch (e) { | ||
console.error(e); | ||
process.exit(1); | ||
} | ||
})(); | ||
|
||
async function bundleJsbAdapter () { | ||
console.log(chalk.green('\nBundling jsb adapter')); | ||
// bundle jsb-engine.js | ||
const jsbEngineEntry = normalizePath(ps.join(engineRoot, 'platforms/native/engine/index.js')); | ||
const jsbEngineOutput = normalizePath(ps.join(engineRoot, 'bin/adapter/native/jsb-engine.js')); | ||
await bundle(jsbEngineEntry, jsbEngineOutput); | ||
|
||
// bundle jsb-engine.js | ||
const jsbBuiltinEntry = normalizePath(ps.join(engineRoot, 'platforms/native/builtin/index.js')); | ||
const jsbBuiltinOutput = normalizePath(ps.join(engineRoot, 'bin/adapter/native/jsb-builtin.js')); | ||
await bundle(jsbBuiltinEntry, jsbBuiltinOutput); | ||
} | ||
|
||
async function bundleMinigameAdapter () { | ||
const platformsPath = ps.join(engineRoot, 'platforms/minigame/platforms'); | ||
const platforms = fs.readdirSync(platformsPath); | ||
console.log(chalk.green(`\nBundling minigame platform adapters, including: ${platforms}`)); | ||
|
||
for (let platform of platforms) { | ||
console.log(`handle platform: ${chalk.green(platform)}`); | ||
// bundle engine-adapter.js | ||
const engineEntry = normalizePath(ps.join(engineRoot, `platforms/minigame/platforms/${platform}/wrapper/engine/index.js`)); | ||
const engineOutput = normalizePath(ps.join(engineRoot, `bin/adapter/minigame/${platform}/engine-adapter.js`)); | ||
await bundle(engineEntry, engineOutput); | ||
|
||
// bundle builtin.js | ||
let builtinEntry = normalizePath(ps.join(engineRoot, `platforms/minigame/platforms/${platform}/wrapper/builtin/index.js`)); | ||
if (platform === 'alipay' || platform === 'xiaomi') { | ||
builtinEntry = normalizePath(ps.join(engineRoot, `platforms/minigame/platforms/${platform}/wrapper/builtin.js`)); | ||
} | ||
const builtinOutput = normalizePath(ps.join(engineRoot, `bin/adapter/minigame/${platform}/builtin.js`)); | ||
await bundle(builtinEntry, builtinOutput); | ||
} | ||
} | ||
|
||
async function bundleRuntimeAdapter () { | ||
const platformsPath = ps.join(engineRoot, 'platforms/runtime/platforms'); | ||
const platforms = fs.readdirSync(platformsPath); | ||
console.log(chalk.green(`\nBundling runtime platform adapters, including: ${platforms}`)); | ||
for (let platform of platforms) { | ||
console.log(`handle platform: ${chalk.green(platform)}`); | ||
// bundle engine-adapter.js | ||
const engineEntry = normalizePath(ps.join(engineRoot, `platforms/runtime/platforms/${platform}/engine/index.js`)); | ||
const engineOutput = normalizePath(ps.join(engineRoot, `bin/adapter/runtime/${platform}/engine-adapter.js`)); | ||
await bundle(engineEntry, engineOutput); | ||
} | ||
} | ||
|
||
|
||
function normalizePath (path) { | ||
return path.replace(/\\/g, '/'); | ||
} | ||
|
||
/** | ||
* Traverse and compare the modification time of source code and target file | ||
* @param {string} dir | ||
* @param {string} targetFileMtime | ||
*/ | ||
function checkFileStat (dir, targetFileMtime) { | ||
let files = fs.readdirSync(dir); | ||
return files.some (file => { | ||
let filePath = ps.join(dir, file); | ||
let stat = fs.statSync(filePath); | ||
if (stat.isDirectory()) { | ||
return checkFileStat(filePath, targetFileMtime); | ||
} | ||
else if (stat.mtime.getTime() > targetFileMtime) { | ||
return true; | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Check whether the source code is updated | ||
* @param {string} src | ||
* @param {string} dst | ||
*/ | ||
function hasChanged (src, dst) { | ||
if (!fs.existsSync(dst)) { | ||
return true; | ||
} | ||
let stat = fs.statSync(dst); | ||
let dir = ps.dirname(src); | ||
return checkFileStat(dir, stat.mtime.getTime()); | ||
} | ||
|
||
/** | ||
* Create bundle task | ||
* @param {string} src | ||
* @param {string} dst | ||
* @param {boolean} uglify | ||
*/ | ||
function createBundleTask (src, dst) { | ||
let targetFileName = ps.basename(dst); | ||
let targetFileNameMin = ps.basename(targetFileName, '.js') + '.min.js'; | ||
dst = ps.dirname(dst); | ||
let bundler = browserify(src); | ||
return bundler.transform(babelify, {presets: [require('@babel/preset-env')], | ||
plugins: [ | ||
require('@babel/plugin-proposal-class-properties'), | ||
require('@babel/plugin-proposal-export-default-from') | ||
]}) | ||
.bundle() | ||
.pipe(source(targetFileName)) | ||
.pipe(buffer()) | ||
.pipe(gulp.dest(dst)) | ||
.pipe(rename(targetFileNameMin)).pipe(uglify()).pipe(gulp.dest(dst)); | ||
} | ||
|
||
/** | ||
* Build adapters | ||
* @param {string} entry | ||
* @param {string} output | ||
*/ | ||
async function bundle (entry, output) { | ||
await new Promise((resolve) => { | ||
console.log(`Generate bundle: ${chalk.green(ps.basename(output))}`); | ||
// if (!hasChanged(entry, output)) { | ||
// console.log(chalk.yellow('Use bundle cache, skip bundling')); | ||
// resolve(); | ||
// return; | ||
// } | ||
createBundleTask(entry, output).on('end', resolve); | ||
}); | ||
} |
Oops, something went wrong.