/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/cordova-browser@7.0.0/bin/template/cordova/Api.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
const shell=require("shelljs"),path=require("path"),fs=require("fs"),cdvcmn=require("cordova-common"),CordovaLogger=cdvcmn.CordovaLogger,ConfigParser=cdvcmn.ConfigParser,ActionStack=cdvcmn.ActionStack,selfEvents=cdvcmn.events,xmlHelpers=cdvcmn.xmlHelpers,PlatformJson=cdvcmn.PlatformJson,PlatformMunger=cdvcmn.ConfigChanges.PlatformMunger,PluginInfoProvider=cdvcmn.PluginInfoProvider,BrowserParser=require("./browser_parser"),PLATFORM_NAME="browser";function setupEvents(t){return t?(selfEvents.forwardEventsTo(t),t):(CordovaLogger.get().subscribe(selfEvents),selfEvents)}function Api(t,o,e){this.platform=t||"browser",this.root=path.resolve(__dirname,".."),this.events=setupEvents(e),this.parser=new BrowserParser(this.root),this._handler=require("./browser_handler"),this.locations={platformRootDir:o,root:this.root,www:path.join(this.root,"www"),res:path.join(this.root,"res"),platformWww:path.join(this.root,"platform_www"),configXml:path.join(this.root,"config.xml"),defaultConfigXml:path.join(this.root,"cordova/defaults.xml"),build:path.join(this.root,"build"),cordovaJs:"bin/templates/project/assets/www/cordova.js",cordovaJsSrc:"cordova-js-src"},this._platformJson=PlatformJson.load(this.root,t),this._pluginInfoProvider=new PluginInfoProvider,this._munger=new PlatformMunger(t,this.root,this._platformJson,this._pluginInfoProvider)}Api.createPlatform=function(t,o,e,r){const n=require("../../lib/create");r=setupEvents(r);let i,s="HelloCordova",a="io.cordova.hellocordova";o&&(s=o.name(),a=o.packageName());try{i=n.createProject(t,a,s,e).then((function(){return new(require(path.resolve(t,"cordova/Api")))("browser",t,r)}))}catch(t){throw r.emit("error","createPlatform is not callable from the browser project API."),t}return i},Api.updatePlatform=function(t,o,e){return Promise.resolve()},Api.prototype.getPlatformInfo=function(){return{locations:this.locations,root:this.root,name:this.platform,version:{version:"1.0.0"},projectConfig:this.config}},Api.prototype.prepare=function(t,o){const e=path.join(this.locations.platformRootDir,"cordova","defaults.xml"),r=this.locations.configXml,n=t.projectConfig;fs.existsSync(e)?(this.events.emit("verbose",'Generating config.xml from defaults for platform "'+this.platform+'"'),shell.cp("-f",e,r)):fs.existsSync(r)?(this.events.emit("verbose",'Generating defaults.xml from own config.xml for platform "'+this.platform+'"'),shell.cp("-f",r,e)):(this.events.emit("verbose",'case 3"'+this.platform+'"'),shell.cp("-f",n.path,r)),this.config=new ConfigParser(r),xmlHelpers.mergeXml(t.projectConfig.doc.getroot(),this.config.doc.getroot(),this.platform,!0),this.config.write(),this.parser.update_www(t,o);const i=path.join(this.locations.www,"manifest.json"),s=path.join(t.locations.www,"manifest.json");if(fs.existsSync(s))this.events.emit("verbose","copying "+s+" => "+i),shell.cp("-f",s,i);else{const o={background_color:"#FFF",display:"standalone"};if(this.config){this.config.name()&&(o.name=this.config.name()),this.config.shortName()&&(o.short_name=this.config.shortName()),this.config.packageName()&&(o.version=this.config.packageName()),this.config.description()&&(o.description=this.config.description()),this.config.author()&&(o.author=this.config.author());const e=this.config.getStaticResources("browser","icon").map((function(t){return{src:t.src,type:"image/png",sizes:t.width+"x"+t.height}}));o.icons=e;const r=this.config.getGlobalPreference("Orientation");r&&(["landscape","portrait"].indexOf(r)>-1?o.orientation=r:o.orientation="any");const n=this.config.doc.find("content")||{attrib:{src:"index.html"}};o.start_url=n.attrib.src;const i=path.join(t.locations.www,o.start_url);if(fs.existsSync(i)){const t=fs.readFileSync(i,"utf-8"),e=/<meta(?=[^>]*name="theme-color")\s[^>]*content="([^>]*)"/i.exec(t);let r;r=e&&e.length>=2?e[1]:this.config.getGlobalPreference("StatusBarBackgroundColor"),r&&(o.theme_color=r)}}fs.writeFileSync(i,JSON.stringify(o,null,2),"utf8")}return this.parser.update_project(this.config,o)},Api.prototype.addPlugin=function(t,o){if(!t)return Promise.reject(new Error("The parameter is incorrect. The first parameter should be valid PluginInfo instance"));(o=o||{}).variables=o.variables||{},o.platformVersion=o.platformVersion||this.getPlatformInfo().version;const e=this,r=new ActionStack,n=this._handler.parseProjectFile&&this._handler.parseProjectFile(this.root);return t.getFilesAndFrameworks(this.platform).concat(t.getAssets(this.platform)).concat(t.getJsModules(this.platform)).forEach((function(i){r.push(r.createAction(e._getInstaller(i.itemType),[i,t.dir,t.id,o,n],e._getUninstaller(i.itemType),[i,t.dir,t.id,o,n]))})),r.process(this.platform,this.root).then((function(){n&&n.write(),o.variables.PACKAGE_NAME||(o.variables.PACKAGE_NAME=e._handler.package_name(e.root)),e._munger.add_plugin_changes(t,o.variables,!0,!0).save_all();const r=o.usePlatformWww?e.getPlatformInfo().locations.platformWww:e.getPlatformInfo().locations.www;e._addModulesInfo(t,r)}))},Api.prototype.removePlugin=function(t,o){(o=o||{}).platformVersion=o.platformVersion||this.getPlatformInfo().version;const e=this,r=new ActionStack,n=this._handler.parseProjectFile&&this._handler.parseProjectFile(this.root);return t.getFilesAndFrameworks(this.platform).concat(t.getAssets(this.platform)).concat(t.getJsModules(this.platform)).forEach((function(i){r.push(r.createAction(e._getUninstaller(i.itemType),[i,t.dir,t.id,o,n],e._getInstaller(i.itemType),[i,t.dir,t.id,o,n]))})),r.process(this.platform,this.root).then((function(){n&&n.write(),e._munger.remove_plugin_changes(t,!0).save_all();const r=o.usePlatformWww?e.getPlatformInfo().locations.platformWww:e.getPlatformInfo().locations.www;e._removeModulesInfo(t,r),shell.rm("-rf",path.resolve(e.root,"Plugins",t.id))}))},Api.prototype._getInstaller=function(t){const o=this;return function(e,r,n,i,s){const a=o._handler[t];if(a){const l=i.usePlatformWww?o.getPlatformInfo().locations.platformWww:o._handler.www_dir(o.root);"asset"===t?a.install(e,r,l):"js-module"===t?a.install(e,r,n,l):a.install(e,r,o.root,n,i,s)}else console.log("unrecognized type "+t)}},Api.prototype._getUninstaller=function(t){const o=this;return function(e,r,n,i,s){const a=o._handler[t];if(a){const r=i.usePlatformWww?o.getPlatformInfo().locations.platformWww:o._handler.www_dir(o.root);return["asset","js-module"].indexOf(t)>-1?a.uninstall(e,r,n):a.uninstall(e,o.root,n,i,s)}console.log("browser plugin uninstall: unrecognized type, skipping : "+t)}},Api.prototype._addModulesInfo=function(t,o){const e=this._platformJson.root.modules||[],r=e.map((function(t){return t.file})),n=t.getJsModules(this.platform).filter((function(t){return-1===r.indexOf(t.file)})).map((function(o){const e=t.id+"."+(o.name||o.src.match(/([^/]+)\.js/)[1]),r={file:["plugins",t.id,o.src].join("/"),id:e,pluginId:t.id};return o.clobbers.length>0&&(r.clobbers=o.clobbers.map((function(t){return t.target}))),o.merges.length>0&&(r.merges=o.merges.map((function(t){return t.target}))),o.runs&&(r.runs=!0),r}));this._platformJson.root.modules=e.concat(n),this._platformJson.root.plugin_metadata||(this._platformJson.root.plugin_metadata={}),this._platformJson.root.plugin_metadata[t.id]=t.version,this._writePluginModules(o),this._platformJson.save()},Api.prototype._writePluginModules=function(t){let o="cordova.define('cordova/plugin_list', function(require, exports, module) {\n";o+="module.exports = "+JSON.stringify(this._platformJson.root.modules,null,"    ")+";\n",o+="module.exports.metadata = \n",o+="// TOP OF METADATA\n",o+=JSON.stringify(this._platformJson.root.plugin_metadata||{},null,"    ")+"\n",o+="// BOTTOM OF METADATA\n",o+="});",shell.mkdir("-p",t),fs.writeFileSync(path.join(t,"cordova_plugins.js"),o,"utf-8")},Api.prototype._removeModulesInfo=function(t,o){const e=this._platformJson.root.modules||[],r=t.getJsModules(this.platform).map((function(o){return["plugins",t.id,o.src].join("/")})),n=e.filter((function(t){return-1===r.indexOf(t.file)}));this._platformJson.root.modules=n,this._platformJson.root.plugin_metadata&&delete this._platformJson.root.plugin_metadata[t.id],this._writePluginModules(o),this._platformJson.save()},Api.prototype.build=function(t){const o=this;return require("./lib/check_reqs").run().then((function(){return require("./lib/build").run.call(o,t)}))},Api.prototype.run=function(t){return require("./lib/run").run(t)},Api.prototype.clean=function(t){return require("./lib/clean").run(t)},Api.prototype.requirements=function(){return require("./lib/check_reqs").run()},module.exports=Api;
//# sourceMappingURL=/sm/7c7153cd072ff6941d1b3619e2650e86c5d9ee7f761f61c525e9d8051592da1a.map