(config: Config, cordovaPlugins: Plugin[], platform: string)
| 109 | * Build the plugins/* files for each Cordova plugin installed. |
| 110 | */ |
| 111 | export async function copyPluginsJS(config: Config, cordovaPlugins: Plugin[], platform: string): Promise<void> { |
| 112 | const webDir = await getWebDir(config, platform); |
| 113 | const pluginsDir = join(webDir, 'plugins'); |
| 114 | const cordovaPluginsJSFile = join(webDir, 'cordova_plugins.js'); |
| 115 | await removePluginFiles(config, platform); |
| 116 | await Promise.all( |
| 117 | cordovaPlugins.map(async (p) => { |
| 118 | const pluginId = p.xml.$.id; |
| 119 | const pluginDir = join(pluginsDir, pluginId, 'www'); |
| 120 | await ensureDir(pluginDir); |
| 121 | const jsModules = getJSModules(p, platform); |
| 122 | await Promise.all( |
| 123 | jsModules.map(async (jsModule: any) => { |
| 124 | const filePath = join(webDir, 'plugins', pluginId, jsModule.$.src); |
| 125 | await copy(join(p.rootPath, jsModule.$.src), filePath); |
| 126 | let data = await readFile(filePath, { encoding: 'utf-8' }); |
| 127 | data = data.trim(); |
| 128 | // mimics Cordova's module name logic if the name attr is missing |
| 129 | const name = pluginId + '.' + (jsModule.$.name || basename(jsModule.$.src, extname(jsModule.$.src))); |
| 130 | data = `cordova.define("${name}", function(require, exports, module) { \n${data}\n});`; |
| 131 | data = data.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script\s*>/gi, ''); |
| 132 | await writeFile(filePath, data, { encoding: 'utf-8' }); |
| 133 | }), |
| 134 | ); |
| 135 | const assets = getAssets(p, platform); |
| 136 | await Promise.all( |
| 137 | assets.map(async (asset: any) => { |
| 138 | const filePath = join(webDir, asset.$.target); |
| 139 | await copy(join(p.rootPath, asset.$.src), filePath); |
| 140 | }), |
| 141 | ); |
| 142 | }), |
| 143 | ); |
| 144 | await writeFile(cordovaPluginsJSFile, generateCordovaPluginsJSFile(config, cordovaPlugins, platform)); |
| 145 | } |
| 146 | |
| 147 | export async function copyCordovaJS(config: Config, platform: string): Promise<void> { |
| 148 | const cordovaPath = resolveNode(config.app.rootDir, '@capacitor/core', 'cordova.js'); |
no test coverage detected