diff --git a/package.json b/package.json index 7637a7b..16656c5 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "template/" ], "engines": { - "node": ">=20.0.0" + "node": ">=20.11.0" }, "scripts": { "clean": "rm -rf coverage docs dist", @@ -72,7 +72,7 @@ "@types/yargs": "^17.0.32", "npm-package-json-lint": "^7.1.0", "precommit": "^1.2.2", - "semantic-release": "^23.0.0", + "semantic-release": "^23.0.8", "snazzy": "^9.0.0", "ts-node": "^10.9.2", "ts-standard": "^12.0.2", diff --git a/src/index.ts b/src/index.ts index 902ea23..cff48d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,7 +28,7 @@ export const main = async (): Promise => { // set var const npmName = !isProd() ? undefined : await getProjectName(_.kebabCase(defaultProjectName)) - const { npm, gitLocation, repoOwner, repoName, repoPrivateLocation, website, type, node, vite, email, description, license, keywords, port } = await inquirer.prompt([{ + const { npm, gitLocation, website, type, node, vite, email, description, license, keywords, port } = await inquirer.prompt([{ default: defaultProjectName, name: 'npm', message: 'Your Project NPM name?', @@ -45,30 +45,6 @@ export const main = async (): Promise => { message: 'Where are we storing this code today?', type: 'list', filter (val: string) { return val.toLowerCase() } - }, { - type: 'input', - name: 'repoOwner', - message: 'Repository Owner (e.g. https://github.com/{OWNER}/{PROJECT NAME}):', - default: 'Bugs5382', // this is me! - when: (answers) => answers.gitLocation === 'github' - }, { - type: 'input', - name: 'repoName', - message: 'Repository Project Name (e.g. https://github.com/{OWNER}/{PROJECT NAME}):', - validate: (result) => { - if (result === '') { - return 'Error: Please enter a repo name. If the repo does not exist, it will be created for you.' - } else { - return true - } - }, - when: (answers) => answers.gitLocation === 'github', - filter (val: string) { return val.toLowerCase() } - }, { - type: 'input', - name: 'repoPrivateLocation', - message: 'Full URL of Git Repo:', - when: (answers) => answers.gitLocation !== 'github' && answers.gitLocation !== 'skip-git' }, { name: 'website', message: 'Homepage of Author:', @@ -158,17 +134,69 @@ export const main = async (): Promise => { let gitIssues: string | undefined let gitReadme: string | undefined let gitUrl: string | undefined + let gitOwner: string | undefined if (gitLocation !== 'skip-git') { await git.init(cwd, 'initial') - if (gitLocation === 'github' && typeof repoOwner !== 'undefined' && typeof repoName !== 'undefined') { - await git.addRemote(cwd, repoOwner, repoName) - } + switch (gitLocation) { + case 'github': + + let { repoOwner, repoName } = await inquirer.prompt([{ + type: 'input', + name: 'repoOwner', + message: 'Repository Owner (e.g. https://github.com/[OWNER]):', + default: 'Bugs5382', // this is me! + }, { + type: 'input', + name: 'repoName', + message: 'Repository Project Name (e.g. https://github.com/OWNER/[PROJECT NAME]):', + validate: (result) => { + if (result === '') { + return 'Error: Please enter a repo name. If the repo does not exist, it will be created for you.' + } else { + return true + } + }, + filter (val: string) { return val.toLowerCase() } + }]) + + await git.addRemoteGitHUb(cwd, repoOwner, repoName) + + gitUrl = `https://github.com/${repoOwner as string}/${repoName as string}.git` + gitOwner = repoOwner + + break + case 'private-repo': + + let { repoUrl, repoProject, repoNamePrivate } = await inquirer.prompt([ { + type: 'input', + name: 'repoUrl', + message: 'Full URL of Git Repo (e.g. https://REPOURL) Do not include the trailing /:' + }, { + type: 'input', + name: 'repoProject', + message: 'Project "Folder (e.g. https://REPOURL/[PROJECT]) Do not include the trailing /:' + }, { + type: 'input', + name: 'repoNamePrivate', + message: 'Repository Repo Name (e.g. https://REPOURL/PROJECT/[REPONAME].git}):', + validate: (result) => { + if (result === '') { + return 'Error: Please enter a repo name. If the repo does not exist, it will be potentially created for you.' + } else { + return true + } + }, + filter (val: string) { return val.toLowerCase() } + }]) + + await git.addRemotePrivate(cwd, repoUrl, repoProject, repoNamePrivate ) + + gitUrl = `${repoUrl as string}/${repoProject as string}/${repoNamePrivate as string}.git` + gitOwner = repoProject - if (gitLocation === 'github') { - gitUrl = `https://github.com/${repoOwner as string}/${repoName as string}` - gitIssues = `${gitUrl}/issues` - gitReadme = `${gitUrl}#readme` } + gitIssues = `${gitUrl}/issues` + gitReadme = `${gitUrl}#readme` } // Generate Licence @@ -186,7 +214,7 @@ export const main = async (): Promise => { description, gitIssues, gitReadme, - gitUrl: typeof repoPrivateLocation !== 'undefined' ? repoPrivateLocation : gitUrl, + gitUrl, license, keywords }, { @@ -205,7 +233,7 @@ export const main = async (): Promise => { }, { npm: typeof npmName !== 'undefined' ? npmName : npm, author: DEFAULT_NPM.author.name, - repoOwner, + repoOwner: gitOwner, description, homepage: website, license diff --git a/src/modules/git.ts b/src/modules/git.ts index a2cccfb..f57a22e 100644 --- a/src/modules/git.ts +++ b/src/modules/git.ts @@ -39,7 +39,7 @@ export async function init (folder: string, step: string): Promise { * @param repoOwner * @param repoName */ -export async function addRemote (folder: string, repoOwner: string, repoName: string): Promise { +export async function addRemoteGitHUb (folder: string, repoOwner: string, repoName: string): Promise { try { // If this succeeds, there's already a remote for `origin`. await execFile('git', ['config', 'remote.origin.url'], { cwd: folder }) @@ -52,6 +52,27 @@ export async function addRemote (folder: string, repoOwner: string, repoName: st } } +/** + * Add Git Remote for Other Repo Location + * @since 1.5.0 + * @param folder + * @param repoUrl + * @param repoProject + * @param repoName + */ +export async function addRemotePrivate (folder: string, repoUrl: string, repoProject: string, repoName: string): Promise { + try { + // If this succeeds, there's already a remote for `origin`. + await execFile('git', ['config', 'remote.origin.url'], { cwd: folder }) + } catch { + await execFile( + 'git', + ['remote', 'add', 'origin', `${repoUrl}/${repoProject}/${repoName}.git`], + { cwd: folder } + ) + } +} + export async function getUserName (): Promise { try { const { stdout } = await execFile('git', ['config', 'user.name']) diff --git a/src/modules/npm.ts b/src/modules/npm.ts index c9a0bfb..b7ecac5 100644 --- a/src/modules/npm.ts +++ b/src/modules/npm.ts @@ -119,12 +119,12 @@ export const generatePackageJson = (params: GeneratePackageJsonParams, input: Ge version: '0.0.0-development', description: params.description, engines: { - node: '>=20.0.0' + node: '>=20.11.0' }, ...finalPackage, repository: { type: 'git', - url: `git+${params.gitUrl as string}.git` + url: typeof params.gitUrl === 'undefined' ? '' : `git+${params.gitUrl as string}` }, keywords: params.keywords, author: params.author,