diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-08-31 23:07:20 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-08-31 23:07:20 +0200 |
| commit | 22721a013bdd10d5eb395ba18453585f5f3f1f7f (patch) | |
| tree | 5a920e31d6026ed5dc55265e5fd057febccc50e3 /StoneIsland/platforms/ios/cordova/lib/plugman | |
| parent | d22d51a1ae49680015326857360eb699f31efced (diff) | |
rebuild the ios platform and the plugins
Diffstat (limited to 'StoneIsland/platforms/ios/cordova/lib/plugman')
| -rw-r--r--[-rwxr-xr-x] | StoneIsland/platforms/ios/cordova/lib/plugman/pluginHandlers.js | 205 |
1 files changed, 96 insertions, 109 deletions
diff --git a/StoneIsland/platforms/ios/cordova/lib/plugman/pluginHandlers.js b/StoneIsland/platforms/ios/cordova/lib/plugman/pluginHandlers.js index 1f6920fa..09d5ae51 100755..100644 --- a/StoneIsland/platforms/ios/cordova/lib/plugman/pluginHandlers.js +++ b/StoneIsland/platforms/ios/cordova/lib/plugman/pluginHandlers.js @@ -15,21 +15,20 @@ under the License. */ 'use strict'; -var fs = require('fs'); -var path = require('path'); -var shell = require('shelljs'); -var util = require('util'); -var events = require('cordova-common').events; -var CordovaError = require('cordova-common').CordovaError; +const fs = require('fs-extra'); +const path = require('path'); +const util = require('util'); +const events = require('cordova-common').events; +const CordovaError = require('cordova-common').CordovaError; // These frameworks are required by cordova-ios by default. We should never add/remove them. -var keep_these_frameworks = [ +const keep_these_frameworks = [ 'MobileCoreServices.framework', 'CoreGraphics.framework', 'AssetsLibrary.framework' ]; -var handlers = { +const handlers = { 'source-file': { install: function (obj, plugin, project, options) { installHelper('source-file', obj, plugin.dir, project.projectDir, plugin.id, options, project); @@ -48,47 +47,47 @@ var handlers = { }, 'resource-file': { install: function (obj, plugin, project, options) { - var src = obj.src; - var target = obj.target; - var srcFile = path.resolve(plugin.dir, src); + const src = obj.src; + let target = obj.target; + const srcFile = path.resolve(plugin.dir, src); if (!target) { target = path.basename(src); } - var destFile = path.resolve(project.resources_dir, target); + const destFile = path.resolve(project.resources_dir, target); if (!fs.existsSync(srcFile)) { - throw new CordovaError('Cannot find resource file "' + srcFile + '" for plugin ' + plugin.id + ' in iOS platform'); + throw new CordovaError(`Cannot find resource file "${srcFile}" for plugin ${plugin.id} in iOS platform`); } if (fs.existsSync(destFile)) { - throw new CordovaError('File already exists at destination "' + destFile + '" for resource file specified by plugin ' + plugin.id + ' in iOS platform'); + throw new CordovaError(`File already exists at destination "${destFile}" for resource file specified by plugin ${plugin.id} in iOS platform`); } project.xcode.addResourceFile(path.join('Resources', target)); - var link = !!(options && options.link); + const link = !!(options && options.link); copyFile(plugin.dir, src, project.projectDir, destFile, link); }, uninstall: function (obj, plugin, project, options) { - var src = obj.src; - var target = obj.target; + const src = obj.src; + let target = obj.target; if (!target) { target = path.basename(src); } - var destFile = path.resolve(project.resources_dir, target); + const destFile = path.resolve(project.resources_dir, target); project.xcode.removeResourceFile(path.join('Resources', target)); - shell.rm('-rf', destFile); + fs.removeSync(destFile); } }, - 'framework': { // CB-5238 custom frameworks only + framework: { // CB-5238 custom frameworks only install: function (obj, plugin, project, options) { - var src = obj.src; - var custom = !!(obj.custom); // convert to boolean (if truthy/falsy) - var embed = !!(obj.embed); // convert to boolean (if truthy/falsy) - var link = !embed; // either link or embed can be true, but not both. the other has to be false + const src = obj.src; + const custom = !!(obj.custom); // convert to boolean (if truthy/falsy) + const embed = !!(obj.embed); // convert to boolean (if truthy/falsy) + const link = !embed; // either link or embed can be true, but not both. the other has to be false if (!custom) { - var keepFrameworks = keep_these_frameworks; + const keepFrameworks = keep_these_frameworks; if (keepFrameworks.indexOf(src) < 0) { if (obj.type === 'podspec') { @@ -96,7 +95,7 @@ var handlers = { } else { project.frameworks[src] = project.frameworks[src] || 0; project.frameworks[src]++; - let opt = { customFramework: false, embed: false, link: true, weak: obj.weak }; + const opt = { customFramework: false, embed: false, link: true, weak: obj.weak }; events.emit('verbose', util.format('Adding non-custom framework to project... %s -> %s', src, JSON.stringify(opt))); project.xcode.addFramework(src, opt); events.emit('verbose', util.format('Non-custom framework added to project. %s -> %s', src, JSON.stringify(opt))); @@ -104,41 +103,32 @@ var handlers = { } return; } - var srcFile = path.resolve(plugin.dir, src); - var targetDir = path.resolve(project.plugins_dir, plugin.id, path.basename(src)); - if (!fs.existsSync(srcFile)) throw new CordovaError('Cannot find framework "' + srcFile + '" for plugin ' + plugin.id + ' in iOS platform'); - if (fs.existsSync(targetDir)) throw new CordovaError('Framework "' + targetDir + '" for plugin ' + plugin.id + ' already exists in iOS platform'); - var symlink = !!(options && options.link); + const srcFile = path.resolve(plugin.dir, src); + const targetDir = path.resolve(project.plugins_dir, plugin.id, path.basename(src)); + if (!fs.existsSync(srcFile)) throw new CordovaError(`Cannot find framework "${srcFile}" for plugin ${plugin.id} in iOS platform`); + if (fs.existsSync(targetDir)) throw new CordovaError(`Framework "${targetDir}" for plugin ${plugin.id} already exists in iOS platform`); + const symlink = !!(options && options.link); copyFile(plugin.dir, src, project.projectDir, targetDir, symlink); // frameworks are directories // CB-10773 translate back slashes to forward on win32 - var project_relative = fixPathSep(path.relative(project.projectDir, targetDir)); + const project_relative = fixPathSep(path.relative(project.projectDir, targetDir)); // CB-11233 create Embed Frameworks Build Phase if does not exist - var existsEmbedFrameworks = project.xcode.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed Frameworks'); + const existsEmbedFrameworks = project.xcode.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed Frameworks'); if (!existsEmbedFrameworks && embed) { events.emit('verbose', '"Embed Frameworks" Build Phase (Embedded Binaries) does not exist, creating it.'); project.xcode.addBuildPhase([], 'PBXCopyFilesBuildPhase', 'Embed Frameworks', null, 'frameworks'); } - let opt = { customFramework: true, embed: embed, link: link, sign: true }; + const opt = { customFramework: true, embed, link, sign: true }; events.emit('verbose', util.format('Adding custom framework to project... %s -> %s', src, JSON.stringify(opt))); project.xcode.addFramework(project_relative, opt); events.emit('verbose', util.format('Custom framework added to project. %s -> %s', src, JSON.stringify(opt))); }, uninstall: function (obj, plugin, project, options) { - var src = obj.src; + const src = obj.src; if (!obj.custom) { // CB-9825 cocoapod integration for plugins - var keepFrameworks = keep_these_frameworks; + const keepFrameworks = keep_these_frameworks; if (keepFrameworks.indexOf(src) < 0) { - if (obj.type === 'podspec') { - var podsJSON = require(path.join(project.projectDir, 'pods.json')); - if (podsJSON[src]) { - if (podsJSON[src].count > 1) { - podsJSON[src].count = podsJSON[src].count - 1; - } else { - delete podsJSON[src]; - } - } - } else { + if (obj.type !== 'podspec') { // this should be refactored project.frameworks[src] = project.frameworks[src] || 1; project.frameworks[src]--; @@ -153,12 +143,12 @@ var handlers = { return; } - var targetDir = fixPathSep(path.resolve(project.plugins_dir, plugin.id, path.basename(src))); - var pbxFile = project.xcode.removeFramework(targetDir, {customFramework: true}); + const targetDir = fixPathSep(path.resolve(project.plugins_dir, plugin.id, path.basename(src))); + const pbxFile = project.xcode.removeFramework(targetDir, { customFramework: true }); if (pbxFile) { project.xcode.removeFromPbxEmbedFrameworksBuildPhase(pbxFile); } - shell.rm('-rf', targetDir); + fs.removeSync(targetDir); } }, 'lib-file': { @@ -169,7 +159,7 @@ var handlers = { events.emit('verbose', '<lib-file> uninstall is not supported for iOS plugins'); } }, - 'asset': { + asset: { install: function (obj, plugin, project, options) { if (!obj.src) { throw new CordovaError(generateAttributeError('src', 'asset', plugin.id)); @@ -182,7 +172,7 @@ var handlers = { if (options && options.usePlatformWww) copyFile(plugin.dir, obj.src, project.platformWww, obj.target); }, uninstall: function (obj, plugin, project, options) { - var target = obj.target; + const target = obj.target; if (!target) { throw new CordovaError(generateAttributeError('target', 'asset', plugin.id)); @@ -199,58 +189,58 @@ var handlers = { 'js-module': { install: function (obj, plugin, project, options) { // Copy the plugin's files into the www directory. - var moduleSource = path.resolve(plugin.dir, obj.src); - var moduleName = plugin.id + '.' + (obj.name || path.basename(obj.src, path.extname(obj.src))); + const moduleSource = path.resolve(plugin.dir, obj.src); + const moduleName = `${plugin.id}.${obj.name || path.basename(obj.src, path.extname(obj.src))}`; // Read in the file, prepend the cordova.define, and write it back out. - var scriptContent = fs.readFileSync(moduleSource, 'utf-8').replace(/^\ufeff/, ''); // Window BOM + let scriptContent = fs.readFileSync(moduleSource, 'utf-8').replace(/^\ufeff/, ''); // Window BOM if (moduleSource.match(/.*\.json$/)) { - scriptContent = 'module.exports = ' + scriptContent; + scriptContent = `module.exports = ${scriptContent}`; } - scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) {\n' + scriptContent + '\n});\n'; + scriptContent = `cordova.define("${moduleName}", function(require, exports, module) {\n${scriptContent}\n});\n`; - var moduleDestination = path.resolve(project.www, 'plugins', plugin.id, obj.src); - shell.mkdir('-p', path.dirname(moduleDestination)); + const moduleDestination = path.resolve(project.www, 'plugins', plugin.id, obj.src); + fs.ensureDirSync(path.dirname(moduleDestination)); fs.writeFileSync(moduleDestination, scriptContent, 'utf-8'); if (options && options.usePlatformWww) { - var platformWwwDestination = path.resolve(project.platformWww, 'plugins', plugin.id, obj.src); - shell.mkdir('-p', path.dirname(platformWwwDestination)); + const platformWwwDestination = path.resolve(project.platformWww, 'plugins', plugin.id, obj.src); + fs.ensureDirSync(path.dirname(platformWwwDestination)); fs.writeFileSync(platformWwwDestination, scriptContent, 'utf-8'); } }, uninstall: function (obj, plugin, project, options) { - var pluginRelativePath = path.join('plugins', plugin.id, obj.src); + const pluginRelativePath = path.join('plugins', plugin.id, obj.src); removeFileAndParents(project.www, pluginRelativePath); if (options && options.usePlatformWww) removeFileAndParents(project.platformWww, pluginRelativePath); } } }; -module.exports.getInstaller = function (type) { +module.exports.getInstaller = type => { if (handlers[type] && handlers[type].install) { return handlers[type].install; } - events.emit('warn', '<' + type + '> is not supported for iOS plugins'); + events.emit('warn', `<${type}> is not supported for iOS plugins`); }; -module.exports.getUninstaller = function (type) { +module.exports.getUninstaller = type => { if (handlers[type] && handlers[type].uninstall) { return handlers[type].uninstall; } - events.emit('warn', '<' + type + '> is not supported for iOS plugins'); + events.emit('warn', `<${type}> is not supported for iOS plugins`); }; function installHelper (type, obj, plugin_dir, project_dir, plugin_id, options, project) { - var srcFile = path.resolve(plugin_dir, obj.src); - var targetDir = path.resolve(project.plugins_dir, plugin_id, obj.targetDir || ''); - var destFile = path.join(targetDir, path.basename(obj.src)); + const srcFile = path.resolve(plugin_dir, obj.src); + const targetDir = path.resolve(project.plugins_dir, plugin_id, obj.targetDir || ''); + const destFile = path.join(targetDir, path.basename(obj.src)); - var project_ref; - var link = !!(options && options.link); + let project_ref; + const link = !!(options && options.link); if (link) { - var trueSrc = fs.realpathSync(srcFile); + const trueSrc = fs.realpathSync(srcFile); // Create a symlink in the expected place, so that uninstall can use it. if (options && options.force) { copyFile(plugin_dir, trueSrc, project_dir, destFile, link); @@ -261,101 +251,98 @@ function installHelper (type, obj, plugin_dir, project_dir, plugin_id, options, // Make the Xcode reference the file directly. // Note: Can't use path.join() here since it collapses 'Plugins/..', and xcode // library special-cases Plugins/ prefix. - project_ref = 'Plugins/' + fixPathSep(path.relative(fs.realpathSync(project.plugins_dir), trueSrc)); + project_ref = `Plugins/${fixPathSep(path.relative(fs.realpathSync(project.plugins_dir), trueSrc))}`; } else { if (options && options.force) { copyFile(plugin_dir, srcFile, project_dir, destFile, link); } else { copyNewFile(plugin_dir, srcFile, project_dir, destFile, link); } - project_ref = 'Plugins/' + fixPathSep(path.relative(project.plugins_dir, destFile)); + project_ref = `Plugins/${fixPathSep(path.relative(project.plugins_dir, destFile))}`; } if (type === 'header-file') { project.xcode.addHeaderFile(project_ref); } else if (obj.framework) { - var opt = { weak: obj.weak }; - var project_relative = path.join(path.basename(project.xcode_path), project_ref); + const opt = { weak: obj.weak }; + const project_relative = path.join(path.basename(project.xcode_path), project_ref); project.xcode.addFramework(project_relative, opt); - project.xcode.addToLibrarySearchPaths({path: project_ref}); + project.xcode.addToLibrarySearchPaths({ path: project_ref }); } else { - project.xcode.addSourceFile(project_ref, obj.compilerFlags ? {compilerFlags: obj.compilerFlags} : {}); + project.xcode.addSourceFile(project_ref, obj.compilerFlags ? { compilerFlags: obj.compilerFlags } : {}); } } function uninstallHelper (type, obj, project_dir, plugin_id, options, project) { - var targetDir = path.resolve(project.plugins_dir, plugin_id, obj.targetDir || ''); - var destFile = path.join(targetDir, path.basename(obj.src)); + const targetDir = path.resolve(project.plugins_dir, plugin_id, obj.targetDir || ''); + const destFile = path.join(targetDir, path.basename(obj.src)); - var project_ref; - var link = !!(options && options.link); + let project_ref; + const link = !!(options && options.link); if (link) { - var trueSrc = fs.readlinkSync(destFile); - project_ref = 'Plugins/' + fixPathSep(path.relative(fs.realpathSync(project.plugins_dir), trueSrc)); + const trueSrc = fs.readlinkSync(destFile); + project_ref = `Plugins/${fixPathSep(path.relative(fs.realpathSync(project.plugins_dir), trueSrc))}`; } else { - project_ref = 'Plugins/' + fixPathSep(path.relative(project.plugins_dir, destFile)); + project_ref = `Plugins/${fixPathSep(path.relative(project.plugins_dir, destFile))}`; } - shell.rm('-rf', targetDir); + fs.removeSync(targetDir); if (type === 'header-file') { project.xcode.removeHeaderFile(project_ref); } else if (obj.framework) { - var project_relative = path.join(path.basename(project.xcode_path), project_ref); + const project_relative = path.join(path.basename(project.xcode_path), project_ref); project.xcode.removeFramework(project_relative); - project.xcode.removeFromLibrarySearchPaths({path: project_ref}); + project.xcode.removeFromLibrarySearchPaths({ path: project_ref }); } else { project.xcode.removeSourceFile(project_ref); } } -var pathSepFix = new RegExp(path.sep.replace(/\\/, '\\\\'), 'g'); +const pathSepFix = new RegExp(path.sep.replace(/\\/, '\\\\'), 'g'); function fixPathSep (file) { return file.replace(pathSepFix, '/'); } function copyFile (plugin_dir, src, project_dir, dest, link) { src = path.resolve(plugin_dir, src); - if (!fs.existsSync(src)) throw new CordovaError('"' + src + '" not found!'); + if (!fs.existsSync(src)) throw new CordovaError(`"${src}" not found!`); // check that src path is inside plugin directory - var real_path = fs.realpathSync(src); - var real_plugin_path = fs.realpathSync(plugin_dir); - if (real_path.indexOf(real_plugin_path) !== 0) { throw new CordovaError('File "' + src + '" is located outside the plugin directory "' + plugin_dir + '"'); } + const real_path = fs.realpathSync(src); + const real_plugin_path = fs.realpathSync(plugin_dir); + if (real_path.indexOf(real_plugin_path) !== 0) { throw new CordovaError(`File "${src}" is located outside the plugin directory "${plugin_dir}"`); } dest = path.resolve(project_dir, dest); // check that dest path is located in project directory - if (dest.indexOf(project_dir) !== 0) { throw new CordovaError('Destination "' + dest + '" for source file "' + src + '" is located outside the project'); } + if (dest.indexOf(project_dir) !== 0) { throw new CordovaError(`Destination "${dest}" for source file "${src}" is located outside the project`); } - shell.mkdir('-p', path.dirname(dest)); + fs.ensureDirSync(path.dirname(dest)); if (link) { linkFileOrDirTree(src, dest); - } else if (fs.statSync(src).isDirectory()) { - // XXX shelljs decides to create a directory when -R|-r is used which sucks. http://goo.gl/nbsjq - shell.cp('-Rf', path.join(src, '/*'), dest); } else { - shell.cp('-f', src, dest); + fs.copySync(src, dest); } } // Same as copy file but throws error if target exists function copyNewFile (plugin_dir, src, project_dir, dest, link) { - var target_path = path.resolve(project_dir, dest); - if (fs.existsSync(target_path)) { throw new CordovaError('"' + target_path + '" already exists!'); } + const target_path = path.resolve(project_dir, dest); + if (fs.existsSync(target_path)) { throw new CordovaError(`"${target_path}" already exists!`); } copyFile(plugin_dir, src, project_dir, dest, !!link); } function linkFileOrDirTree (src, dest) { if (fs.existsSync(dest)) { - shell.rm('-Rf', dest); + fs.removeSync(dest); } if (fs.statSync(src).isDirectory()) { - shell.mkdir('-p', dest); - fs.readdirSync(src).forEach(function (entry) { + fs.ensureDirSync(dest); + fs.readdirSync(src).forEach(entry => { linkFileOrDirTree(path.join(src, entry), path.join(dest, entry)); }); } else { @@ -365,24 +352,24 @@ function linkFileOrDirTree (src, dest) { // checks if file exists and then deletes. Error if doesn't exist function removeFile (project_dir, src) { - var file = path.resolve(project_dir, src); - shell.rm('-Rf', file); + const file = path.resolve(project_dir, src); + fs.removeSync(file); } // deletes file/directory without checking function removeFileF (file) { - shell.rm('-Rf', file); + fs.removeSync(file); } function removeFileAndParents (baseDir, destFile, stopper) { stopper = stopper || '.'; - var file = path.resolve(baseDir, destFile); + const file = path.resolve(baseDir, destFile); if (!fs.existsSync(file)) return; removeFileF(file); // check if directory is empty - var curDir = path.dirname(file); + let curDir = path.dirname(file); while (curDir !== path.resolve(baseDir, stopper)) { if (fs.existsSync(curDir) && fs.readdirSync(curDir).length === 0) { @@ -396,5 +383,5 @@ function removeFileAndParents (baseDir, destFile, stopper) { } function generateAttributeError (attribute, element, id) { - return 'Required attribute "' + attribute + '" not specified in <' + element + '> element from plugin: ' + id; + return `Required attribute "${attribute}" not specified in <${element}> element from plugin: ${id}`; } |
