From 02ad26a5c24afa92fc7803dd24ae35c21aab9f77 Mon Sep 17 00:00:00 2001 From: Viviano Cantu Date: Wed, 23 May 2018 17:08:43 -0400 Subject: [PATCH 1/2] Update rename script to include option to specify domain --- bin/rename.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/bin/rename.js b/bin/rename.js index ba2f1cd..8566338 100644 --- a/bin/rename.js +++ b/bin/rename.js @@ -7,6 +7,7 @@ const DEFAULT_COMPANY_NAME = 'invertase'; const DEFAULT_PACKAGE_NAME = 'com.invertase.rnfirebasestarter'; const DEFAULT_PROJECT_NAME = 'RNFirebaseStarter'; const VALID_CHARACTERS = /^[a-zA-Z\s]+$/; +const VALID_DOMAIN = /^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/; const rl = readline.createInterface({ input: process.stdin, @@ -130,7 +131,7 @@ const run = async () => { if (!projectName.match(VALID_CHARACTERS)) { throw new Error('ERROR: The project name must only contain letters or spaces'); } - + let companyName = await readInput('Company name, e.g. My Company'); console.log('---------------------------------------------------------'); if (!companyName || companyName === '' || companyName.trim() === '') { @@ -139,11 +140,22 @@ const run = async () => { if (!companyName.match(VALID_CHARACTERS)) { throw new Error('ERROR: The company name must only contain letters or spaces'); } - + + let companyDomain = await readInput('Company Domain, e.g. company.com'); + console.log('---------------------------------------------------------'); + if (!companyDomain || companyDomain === '' || companyDomain.trim() === '') { + throw new Error('ERROR: Please supply a company URL'); + } + if (!companyDomain.match(VALID_DOMAIN)) { + throw new Error('ERROR: Invalid company domain, does not follow format: [domain name].[domain extension]'); + } + projectName = projectName.replace(/ /g, ''); companyName = companyName.replace(/ /g, '').toLowerCase(); - - const packageName = `com.${companyName}.${projectName.toLowerCase()}`; + domainExt = companyName.toLowerCase().split('.')[1] + domainName = companyName.toLowerCase().split('.')[0] + + const packageName = `${domainExt}.${domainName}.${projectName.toLowerCase()}`; // Close the input rl.close(); From 0af1c305c35f2eeab6613d61cded00663d71f808 Mon Sep 17 00:00:00 2001 From: Viviano Cantu Date: Wed, 23 May 2018 17:50:11 -0400 Subject: [PATCH 2/2] fixed type which caused domained extension to be undefined --- bin/rename.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/rename.js b/bin/rename.js index 8566338..507f149 100644 --- a/bin/rename.js +++ b/bin/rename.js @@ -152,13 +152,15 @@ const run = async () => { projectName = projectName.replace(/ /g, ''); companyName = companyName.replace(/ /g, '').toLowerCase(); - domainExt = companyName.toLowerCase().split('.')[1] - domainName = companyName.toLowerCase().split('.')[0] + domainExt = companyDomain.toLowerCase().split('.')[1] + domainName = companyDomain.toLowerCase().split('.')[0] + + console.log const packageName = `${domainExt}.${domainName}.${projectName.toLowerCase()}`; // Close the input rl.close(); - + updateProjectName(projectName) .then(() => updatePackageName(packageName)) .then(() => renameProjectFiles(projectName))