新しいアプリケーションのアップロード
api.applications.create(file) は zip をアップロードして、まったく新しいアプリケーションを作成します。file 引数は、ローカルファイルパスまたは Buffer のいずれかです。
import { SquareCloudAPI } from "@squarecloud/api";
import { join } from "node:path";
const api = new SquareCloudAPI(process.env.SQUARE_API_KEY!);
const result = await api.applications.create(join(__dirname, "my-app.zip"));
console.log(result.id); // 新しく作成されたアプリケーション ID
console.log(result.name); // 表示名
console.log(result.lang); // 言語スラッグ (例: "javascript")
console.log(result.ram); // 割り当てられた RAM (MB)
zip には最低限、以下が含まれている必要があります:
- メインファイル — アプリケーションのエントリーポイント
- 依存関係ファイル —
package.json、requirements.txt など
squarecloud.app — 名前、説明、メインファイル、バージョンなどを記載した設定ファイル。設定ファイルガイド を参照してください
既存のアプリケーションへのファイルの commit
app.commit(file, fileName?) は、すでにデプロイ済みのアプリケーションにファイルをアップロードします。複数のファイルを一度に置き換えるには zip を渡し、1 つのファイルだけを更新するには単一のファイルを渡します。
| Parameter | Type | Description |
|---|
file | string | Buffer | ローカルファイルパスまたは Buffer の内容 |
fileName | string? | アップロードに付与される名前。.zip はサーバー側で展開されます。それ以外の拡張子は単一のファイルとして書き込まれます。 |
単一のファイルを commit (Buffer)
ディスクから zip を commit
パス指定でファイルを commit
const content = Buffer.from("console.log('hello')\n");
await app.commit(content, "index.js");
import { readFile } from "node:fs/promises";
const zip = await readFile("./dist.zip");
await app.commit(zip, "dist.zip");
import { join } from "node:path";
const filePath = join(__dirname, "index.js");
await app.commit(filePath, "index.js");
v3 では commit() は 3 番目の restart 引数を受け付けていました。v4 では 3 番目のパラメータは削除されています。再起動が必要な場合は、commit の後に app.restart() を使用してください。
await app.commit(zip, "dist.zip");
await app.restart();