function _build ( packageObj, force, cb ) { if ( !packageObj.build ) { if ( cb ) { cb ( null, packageObj._path ); } return; } if ( !force ) { // check if bin/dev exists let binPath = Path.join( packageObj._path, 'bin/dev' ); if ( Fs.existsSync(binPath) ) { let packageJsonPath = Path.join( binPath, 'package.json'); if ( Fs.existsSync(packageJsonPath) ) { // check if bin/dev/package.json have the same version let binPackageObj = JSON.parse(Fs.readFileSync(packageJsonPath)); if ( packageObj.version === binPackageObj.version ) { if ( cb ) { cb ( null, binPath ); } return; } } } } Console.log( 'Building ' + packageObj.name ); Package.build( packageObj._path, cb ); }
module.exports = function (path, opts, cb) { let tap = require('../share/tap'); tap.init(opts.reporter); tap.on('end', () => { cb(tap._fail); }); global.tap = tap; global.helper = require('../share/helper'); global.suite = tap.suite; // glob files let files = []; if ( Fs.isDirSync(path) ) { files = Globby.sync([ Path.join(path,'**/*.js'), '!'+Path.join(path,'**/*.skip.js'), '!**/fixtures/**', ]); } else { files = [path]; } files.forEach(file => { let fullpath = Path.resolve(file); try { require(fullpath); } catch (err) { _logError(`Failed to load spec: ${file}`); } }); tap.end(); };
protocol.registerBufferProtocol('thumbnail', (request, cb) => { let url = decodeURIComponent(request.url); let uri = Url.parse(url); let relativePath = uri.hostname; if ( uri.pathname ) { relativePath = Path.join( relativePath, uri.pathname ); } let file = Path.join( Editor.App.path, relativePath ); if ( !Fs.existsSync(file) ) { cb(-6); // FILE NOT FOUND return; } let size = parseInt(uri.query) || 32; Sharp(file) .resize(size,size) // .background({r: 0, g: 0, b: 0, a: 0}) .background({r: 0, g: 0, b: 0, a: 255}) .embed() .toFormat(Sharp.format.png) .toBuffer() .then(buffer => { cb({ mimeType: 'image/png', data: buffer, }); }) ; }, err => {
Project.getInfo( projectPath, function ( info ) { if ( !info ) { if ( cb ) cb ( new Error('Can not find project.json') ); return; } if ( info.error ) { if ( cb ) cb ( new Error(info.error) ); return; } // validate folders and create them if not exists var path = Path.join(projectPath,'settings'); if ( !Fs.existsSync(path) ) Fs.mkdirSync(path); path = Path.join(projectPath,'local'); if ( !Fs.existsSync(path) ) Fs.mkdirSync(path); path = Path.join(projectPath,'packages'); if ( !Fs.existsSync(path) ) Fs.mkdirSync(path); path = Path.join(projectPath,'assets'); if ( !Fs.existsSync(path) ) Fs.mkdirSync(path); path = Path.join(projectPath,'library'); if ( !Fs.existsSync(path) ) Fs.mkdirSync(path); if ( cb ) cb ( null, info ); });
.on('change', path => { // NOTE: this is not 100% safe, because 50ms debounce still can have multiple // same packages building together, to avoid this, try to use Async.queue let packageInfo = Editor.Package.packageInfo(path); if ( !packageInfo ) { return; } // let reloadInfo; _packageReloadInfo.some(info => { if ( info.path === packageInfo._path ) { reloadInfo = info; return true; } return false; }); if ( !reloadInfo ) { reloadInfo = { path: packageInfo._path, reloadTest: false, reloadPage: false, reloadCore: false, }; _packageReloadInfo.push(reloadInfo); } // reload test if ( Path.contains(Path.join(packageInfo._path, 'test') , path) ) { reloadInfo.reloadTest = true; } // reload page else if ( Path.contains(Path.join(packageInfo._path, 'page') , path) || Path.contains(Path.join(packageInfo._path, 'panel') , path) || Path.contains(Path.join(packageInfo._path, 'widget') , path) || Path.contains(Path.join(packageInfo._path, 'element') , path) ) { reloadInfo.reloadPage = true; } // reload core else { reloadInfo.reloadCore = true; } // debounce write for 50ms if ( _watchDebounceID ) { clearTimeout(_watchDebounceID); _watchDebounceID = null; } _watchDebounceID = setTimeout(() => { _reloadPackages(_packageReloadInfo); _packageReloadInfo = []; _watchDebounceID = null; }, 50); })
module.exports = function (path, opts, cb) { let files = []; if ( Fs.isDirSync(path) ) { files = Globby.sync([ Path.join(path,'**/*.js'), '!'+Path.join(path,'**/*.skip.js'), '!**/fixtures/**', ]); } else { files = [path]; } let win = new Editor.Window('__test__', { 'title': 'Testing Renderer...', 'width': 400, 'height': 300, 'show': false, 'resizable': true, }); Editor.Window.main = win; const ipcMain = Electron.ipcMain; ipcMain.on('stdout:write', (event, ...args) => { process.stdout.write.apply(process.stdout, args); }); ipcMain.on('tap:error', (event, message) => { _logError(message); }); ipcMain.on('tap:end', (event, failures) => { if ( opts.detail ) { // open devtools if there has failed tests if ( failures ) { win.openDevTools(); } return; } win.close(); if ( cb ) { cb ( failures ); } }); // load and show main window win.show(); // page-level test case win.load('editor-framework://lib/tester/renderer/index.html', { files: files, detail: opts.detail, reporter: opts.reporter, }); };
Protocol.registerProtocol('editor-framework', function(request) { var url = decodeURIComponent(request.url); var data = Url.parse(url); var relativePath = data.hostname; if ( data.pathname ) { relativePath = Path.join( relativePath, data.pathname ); } var file = Path.join( Editor.frameworkPath, relativePath ); return new Protocol.RequestFileJob(file); });
assetdb.init(function ( err ) { var meta = Meta.load( assetdb, Path.join(dest,'a-folder.meta') ); expect(meta).to.be.instanceof(Meta.FolderMeta); expect( Fs.existsSync(assetdb._uuid2importPath(meta.uuid)) ).to.be.equal(false); meta = Meta.load( assetdb, Path.join(dest,'an-asset.atlas.meta') ); expect(meta).to.be.instanceof(Meta.AssetMeta); expect( Fs.existsSync(assetdb._uuid2importPath(meta.uuid)) ).to.be.equal(true); done(); });
platformChanged: function () { var profile = this.profiles.project; var projectPath = Remote.getGlobal('Editor').projectPath; if ( profile.platform === "web-mobile" ) { profile.buildPath = Path.join(projectPath, "/mobile-" + profile.projectName); } else { profile.buildPath = Path.join(projectPath, "/desktop-" + profile.projectName); } profile.save(); },
describe('init-with-meta', function () { var src = Path.join( __dirname, 'fixtures/init-with-meta' ); var dest = Path.join( __dirname, 'playground/init-with-meta' ); var mtimeList = {}; beforeEach(function ( done ) { assetdb = new AssetDB({ cwd: Path.join( __dirname, 'playground' ), library: 'library', }); Fs.copySync( src, dest ); assetdb.mount( dest, 'assets', function ( err ) { done (); }); mtimeList = { 'a-folder.meta': Fs.statSync( Path.join(dest,'a-folder.meta') ).mtime, 'a-folder/an-asset.asset.meta': Fs.statSync( Path.join(dest,'a-folder/an-asset.asset.meta') ).mtime, 'an-asset.atlas.meta': Fs.statSync( Path.join(dest,'an-asset.atlas.meta') ).mtime, 'an-folder-asset.atlas.meta': Fs.statSync( Path.join(dest,'an-folder-asset.atlas.meta') ).mtime, 'an-folder-asset.atlas/asset-in-folder-asset.png.meta': Fs.statSync( Path.join(dest,'an-folder-asset.atlas/asset-in-folder-asset.png.meta') ).mtime, }; }); afterEach( function ( done ) { Del( Path.join( __dirname, 'playground' ), done ); }); it('should create library file after init', function ( done ) { assetdb.init(function ( err ) { var meta = Meta.load( assetdb, Path.join(dest,'a-folder.meta') ); expect(meta).to.be.instanceof(Meta.FolderMeta); expect( Fs.existsSync(assetdb._uuid2importPath(meta.uuid)) ).to.be.equal(false); meta = Meta.load( assetdb, Path.join(dest,'an-asset.atlas.meta') ); expect(meta).to.be.instanceof(Meta.AssetMeta); expect( Fs.existsSync(assetdb._uuid2importPath(meta.uuid)) ).to.be.equal(true); done(); }); }); it('should not touch the original meta', function ( done ) { assetdb.init(function ( err ) { for ( var p in mtimeList ) { expect( Fs.statSync(Path.join(dest,p)).mtime.getTime() ).to.be.equal( mtimeList[p].getTime() ); } done(); }); }); });
function _getUserDoc() { if (process.env.USERPROFILE) { var win8 = Path.join(process.env.USERPROFILE, 'Documents'); if (Fs.existsSync(win8)) { return win8; } var win7 = Path.join(process.env.USERPROFILE, 'My Documents'); if (Fs.existsSync(win7)) { return win7; } } return process.cwd(); }
describe('init-with-meta-and-lib', function () { var src = Path.join( __dirname, 'fixtures/init-with-meta-and-lib/' ); var destPlayground = Path.join( __dirname, 'playground/init-with-meta-and-lib/' ); var dest = Path.join( __dirname, 'playground/init-with-meta-and-lib/assets' ); var mtimeList = {}; beforeEach(function ( done ) { Fs.copySync( src, destPlayground ); assetdb = new AssetDB({ cwd: Path.join( __dirname, 'playground' ), library: 'init-with-meta-and-lib/library', }); assetdb.mount( dest, 'assets', function ( err ) { done (); }); mtimeList = { 'a-folder.meta': Fs.statSync( Path.join(dest,'a-folder.meta') ).mtime, 'a-folder/an-asset.asset.meta': Fs.statSync( Path.join(dest,'a-folder/an-asset.asset.meta') ).mtime, 'an-asset.atlas.meta': Fs.statSync( Path.join(dest,'an-asset.atlas.meta') ).mtime, 'an-folder-asset.atlas.meta': Fs.statSync( Path.join(dest,'an-folder-asset.atlas.meta') ).mtime, 'an-folder-asset.atlas/asset-in-folder-asset.png.meta': Fs.statSync( Path.join(dest,'an-folder-asset.atlas/asset-in-folder-asset.png.meta') ).mtime, }; }); afterEach( function ( done ) { Del( Path.join( __dirname, 'playground' ), done ); }); it('should not touch the original meta', function ( done ) { assetdb.init(function ( err ) { for ( var p in mtimeList ) { expect( Fs.statSync(Path.join(dest,p)).mtime.getTime() ).to.be.equal( mtimeList[p].getTime() ); } done(); }); }); it('should remove unused import files', function ( done ) { assetdb.init(function ( err ) { var deadbeaf = Path.join(assetdb._importPath, 'de/deadbeaf-dead-beaf-dead-beafdeadbeaf' ); expect( Fs.existsSync(deadbeaf) ).to.be.equal(false); done(); }); }); });
'editor:build-finished': function (event, target) { var root = Path.normalize(target.dest); var url = Path.join(root, "jsb-" + target.template, "main.js"); Fs.readFile(url, "utf8", function (err, data) { if (err) { throw err; } var newStr = "(function () { \n"+ "\n"+ " if (cc.sys.isNative) { \n" + " var hotUpdateSearchPaths = cc.sys.localStorage.getItem('HotUpdateSearchPaths'); \n" + " if (hotUpdateSearchPaths) { \n" + " jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths)); \n" + " }\n" + " }"; var newData = data.replace("(function () {", newStr); Fs.writeFile(url, newData, function (error) { if (err) { throw err; } Editor.log("SearchPath updated in built main.js for hot update"); }); }); }
function _packages2path ( urlInfo ) { var packagePath = Editor.Package.packagePath(urlInfo.hostname); if ( packagePath ) { return Path.join( packagePath, urlInfo.pathname ); } return ''; }
assetdb.init(function ( err ) { for ( var p in mtimeList ) { expect( Fs.statSync(Path.join(dest,p)).mtime.getTime() ).to.be.equal( mtimeList[p].getTime() ); } done(); });
it('should report error when mount path is a file', function ( done ) { assetdb.mount( Path.join( __dirname, 'basic.js'), 'foo', function ( err ) { console.log(err); expect(err).to.be.instanceof(Error); done(); }); });
it('should report error when mount target have `/`, `\\` or `.`', function ( done ) { assetdb.mount( Path.join( __dirname, 'fixtures/simple-assets-01' ), 'foo/bar', function ( err ) { console.log(err); expect(err).to.be.instanceof(Error); done(); }); });
app.get('/', function (req, res) { var runtimePkg = require(Path.join(Editor.runtimePath, 'package.json')); res.render('index', { title: 'Fireball | ' + Editor.projectInfo.name, runtimeScripts: runtimePkg.build.scriptsDev, }); });
it('should report error when mount to foo again', function ( done ) { assetdb.mount( Path.join( __dirname, 'fixtures/simple-assets-02' ), 'foo', function ( err ) { console.log(err); expect(err).to.be.instanceof(Error); done(); }); });
// function ( next ) { assetdb.mount( Path.join( __dirname, 'fixtures/simple-assets-01/' ), 'bar', function ( err ) { console.log(err); expect(err).to.be.instanceof(Error); next(); }); },
Getmac.getMac( function ( err, macAddress) { if ( err ) { reply({ 'account': lastLoginAccount, 'remember-passwd': rememberPasswd, 'password': '', }); return; } var infoFile = Path.join(Editor.dataPath,'.info'); if ( Fs.existsSync(infoFile) ) { var info = JSON.parse(Fs.readFileSync(infoFile)); var crypted = info[lastLoginAccount]; var passwd = ''; if ( crypted ) { var decipher = Crypto.createDecipher('aes-256-cbc', macAddress); decipher.update( crypted, 'hex', 'utf8' ); passwd = decipher.final('utf8'); } reply({ 'account': lastLoginAccount, 'remember-passwd': rememberPasswd, 'password': passwd, 'login-type': loginType, }); } });
describe('fixtures/packages/simple ipc-message', function () { const path = Path.join(testPackages,'simple'); assert.isTrue( Fs.existsSync(path) ); beforeEach(function () { Helper.reset(); }); it('should send loaded ipc message', function (done) { Editor.Package.load(path, function () { assert( Helper.sendToWindows.calledWith('package:loaded', 'simple') ); done(); }); }); it('should send unload message', function (done) { Async.series([ next => { Editor.Package.load(path, next); }, next => { Editor.Package.unload(path, next); }, ], function () { assert( Helper.sendToWindows.calledWith('package:unloaded', 'simple') ); done(); }); }); });
describe('fixtures/packages/localize', function () { const path = Path.join(testPackages,'localize'); it('should load and unload en i18n file', function (done) { Editor.lang = 'en'; Editor.Package.load(path, () => { expect(Editor.T('localize.search')).to.equal('Search'); expect(Editor.T('localize.edit')).to.equal('Edit'); Editor.Package.unload(path, () => { expect(Editor.i18n._phrases().localize).to.eql(undefined); done(); }); }); }); it('should load zh i18n file', function (done) { Editor.lang = 'zh'; Editor.Package.load(path, () => { expect(Editor.T('localize.search')).to.equal('搜索'); expect(Editor.T('localize.edit')).to.equal('编辑'); Editor.Package.unload(path, done); }); }); });
it('should report error when you mount a path that its children already used', function ( done ) { assetdb.mount( Path.join( __dirname, 'fixtures' ), 'bar', function ( err ) { console.log(err); expect(err).to.be.instanceof(Error); done(); }); });
Editor.reset = function () { // reset i18n method Editor.i18n.clear(); Editor.i18n.extend(require(`../../static/i18n/${Editor.lang}.js`)); // reset profile path Editor._type2profilepath = {}; Editor.registerProfilePath( 'global', Editor.App.home ); Editor.registerProfilePath( 'local', Path.join( Editor.App.home, 'local' ) ); // reset package search path Editor.Package.resetPath(); Editor.Package.addPath( Editor.url('app://builtin') ); // reset main menu Editor.MainMenu._revert(); // reset panel window Editor.Panel.templateUrl = 'editor-framework://static/window.html'; // reset layout Editor.registerDefaultLayout( Editor.url('app://static/layout.json') ); // reset selection Editor.Selection.reset(); // reset undo Editor.Undo.reset(); };
before(function ( done ) { assetdb = new AssetDB({ cwd: Path.join( __dirname, 'playground' ), library: 'library', }); done(); });
EditorM.reset = function () { // reset i18n method i18n.clear(); i18n.extend(require(`../../static/i18n/${EditorM.lang}.js`)); // reset profile path Profile.reset(); Profile.register( 'global', App.home ); Profile.register( 'local', Path.join( App.home, 'local' ) ); // reset package search path Package.resetPath(); // reset main menu to builtin MainMenu._resetToBuiltin(); // reset panel window Panel.templateUrl = 'editor-framework://static/window.html'; // reset layout EditorM.registerDefaultLayout( EditorM.url('app://static/layout.json') ); // reset selection Selection.reset(); // reset undo Undo.reset(); };
next => { var index; for (var name in cache) { index = loadCacheList.indexOf(cache[name].filename); loadCacheList.splice(index, 1); } // main.js | core/test.js expect(loadCacheList).to.eql([ Path.join(path, 'main.js'), Path.join(path, 'core/test.js'), Path.join(path, 'core/foo/bar.js'), Path.join(path, 'test.js'), ]); next(); },
Async.eachSeries( files, (name, done) => { let packagePath = Path.join(path,name); if ( !Fs.isDirSync(packagePath) ) { done(); return; } Builder.buildPackage(packagePath, done); }, err => {
FindUp('package.json', {cwd: path}).then(file => { if ( !file ) { _logError(`Can not find package.json in ${file}`); return; } // load package let packagePath = Path.dirname(file); if ( !Path.isAbsolute(packagePath) ) { packagePath = Path.join(Editor.App.path,packagePath); } Editor.Package.load(packagePath, {build: true}, () => { // if the path is not a specific test, run all tests in the package let runAllTest = true; if ( path.indexOf('test') !== -1 ) { runAllTest = false; } // if ( runAllTest ) { const Async = require('async'); let totalFailures = 0; let testPath = Path.join(packagePath,'test'); Async.series([ next => { Tester.runRenderer(Path.join(testPath,'renderer'), opts, failures => { totalFailures += failures; next (); }); }, next => { Tester.runMain(Path.join(testPath,'main'), opts, failures => { totalFailures += failures; next (); }); }, ], () => { if ( cb ) { cb (totalFailures); } }); return; } // run test in renderer process if ( opts.renderer || path.indexOf('renderer') !== -1 ) { Tester.runRenderer(path,opts,cb); return; } // run test in main process Tester.runMain(path,opts,cb); }); });