├── scripts ├── update-ios-app-name.js └── sync-plugin-version.js ├── .gitignore ├── README.md ├── LICENSE ├── package.json ├── plugin.xml └── src └── rename-app.js /scripts/update-ios-app-name.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/sync-plugin-version.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var libxml = require('libxmljs'); 3 | var version = process.env.npm_package_version; 4 | var content = fs.readFileSync('plugin.xml'); 5 | var xml = libxml.parseXmlString(content); 6 | xml.get('/p:plugin', { 7 | 'p': 'http://apache.org/cordova/ns/plugins/1.0' 8 | }).attr({ 9 | 'version': version 10 | }); 11 | 12 | fs.writeFileSync('plugin.xml', xml.toString()); 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Node template 3 | # Logs 4 | logs 5 | *.log 6 | npm-debug.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | 13 | # Directory for instrumented libs generated by jscoverage/JSCover 14 | lib-cov 15 | 16 | # Coverage directory used by tools like istanbul 17 | coverage 18 | 19 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 20 | .grunt 21 | 22 | # node-waf configuration 23 | .lock-wscript 24 | 25 | # Compiled binary addons (http://nodejs.org/api/addons.html) 26 | build/Release 27 | 28 | # Dependency directory 29 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git 30 | node_modules 31 | .idea/ 32 | *.iml 33 | 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cordova-plugin-app-name 2 | I created this plugin to address the issue of spaces in the names of my Cordova apps. 3 | 4 | ## How does it work? 5 | It adds an after_prepare hook that changes the value of app_name in strings.xml for Android and updates the "Project Name" and 6 | "Project Display Name" in the plist for iOS. 7 | 8 | ## How do I install it? 9 | 10 | If you're like me and using [Cordova CLI](http://cordova.apache.org/): 11 | ``` 12 | cordova plugin add cordova-plugin-app-name --variable APP_NAME="Look I Got Spaces and Stuff!" 13 | ``` 14 | 15 | or 16 | 17 | ``` 18 | phonegap local plugin add cordova-plugin-app-name --variable APP_NAME="Look I Got Spaces and Stuff!" 19 | ``` 20 | 21 | ## How do I use it? 22 | Um ... See above :) 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 blakgeek 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cordova-plugin-app-name", 3 | "version": "1.0.7", 4 | "description": "A Cordova/PhoneGap plugin that allows you to give you app a name with spaces and special characters and stuff.", 5 | "cordova": { 6 | "id": "cordova-plugin-app-name", 7 | "platforms": [ 8 | "ios", 9 | "android" 10 | ] 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/blakgeek/cordova-plugin-app-name.git" 15 | }, 16 | "bugs": { 17 | "url": "https://github.com/blakgeek/cordova-plugin-app-name/issues" 18 | }, 19 | "homepage": "https://github.com/blakgeek/cordova-plugin-app-name", 20 | "keywords": [ 21 | "ecosystem:cordova", 22 | "cordova-android", 23 | "cordova-ios", 24 | "cordova:plugin", 25 | "spaces", 26 | "app", 27 | "name", 28 | "rename" 29 | ], 30 | "license": "MIT", 31 | "dependencies": { 32 | "semver": "^6.3.0", 33 | "xml2js": "^0.4.16" 34 | }, 35 | "devDependencies": { 36 | "libxmljs": "^0.18.4" 37 | }, 38 | "scripts": { 39 | "postversion": "node scripts/sync-plugin-version.js; git add plugin.xml; git commit plugin.xml -m \"v${npm_package_version}\"" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | App Namer 4 | Carlos "blakgeek" Lawton 5 | 6 | Cordova/Phonegap plugin that allows you to put spaces in the display name of your app. 7 | 8 | cordova, ios, app, name, spaces 9 | MIT 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | $APP_NAME 26 | 27 | 28 | $APP_NAME 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/rename-app.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var fs = require('fs'); 4 | var path = require("path"); 5 | var xml2js = require('xml2js'); 6 | var parser = new xml2js.Parser(); 7 | var semver = require('semver'); 8 | var builder = new xml2js.Builder({ 9 | xmldec: { 10 | version: '1.0', 11 | encoding: 'UTF-8' 12 | } 13 | }); 14 | 15 | module.exports = function (context) { 16 | 17 | if(context.opts.platforms.indexOf('android') === -1) return; 18 | 19 | console.log('Attempting to set app name'); 20 | 21 | var projectRoot = context.opts.projectRoot; 22 | 23 | const usesNewStructure = fs.existsSync(path.join(projectRoot, 'platforms', 'android', 'app')); 24 | const basePath = usesNewStructure ? path.join(projectRoot, 'platforms', 'android', 'app', 'src', 'main') : path.join(projectRoot, 'platforms', 'android'); 25 | var configPath = path.join(basePath, 'res', 'xml', 'config.xml'); 26 | var stringsPath = path.join(basePath, 'res', 'values', 'strings.xml'); 27 | var stringsXml, name; 28 | 29 | // make sure the android config file exists 30 | try { 31 | fs.accessSync(configPath, fs.F_OK); 32 | } catch(e) { 33 | console.error(`Could not find android config.xml at ${configPath}`); 34 | return; 35 | } 36 | 37 | name = getConfigParser(context, configPath).getPreference('AppName'); 38 | 39 | if (name) { 40 | stringsXml = fs.readFileSync(stringsPath, 'UTF-8'); 41 | parser.parseString(stringsXml, function (err, data) { 42 | 43 | data.resources.string.forEach(function (string) { 44 | 45 | if (string.$.name === 'app_name') { 46 | 47 | console.log('Setting App Name: ', name); 48 | string._ = name; 49 | } 50 | }); 51 | 52 | fs.writeFileSync(stringsPath, builder.buildObject(data)); 53 | 54 | }); 55 | } 56 | }; 57 | 58 | function getConfigParser(context, config) { 59 | 60 | if (semver.lt(context.opts.cordova.version, '5.4.0')) { 61 | ConfigParser = context.requireCordovaModule('cordova-lib/src/ConfigParser/ConfigParser'); 62 | } else { 63 | ConfigParser = context.requireCordovaModule('cordova-common/src/ConfigParser/ConfigParser'); 64 | } 65 | 66 | return new ConfigParser(config); 67 | } 68 | --------------------------------------------------------------------------------