Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
add clone project helper script
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField committed Aug 16, 2024
1 parent f4898d1 commit 88e0fd8
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@
"scripts": {
"build-client": "cd packages/client && npm run build",
"check": "npm run lint && npm run check-errors && npm run check-eslint && npm run test && npm run build-client",
"check-errors": "tsc --noemit && lerna run --scope '@etherealengine/*' check-errors && lerna run --ignore '@etherealengine/*' check-errors",
"check-errors": "lerna run --scope '@etherealengine/*' check-errors && lerna run --ignore '@etherealengine/*' check-errors",
"check-eslint": "eslint --quiet .",
"checkout-dev": "lerna exec 'git checkout dev' --parallel --no-bail",
"clean-node-modules": "npx rimraf node_modules && npx rimraf package-lock.json && npx lerna exec npx rimraf node_modules && npx lerna exec npx rimraf package-lock.json",
"clone-project": "cross-env ts-node --swc scripts/clone-project.ts",
"create-root-package-json": "cross-env ts-node --swc scripts/create-root-package-json",
"create-project": "cross-env ts-node --swc scripts/create-project",
"depcheck": "lerna exec --no-bail --stream -- depcheck",
Expand Down
90 changes: 90 additions & 0 deletions scripts/clone-project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
CPAL-1.0 License
The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.
The Original Code is Ethereal Engine.
The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Ethereal Engine team.
All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023
Ethereal Engine. All Rights Reserved.
*/
import appRootPath from 'app-root-path'
import cli from 'cli'
import dotenv from 'dotenv-flow'
import fs from 'fs'
import path from 'path'

import { execPromise } from '@etherealengine/server-core/src/util/execPromise'
dotenv.config({
path: appRootPath.path,
silent: true
})
cli.enable('status')

/**
* Repo must be in the format https://github.com/<ORG>/<REPO>
*/

const options = cli.parse({
url: [false, 'Repo URL', 'string'],
branch: ['b', 'Branch', 'string', 'dev']
}) as {
url?: string
branch: string
}

const cloneRepo = async () => {
const branch = options.branch
const url = options.url
if (!url) throw new Error('URL is required')

const [org, repo] = new URL(url).pathname.split('/').slice(1, 3)

const orgFolderPath = path.resolve(appRootPath.path, 'packages/projects/projects', '@' + org)
const orgExists = await fs.promises
.access(orgFolderPath)
.then(() => true)
.catch(() => false)

if (!orgExists) {
await fs.promises.mkdir(orgFolderPath)
}

const repoExists = await fs.promises
.access(path.resolve(orgFolderPath, repo))
.then(() => true)
.catch(() => false)
if (!repoExists) {
await execPromise(`git clone ${url}`, {
cwd: path.resolve(orgFolderPath)
})
}

/** Checkout branch and rebase */
await execPromise(`git checkout ${branch} && git fetch -p && git rebase`, {
cwd: path.resolve(appRootPath.path, `packages/projects/projects/@${org}/${repo}`)
})
}
cli.main(async () => {
try {
await cloneRepo()
cli.exit(0)
} catch (err) {
console.log(err)
cli.fatal(err)
}
})

0 comments on commit 88e0fd8

Please sign in to comment.