-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
941b322
commit 8849d05
Showing
14 changed files
with
469 additions
and
214 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
FROM mhart/alpine-node | ||
FROM timbru31/node-alpine-git | ||
|
||
COPY docker/* . | ||
|
||
EXPOSE 1512 | ||
EXPOSE 1512 3000-3050 | ||
|
||
CMD [ "npm", "start" ] |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { v4 as uuid } from 'uuid'; | ||
import { execSync } from 'child_process'; | ||
import path from 'path'; | ||
import { Socket, Server as SocketIOServer } from 'socket.io'; | ||
import { | ||
addCredentialsToGitURI, | ||
createExampleProject, | ||
createProjectPath, | ||
getProjectsNameList, | ||
isDirectoryEmpty, | ||
readAppSettings, | ||
updateAppSettings, | ||
verifyProjectFoldersExist, | ||
} from '../utils'; | ||
import { EVENT_KEYS } from '../../types/events'; | ||
import { updateClientProjectData } from '../utils/events'; | ||
import { emitSocketMessage } from '../socket'; | ||
|
||
type CreateProjectType = { | ||
sshUrl?: string; | ||
httpsUrl?: string; | ||
cloneType: 'OPEN' | 'SSH' | 'HTTPS' | 'LOCAL'; | ||
username?: string; | ||
password?: string; | ||
projectName: string; | ||
directoryPath?: string; | ||
}; | ||
|
||
export const createProject = async ( | ||
socket: Socket | SocketIOServer, | ||
{ | ||
sshUrl, | ||
httpsUrl, | ||
cloneType, | ||
username, | ||
password, | ||
projectName, | ||
directoryPath, | ||
}: CreateProjectType, | ||
) => { | ||
await verifyProjectFoldersExist(); | ||
|
||
const projectPath = | ||
cloneType === 'OPEN' ? directoryPath || '' : createProjectPath(projectName); | ||
|
||
const appSettings = await readAppSettings(); | ||
const newProject = { | ||
id: uuid(), | ||
name: projectName, | ||
directoryPath: projectPath, | ||
}; | ||
await updateAppSettings({ | ||
...appSettings, | ||
projects: [...(appSettings.projects || []), newProject], | ||
}); | ||
|
||
if (cloneType === 'SSH') { | ||
await execSync(`git clone ${sshUrl} ${projectPath}`, { | ||
Check failure Code scanning / CodeQL Uncontrolled command line Critical
This command line depends on a
user-provided value Error loading related location Loading This command line depends on a user-provided value Error loading related location Loading This command line depends on a user-provided value Error loading related location Loading This command line depends on a user-provided value Error loading related location Loading |
||
stdio: [0, 1, 2], // we need this so node will print the command output | ||
cwd: path.resolve('', ''), // path to where you want to save the file | ||
}); | ||
} else if (cloneType === 'HTTPS' && httpsUrl && username && password) { | ||
const updatedURI = addCredentialsToGitURI(httpsUrl, username, password); | ||
|
||
await execSync(`git clone ${updatedURI} ${projectPath}`, { | ||
Check failure Code scanning / CodeQL Uncontrolled command line Critical
This command line depends on a
user-provided value Error loading related location Loading This command line depends on a user-provided value Error loading related location Loading This command line depends on a user-provided value Error loading related location Loading This command line depends on a user-provided value Error loading related location Loading |
||
stdio: [0, 1, 2], // we need this so node will print the command output | ||
cwd: path.resolve('', ''), // path to where you want to save the file | ||
}); | ||
} | ||
|
||
if (await isDirectoryEmpty(projectName)) { | ||
await createExampleProject(projectName); | ||
} | ||
|
||
const newProjectsNameList = await getProjectsNameList(); | ||
|
||
await updateClientProjectData(socket, projectName); | ||
|
||
emitSocketMessage(socket, EVENT_KEYS.CREATE_PROJECT, { | ||
success: true, | ||
newProjectsNameList, | ||
newProjectName: projectName, | ||
}); | ||
}; |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { Router, Request, Response } from 'express'; | ||
import { logger } from '../utils/logger'; | ||
import { getGlobalSocketIo } from '../socket'; | ||
import { createProject } from '../actions/general'; | ||
|
||
const projectRouter = Router(); | ||
|
||
projectRouter.post('/clone/ssh', async (req: Request, res: Response) => { | ||
try { | ||
const { projectName, sshUrl } = req.body; | ||
|
||
const socket = getGlobalSocketIo(); | ||
|
||
await createProject(socket, { | ||
projectName, | ||
sshUrl, | ||
cloneType: 'SSH', | ||
}); | ||
|
||
res.status(200).send({ success: true }); | ||
} catch (error: any) { | ||
console.log(error); | ||
logger('Error restart server', error?.message); | ||
|
||
res | ||
.status(500) | ||
.send({ success: false, message: 'fail to ssh clone the project' }); | ||
} | ||
}); | ||
|
||
projectRouter.post('/clone/https', async (req: Request, res: Response) => { | ||
try { | ||
const { projectName, httpsUrl, username, password } = req.body; | ||
|
||
const socket = getGlobalSocketIo(); | ||
|
||
await createProject(socket, { | ||
projectName, | ||
httpsUrl, | ||
username, | ||
password, | ||
cloneType: 'HTTPS', | ||
}); | ||
|
||
res.status(200).send({ success: true }); | ||
} catch (error: any) { | ||
console.log(error); | ||
logger('Error restart server', error?.message); | ||
|
||
res.status(500).send({ success: false, message: 'fail to restart server' }); | ||
} | ||
}); | ||
|
||
projectRouter.post('/open', async (req: Request, res: Response) => { | ||
try { | ||
const { projectName, directoryPath } = req.body; | ||
|
||
const socket = getGlobalSocketIo(); | ||
|
||
await createProject(socket, { | ||
projectName, | ||
directoryPath, | ||
cloneType: 'OPEN', | ||
}); | ||
|
||
res.status(200).send({ success: true }); | ||
} catch (error: any) { | ||
console.log(error); | ||
logger('Error restart server', error?.message); | ||
|
||
res.status(500).send({ success: false, message: 'fail to restart server' }); | ||
} | ||
}); | ||
|
||
projectRouter.post('/create', async (req: Request, res: Response) => { | ||
try { | ||
const { projectName } = req.body; | ||
|
||
const socket = getGlobalSocketIo(); | ||
|
||
await createProject(socket, { | ||
projectName, | ||
cloneType: 'LOCAL', | ||
}); | ||
|
||
res.status(200).send({ success: true }); | ||
} catch (error: any) { | ||
console.log(error); | ||
logger('Error restart server', error?.message); | ||
|
||
res.status(500).send({ success: false, message: 'fail to restart server' }); | ||
} | ||
}); | ||
|
||
export { projectRouter }; |
Oops, something went wrong.