diff --git a/app-bundler/.env.example b/app-bundler/.env.example index be064c628816f1a2b2d0607721c1de5904bbef51..38f6eed9379cfe7f226dc8ae7778b707cae0dbc4 100644 --- a/app-bundler/.env.example +++ b/app-bundler/.env.example @@ -1,5 +1,6 @@ PORT=4000 REPOSITORIES_PATH= ADMIN_PASSWORD=password +INTERKIT_BUNDLER_URL=http://localhost:4000 INTERKIT_SERVER_URL=http://localhost:3000 INTERKIT_SERVER_WEBSOCKETS_URL=ws://localhost:3000/websocket \ No newline at end of file diff --git a/app-bundler/src/filesystem.mjs b/app-bundler/src/filesystem.mjs index d65b96b9cf96cc218ac8520ca10348cf7b602d04..380bfe3b26f38b457a4ad4cf5f6eeed04df217ce 100644 --- a/app-bundler/src/filesystem.mjs +++ b/app-bundler/src/filesystem.mjs @@ -4,6 +4,9 @@ import fse from 'fs-extra' import git from 'isomorphic-git' const REPOSITORIES_PATH = process.env.REPOSITORIES_PATH +const INTERKIT_BUNDLER_URL = process.env.INTERKIT_BUNDLER_URL +const INTERKIT_SERVER_WEBSOCKETS_URL = process.env.INTERKIT_SERVER_WEBSOCKETS_URL +const INTERKIT_SERVER_URL = process.env.INTERKIT_SERVER_URL function getProjectPath(projectId) { const projectPath = path.join(REPOSITORIES_PATH, "projects", projectId) @@ -22,12 +25,25 @@ function ensureRepositories(projects) { } } +function generateInterkitConfig(project) { + return { + project_slug: project.slug || "", + bundle_version: "0.1", + INTERKIT_BUNDLER_URL, + INTERKIT_SERVER_WEBSOCKETS_URL, + INTERKIT_SERVER_URL, + } +} + async function setupNewRepository(project) { const projectId = project.id - console.log("setup new project " + projectId) const starterPath = process.env.REPOSITORIES_PATH + "/starters/cs1" const projectPath = getProjectPath(projectId) + const interkitConfigJson = JSON.stringify(generateInterkitConfig(project)) + + console.log(`setup new project ${projectId} in ${projectPath}. \n ${interkitConfigJson}`) + // create new directory and initialize repo try { @@ -35,6 +51,23 @@ async function setupNewRepository(project) { await fs.promises.mkdir(projectPath); await git.init({ fs, dir: projectPath }); await fse.copySync(starterPath, projectPath) + await fs.promises.writeFile( + path.join(projectPath, "interkit.config.json"), + interkitConfigJson + ) + + await gitAddAll(projectPath) + + let sha = await git.commit({ + fs, + dir: projectPath, + author: { + name: 'Interkit System', + email: 'info@interkit.app', + }, + message: 'Initial commit' + }) + console.log(`initial commit: ${sha}`) } else { console.log("Directory already exists."); @@ -44,6 +77,20 @@ async function setupNewRepository(project) { } } +async function gitAddAll(projectPath) { + const repo = { + fs, + dir: projectPath + } + await git.statusMatrix(repo).then((status) => + Promise.all( + status.map(([filepath, , worktreeStatus]) => + worktreeStatus ? git.add({ ...repo, filepath }) : git.remove({ ...repo, filepath }) + ) + ) + ) +} + export { ensureRepositories, getProjectPath diff --git a/docker-compose.yml b/docker-compose.yml index 69fab88bab74f1b3e23432852bca4e2e27024f3c..3e4d99ed7130c5b7f5438817e7ec3c59096881f5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -94,6 +94,7 @@ services: environment: PORT: 4000 ADMIN_PASSWORD: ${INTERKIT_ADMIN_PASSWORD} + INTERKIT_BUNDLER_URL: ${INTERKIT_BUNDLER_URL:-http://localhost:4000} INTERKIT_SERVER_WEBSOCKETS_URL: ${INTERKIT_SERVER_WEBSOCKETS_URL:-ws://localhost:3000/websocket} INTERKIT_SERVER_URL: ${INTERKIT_SERVER_URL:-http://localhost:3000} labels: