async function copyPluginsJS(config, cordovaPlugins, platform) {
    const webDir = getWebDir(config, platform);
    const pluginsDir = path_1.join(webDir, 'plugins');
    const cordovaPluginsJSFile = path_1.join(webDir, 'cordova_plugins.js');
    removePluginFiles(config, platform);
    await Promise.all(cordovaPlugins.map(async (p) => {
        const pluginId = p.xml.$.id;
        const pluginDir = path_1.join(pluginsDir, pluginId, 'www');
        fs_1.ensureDirSync(pluginDir);
        const jsModules = plugin_1.getJSModules(p, platform);
        await Promise.all(jsModules.map(async (jsModule) => {
            const filePath = path_1.join(webDir, 'plugins', pluginId, jsModule.$.src);
            fs_1.copySync(path_1.join(p.rootPath, jsModule.$.src), filePath);
            let data = await fs_1.readFileAsync(filePath, 'utf8');
            data = data.trim();
            // mimics Cordova's module name logic if the name attr is missing
            const name = pluginId + '.' + (jsModule.$.name || path_1.basename(jsModule.$.src, path_1.extname(jsModule.$.src)));
            data = `cordova.define("${name}", function(require, exports, module) { \n${data}\n});`;
            data = data.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script\s*>/gi, '');
            await fs_1.writeFileAsync(filePath, data, 'utf8');
        }));
        const assets = plugin_1.getAssets(p, platform);
        assets.map((asset) => {
            const filePath = path_1.join(webDir, asset.$.target);
            fs_1.copySync(path_1.join(p.rootPath, asset.$.src), filePath);
        });
    }));
    fs_1.writeFileAsync(cordovaPluginsJSFile, generateCordovaPluginsJSFile(config, cordovaPlugins, platform));
}
/**
 * Build the plugins/* files for each Cordova plugin installed.
 */
Build the plugins files for each Cordova plugin installed.
Build the plugins files for each Cordova plugin installed .
async function copyPluginsJS(config, cordovaPlugins, platform) {
    const webDir = getWebDir(config, platform);
    const pluginsDir = path_1.join(webDir, 'plugins');
    const cordovaPluginsJSFile = path_1.join(webDir, 'cordova_plugins.js');
    removePluginFiles(config, platform);
    await Promise.all(cordovaPlugins.map(async (p) => {
        const pluginId = p.xml.$.id;
        const pluginDir = path_1.join(pluginsDir, pluginId, 'www');
        fs_1.ensureDirSync(pluginDir);
        const jsModules = plugin_1.getJSModules(p, platform);
        await Promise.all(jsModules.map(async (jsModule) => {
            const filePath = path_1.join(webDir, 'plugins', pluginId, jsModule.$.src);
            fs_1.copySync(path_1.join(p.rootPath, jsModule.$.src), filePath);
            let data = await fs_1.readFileAsync(filePath, 'utf8');
            data = data.trim();
            const name = pluginId + '.' + (jsModule.$.name || path_1.basename(jsModule.$.src, path_1.extname(jsModule.$.src)));
            data = `cordova.define("${name}", function(require, exports, module) { \n${data}\n});`;
            data = data.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script\s*>/gi, '');
            await fs_1.writeFileAsync(filePath, data, 'utf8');
        }));
        const assets = plugin_1.getAssets(p, platform);
        assets.map((asset) => {
            const filePath = path_1.join(webDir, asset.$.target);
            fs_1.copySync(path_1.join(p.rootPath, asset.$.src), filePath);
        });
    }));
    fs_1.writeFileAsync(cordovaPluginsJSFile, generateCordovaPluginsJSFile(config, cordovaPlugins, platform));
}
async function copyPluginsJS ( config , cordovaPlugins , platform ) { const webDir = getWebDir ( config , platform ) ; const pluginsDir = path_1 . join ( webDir , 'plugins' ) ; const cordovaPluginsJSFile = path_1 . join ( webDir , 'cordova_plugins.js' ) ; removePluginFiles ( config , platform ) ; await Promise . all ( cordovaPlugins . map ( async ( p ) => { const pluginId = p . xml . $ . id ; const pluginDir = path_1 . join ( pluginsDir , pluginId , 'www' ) ; fs_1 . ensureDirSync ( pluginDir ) ; const jsModules = plugin_1 . getJSModules ( p , platform ) ; await Promise . all ( jsModules . map ( async ( jsModule ) => { const filePath = path_1 . join ( webDir , 'plugins' , pluginId , jsModule . $ . src ) ; fs_1 . copySync ( path_1 . join ( p . rootPath , jsModule . $ . src ) , filePath ) ; let data = await fs_1 . readFileAsync ( filePath , 'utf8' ) ; data = data . trim ( ) ; const name = pluginId + '.' + ( jsModule . $ . name || path_1 . basename ( jsModule . $ . src , path_1 . extname ( jsModule . $ . src ) ) ) ; data = ` ${ name } \n ${ data } \n ` ; data = data . replace ( / <script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script\s*> / gi , '' ) ; await fs_1 . writeFileAsync ( filePath , data , 'utf8' ) ; } ) ) ; const assets = plugin_1 . getAssets ( p , platform ) ; assets . map ( ( asset ) => { const filePath = path_1 . join ( webDir , asset . $ . target ) ; fs_1 . copySync ( path_1 . join ( p . rootPath , asset . $ . src ) , filePath ) ; } ) ; } ) ) ; fs_1 . writeFileAsync ( cordovaPluginsJSFile , generateCordovaPluginsJSFile ( config , cordovaPlugins , platform ) ) ; }
Build the plugins/* files for each Cordova plugin installed.
Build the plugins / * files for each Cordova plugin installed .
// mimics Cordova's module name logic if the name attr is missing