Skip to content

Commit cd5915d

Browse files
committed
RC updage
1 parent 5301b71 commit cd5915d

File tree

3 files changed

+43
-41
lines changed

3 files changed

+43
-41
lines changed

lib/commands/push.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ const awaitPools = {
341341
}
342342

343343
const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural) => {
344-
log('Checking for changes');
344+
log('Checking for changes ...');
345345
const changes = [];
346346

347347
await Promise.all(resource.map(async (localResource) => {
@@ -881,7 +881,7 @@ const pushSettings = async () => {
881881
const remoteSettings = localConfig.createSettingsObject(response ?? {});
882882
const localSettings = localConfig.getProject().projectSettings ?? {};
883883

884-
log('Checking for changes');
884+
log('Checking for changes ...');
885885
const changes = [];
886886

887887
changes.push(...(getObjectChanges(remoteSettings, localSettings, 'services', 'Service')));

lib/commands/run.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const { systemHasCommand, isPortTaken, getAllFiles } = require('../utils');
1717
const { runtimeNames, systemTools, JwtManager, Queue } = require('../emulation/utils');
1818
const { dockerStop, dockerCleanup, dockerStart, dockerBuild, dockerPull } = require('../emulation/docker');
1919

20-
const runFunction = async ({ port, functionId, noVariables, noReload, userId } = {}) => {
20+
const runFunction = async ({ port, functionId, variables, reload, userId } = {}) => {
21+
console.log(variables);
22+
console.log(reload);
2123
// Selection
2224
if(!functionId) {
2325
const answers = await inquirer.prompt(questionsRunFunctions[0]);
@@ -113,17 +115,17 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
113115
}
114116

115117
const userVariables = {};
116-
const variables = {};
118+
const allVariables = {};
117119

118-
if(!noVariables) {
120+
if(variables) {
119121
try {
120122
const { variables: remoteVariables } = await paginate(functionsListVariables, {
121123
functionId: func['$id'],
122124
parseOutput: false
123125
}, 100, 'variables');
124126

125127
remoteVariables.forEach((v) => {
126-
variables[v.key] = v.value;
128+
allVariables[v.key] = v.value;
127129
userVariables[v.key] = v.value;
128130
});
129131
} catch(err) {
@@ -137,18 +139,18 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
137139
const env = parseDotenv(fs.readFileSync(envPath).toString() ?? '');
138140

139141
Object.keys(env).forEach((key) => {
140-
variables[key] = env[key];
142+
allVariables[key] = env[key];
141143
userVariables[key] = env[key];
142144
});
143145
}
144146

145-
variables['APPWRITE_FUNCTION_API_ENDPOINT'] = globalConfig.getFrom('endpoint');
146-
variables['APPWRITE_FUNCTION_ID'] = func.$id;
147-
variables['APPWRITE_FUNCTION_NAME'] = func.name;
148-
variables['APPWRITE_FUNCTION_DEPLOYMENT'] = ''; // TODO: Implement when relevant
149-
variables['APPWRITE_FUNCTION_PROJECT_ID'] = localConfig.getProject().projectId;
150-
variables['APPWRITE_FUNCTION_RUNTIME_NAME'] = runtimeNames[runtimeName] ?? '';
151-
variables['APPWRITE_FUNCTION_RUNTIME_VERSION'] = func.runtime;
147+
allVariables['APPWRITE_FUNCTION_API_ENDPOINT'] = globalConfig.getFrom('endpoint');
148+
allVariables['APPWRITE_FUNCTION_ID'] = func.$id;
149+
allVariables['APPWRITE_FUNCTION_NAME'] = func.name;
150+
allVariables['APPWRITE_FUNCTION_DEPLOYMENT'] = ''; // TODO: Implement when relevant
151+
allVariables['APPWRITE_FUNCTION_PROJECT_ID'] = localConfig.getProject().projectId;
152+
allVariables['APPWRITE_FUNCTION_RUNTIME_NAME'] = runtimeNames[runtimeName] ?? '';
153+
allVariables['APPWRITE_FUNCTION_RUNTIME_VERSION'] = func.runtime;
152154

153155
try {
154156
await JwtManager.setup(userId, func.scopes ?? []);
@@ -162,7 +164,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
162164
headers['x-appwrite-event'] = '';
163165
headers['x-appwrite-user-id'] = userId ?? '';
164166
headers['x-appwrite-user-jwt'] = JwtManager.userJwt ?? '';
165-
variables['OPEN_RUNTIMES_HEADERS'] = JSON.stringify(headers);
167+
allVariables['OPEN_RUNTIMES_HEADERS'] = JSON.stringify(headers);
166168

167169
if(Object.keys(userVariables).length > 0) {
168170
drawTable(Object.keys(userVariables).map((key) => ({
@@ -180,7 +182,7 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } =
180182
process.stdout.write(chalk.white(`${data}\n`));
181183
});
182184

183-
if(!noReload) {
185+
if(reload) {
184186
const ignorer = ignore();
185187
ignorer.add('.appwrite');
186188
ignorer.add('code.tar.gz');

lib/emulation/docker.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,31 @@ async function dockerBuild(func, variables) {
5151

5252
const id = func.$id;
5353

54+
const ignorer = ignore();
55+
ignorer.add('.appwrite');
56+
if (func.ignore) {
57+
ignorer.add(func.ignore);
58+
} else if (fs.existsSync(path.join(functionDir, '.gitignore'))) {
59+
ignorer.add(fs.readFileSync(path.join(functionDir, '.gitignore')).toString());
60+
}
61+
62+
const files = getAllFiles(functionDir).map((file) => path.relative(functionDir, file)).filter((file) => !ignorer.ignores(file));
63+
const tmpBuildPath = path.join(functionDir, '.appwrite/tmp-build');
64+
if (!fs.existsSync(tmpBuildPath)) {
65+
fs.mkdirSync(tmpBuildPath, { recursive: true });
66+
}
67+
68+
for(const f of files) {
69+
const filePath = path.join(tmpBuildPath, f);
70+
const fileDir = path.dirname(filePath);
71+
if (!fs.existsSync(fileDir)) {
72+
fs.mkdirSync(fileDir, { recursive: true });
73+
}
74+
75+
const sourcePath = path.join(functionDir, f);
76+
fs.copyFileSync(sourcePath, filePath);
77+
}
78+
5479
const params = [ 'run' ];
5580
params.push('--name', id);
5681
params.push('-v', `${tmpBuildPath}/:/mnt/code:rw`);
@@ -131,31 +156,6 @@ async function dockerStart(func, variables, port) {
131156
// Pack function files
132157
const functionDir = path.join(process.cwd(), func.path);
133158

134-
const ignorer = ignore();
135-
ignorer.add('.appwrite');
136-
if (func.ignore) {
137-
ignorer.add(func.ignore);
138-
} else if (fs.existsSync(path.join(functionDir, '.gitignore'))) {
139-
ignorer.add(fs.readFileSync(path.join(functionDir, '.gitignore')).toString());
140-
}
141-
142-
const files = getAllFiles(functionDir).map((file) => path.relative(functionDir, file)).filter((file) => !ignorer.ignores(file));
143-
const tmpBuildPath = path.join(functionDir, '.appwrite/tmp-build');
144-
if (!fs.existsSync(tmpBuildPath)) {
145-
fs.mkdirSync(tmpBuildPath, { recursive: true });
146-
}
147-
148-
for(const f of files) {
149-
const filePath = path.join(tmpBuildPath, f);
150-
const fileDir = path.dirname(filePath);
151-
if (!fs.existsSync(fileDir)) {
152-
fs.mkdirSync(fileDir, { recursive: true });
153-
}
154-
155-
const sourcePath = path.join(functionDir, f);
156-
fs.copyFileSync(sourcePath, filePath);
157-
}
158-
159159
const runtimeChunks = func.runtime.split("-");
160160
const runtimeVersion = runtimeChunks.pop();
161161
const runtimeName = runtimeChunks.join("-");

0 commit comments

Comments
 (0)