Commit 6b44e835 authored by Holger Heißmeyer's avatar Holger Heißmeyer
Browse files

bundler: generate interkit.config.json for new project

Showing with 50 additions and 1 deletion
+50 -1
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
......@@ -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
......
......@@ -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:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment