Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Update rename script to include option to specify domain #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions bin/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() === '') {
Expand All @@ -139,14 +140,27 @@ 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 = 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))
Expand Down