Created
November 9, 2023 00:24
-
-
Save loraxx753/b75b3844df1fd642578ede8fa2c43a74 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
import { Command } from 'commander'; | |
import { log, info, success, warning, pbcopy } from '../lib/utils.mjs'; | |
import { Octokit } from 'octokit'; | |
import { cloneRepository, createApplication } from '../lib/functions.mjs'; | |
import { enterpriseServer36 } from '@octokit/plugin-enterprise-server'; | |
import auth from '../auth.json' assert { type: 'json' }; | |
import shell from 'shelljs'; | |
const { github: githubAuth } = auth; | |
const OctokitEnterprise36 = Octokit.plugin(enterpriseServer36); | |
export const octokit = new OctokitEnterprise36({ | |
auth: githubAuth, | |
baseUrl: 'https://github.com/api/v3', | |
}); | |
const program = new Command(); | |
export const projectsFolder = process.cwd(); | |
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
program.description('CLI for Atlas applications').version('0.8.0'); | |
program | |
.command('init') | |
.description('Initiate new project') | |
.argument('<appName>', 'Application Name') | |
.option('--verbose', 'Show all logging') | |
.option('--with <repos...>', 'Clones other repos. Options: lib gql') | |
.action(async (appName, options) => { | |
// console.log(options); | |
// process.exit(0); | |
log(info`Creating Atlas application ${warning(appName)} ...`); | |
log( | |
info`Creating ${warning`${appName}`} from template ${warning`atlas-template`} ...` | |
); | |
const appInfo = await createApplication(appName); | |
log( | |
success`Atlas repository created at ${warning`${appInfo.data.svn_url}`}` | |
); | |
await delay(1000); | |
log(info`Cloning Atlas repository to the ${warning`${projectsFolder}`}`); | |
const cloneUrl = appInfo.data.clone_url; | |
await cloneRepository(appName, cloneUrl); | |
log( | |
success`Cloned ${warning`${appName}`} to ${warning`${projectsFolder}/${appName}`}!` | |
); | |
if (options.with && options.with.includes('lib')) { | |
await cloneRepository( | |
`atlas-components`, | |
`[email protected]:abc/def.git` | |
); | |
} | |
if (options.with && options.with.includes('gql')) { | |
const appInfo = await createApplication( | |
`${appName}-graphql`, | |
`kbaugh`, | |
`graphql-template` | |
); | |
// pbcopy(appInfo); | |
log( | |
success`Graphql server repository created at ${warning`${appInfo.data.svn_url}`}` | |
); | |
await delay(1000); | |
log(info`Cloning Graphql server to ${warning`${projectsFolder}`}`); | |
const cloneUrl = appInfo.data.clone_url; | |
await cloneRepository(`${appName}-graphql`, cloneUrl); | |
log( | |
success`Cloned ${warning`${appName}-graphql`} to ${warning`${projectsFolder}/${appName}-graphql`}!` | |
); | |
} | |
}); | |
program.parse(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment