Skip to content

Commit 88b97a9

Browse files
committed
chore: Module to commonjs
1 parent 6711fbd commit 88b97a9

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

templates/cli/lib/emulation/docker.js.twig

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const activeDockerIds = {};
22

3-
export async function dockerStop(id) {
3+
async function dockerStop(id) {
44
delete activeDockerIds[id];
55
const stopProcess = childProcess.spawn('docker', ['rm', '--force', id], {
66
stdio: 'pipe',
@@ -9,7 +9,7 @@ export async function dockerStop(id) {
99
await new Promise((res) => { stopProcess.on('close', res) });
1010
}
1111

12-
export async function dockerPull(func) {
12+
async function dockerPull(func) {
1313
log('Pulling Docker image of function runtime ...');
1414

1515
const runtimeChunks = func.runtime.split("-");
@@ -29,7 +29,7 @@ export async function dockerPull(func) {
2929
await new Promise((res) => { pullProcess.on('close', res) });
3030
}
3131

32-
export async function dockerBuild(func, variables) {
32+
async function dockerBuild(func, variables) {
3333
log('Building function using Docker ...');
3434

3535
const runtimeChunks = func.runtime.split("-");
@@ -63,7 +63,7 @@ export async function dockerBuild(func, variables) {
6363
buildProcess.stdout.on('data', (data) => {
6464
process.stdout.write(`\n${data}`);
6565
});
66-
66+
6767
buildProcess.stderr.on('data', (data) => {
6868
process.stderr.write(`\n${data}`);
6969
});
@@ -95,19 +95,19 @@ export async function dockerBuild(func, variables) {
9595
const tempPath = path.join(process.cwd(), func.path, 'code.tar.gz');
9696
if (fs.existsSync(tempPath)) {
9797
fs.rmSync(tempPath, { force: true });
98-
}
98+
}
9999
}
100100

101-
export async function dockerStart(func, variables, port) {
101+
async function dockerStart(func, variables, port) {
102102
log('Starting function using Docker ...');
103103

104104
log("Permissions, events, CRON and timeouts dont apply when running locally.");
105105

106106
log('💡 Hint: Function automatically restarts when you edit your code.');
107107

108108
success(`Visit http://localhost:${port}/ to execute your function.`);
109-
110-
109+
110+
111111
const runtimeChunks = func.runtime.split("-");
112112
const runtimeVersion = runtimeChunks.pop();
113113
const runtimeName = runtimeChunks.join("-");
@@ -136,7 +136,7 @@ export async function dockerStart(func, variables, port) {
136136
params.push('-v', `${functionDir}/.appwrite/errors.txt:/mnt/logs/dev_errors.log:rw`);
137137
params.push('-v', `${functionDir}/.appwrite/build.tar.gz:/mnt/code/code.tar.gz:ro`);
138138
params.push(imageName, 'sh', '-c', `helpers/start.sh "${tool.startCommand}"`);
139-
139+
140140
childProcess.spawn('docker', params, {
141141
stdio: 'pipe',
142142
pwd: functionDir
@@ -145,7 +145,7 @@ export async function dockerStart(func, variables, port) {
145145
activeDockerIds[id] = true;
146146
}
147147

148-
export async function dockerCleanup() {
148+
async function dockerCleanup() {
149149
await dockerStop();
150150

151151
const functions = localConfig.getFunctions();
@@ -162,9 +162,18 @@ export async function dockerCleanup() {
162162
}
163163
}
164164

165-
export async function dockerStopActive() {
165+
async function dockerStopActive() {
166166
const ids = Object.keys(activeDockerIds);
167167
for await (const id of ids) {
168168
await dockerStop(id);
169-
}
170-
}
169+
}
170+
}
171+
172+
module.exports = {
173+
dockerStop,
174+
dockerPull,
175+
dockerBuild,
176+
dockerStart,
177+
dockerCleanup,
178+
dockerStopActive,
179+
}

templates/cli/lib/emulation/utils.js.twig

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
export const openRuntimesVersion = 'v3';
1+
const EventEmitter = require('node:events');
22

3-
export const runtimeNames = {
3+
const openRuntimesVersion = 'v3';
4+
5+
const runtimeNames = {
46
'node': 'Node.js',
57
'php': 'PHP',
68
'ruby': 'Ruby',
@@ -15,7 +17,7 @@ export const runtimeNames = {
1517
'bun': 'Bun'
1618
};
1719

18-
export const systemTools = {
20+
const systemTools = {
1921
'node': {
2022
isCompiled: false,
2123
startCommand: "node src/server.js",
@@ -78,7 +80,7 @@ export const systemTools = {
7880
},
7981
};
8082

81-
export const JwtManager = {
83+
const JwtManager = {
8284
userJwt: null,
8385
functionJwt: null,
8486

@@ -115,7 +117,7 @@ export const JwtManager = {
115117
});
116118
this.userJwt = userResponse.jwt;
117119
}
118-
120+
119121
const functionResponse = await projectsCreateJWT({
120122
projectId: localConfig.getProject().projectId,
121123
// TODO: Once we have endpoint for this, use it
@@ -127,7 +129,7 @@ export const JwtManager = {
127129
}
128130
};
129131

130-
export const Queue = {
132+
const Queue = {
131133
files: [],
132134
locked: false,
133135
events: new EventEmitter(),
@@ -161,4 +163,12 @@ export const Queue = {
161163
this.debounce = null;
162164
}, 300);
163165
}
164-
};
166+
};
167+
168+
module.exports = {
169+
openRuntimesVersion,
170+
runtimeNames,
171+
systemTools,
172+
JwtManager,
173+
Queue
174+
}

0 commit comments

Comments
 (0)