Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/.eslintrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export default tseslint.config(eslint.configs.recommended, ...tseslint.configs.r
],
'prettier/prettier': 'error',
},
ignores: ['src/graphql/generated/client/**/*'],
});
5 changes: 4 additions & 1 deletion api/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
!src/*

# Downloaded Fixtures (For File Modifications)
src/unraid-api/unraid-file-modifier/modifications/__fixtures__/downloaded/*
src/unraid-api/unraid-file-modifier/modifications/__fixtures__/downloaded/*

# Generated Types
src/graphql/generated/client/*.ts
74 changes: 48 additions & 26 deletions api/scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env zx
import { cp, mkdir, writeFile, stat } from 'fs/promises';
import { pathExists } from 'fs-extra';
import { exit } from 'process';
import { cd, $ } from 'zx';

import { $, cd } from 'zx';

import { getDeploymentVersion } from './get-deployment-version.mjs';

Expand All @@ -12,20 +15,18 @@ try {
process.env.WORKDIR ??= process.env.PWD;
cd(process.env.WORKDIR);

// Create deployment directories - ignore if they already exist
await $`mkdir -p ./deploy/release`;
await $`mkdir -p ./deploy/pre-pack`;

await $`rm -rf ./deploy/release/*`;
await $`rm -rf ./deploy/pre-pack/*`;
// Create deployment directories - ignore if they already exist
await mkdir('./deploy/release', { recursive: true });
await mkdir('./deploy/pre-pack', { recursive: true });

// Build Generated Types
await $`npm run codegen`;

await $`npm run build`;
// Copy app files to plugin directory
await $`cp -r ./src/ ./deploy/pre-pack/src/`;
await $`cp -r ./dist/ ./deploy/pre-pack/dist/`;
await cp('./dist', './deploy/pre-pack/dist', { recursive: true });

// Copy environment to deployment directory
const files = [
Expand All @@ -35,10 +36,10 @@ try {
'codegen.ts',
'ecosystem.config.json',
'vite.config.ts',
]
];

for (const file of files) {
await $`cp ./${file} ./deploy/pre-pack/${file}`;
await cp(`./${file}`, `./deploy/pre-pack/${file}`);
}

// Get package details
Expand All @@ -49,28 +50,49 @@ try {
const deploymentVersion = getDeploymentVersion(process.env, version);

// Create deployment package.json
await $`echo ${JSON.stringify({
...rest,
name,
version: deploymentVersion,
})} > ./deploy/pre-pack/package.json`;

await writeFile(
'./deploy/pre-pack/package.json',
JSON.stringify(
{
name,
version: deploymentVersion,
...rest,
},
null,
2
)
);
// # Create final tgz
await $`cp ./README.md ./deploy/pre-pack/`;
await cp('./README.md', './deploy/pre-pack/README.md');

await cp('./node_modules', './deploy/pre-pack/node_modules', { recursive: true });
// Install production dependencies

await $`cp -r ./node_modules ./deploy/pre-pack/node_modules`;
// Install production dependencies
cd('./deploy/pre-pack');
console.log('Installing dependencies...');

await $`npm prune --omit=dev`;
await $`npm install --omit=dev`;
await $`npm install github:unraid/libvirt`;
$.verbose = true;
await $`npm --prefix ./deploy/pre-pack prune --omit=dev`;
await $`npm --prefix ./deploy/pre-pack install --omit=dev`;

// Now we'll pack everything in the pre-pack directory
await $`tar -czf ../unraid-api-${deploymentVersion}.tgz .`;
// Ensure that we don't have any dev dependencies left
console.log('Installed dependencies:');
await $`npm --prefix ./deploy/pre-pack ls --omit=dev --depth=0`;

// Move unraid-api.tgz to release directory
await $`mv ../unraid-api-${deploymentVersion}.tgz ../release`;
console.log('Dependencies installed, packing...');

// Now we'll pack everything in the pre-pack directory to the release directory
await cd('./deploy/pre-pack');
const tarballPath = `../release/unraid-api-${deploymentVersion}.tgz`;
await $`tar -czf ${tarballPath} .`;
// Ensure the tarball exists
if (!(await pathExists(tarballPath))) {
console.error(`Failed to create tarball at ${tarballPath}`);
process.exit(1);
}
const packageSize = Math.round((await stat(tarballPath)).size / 1024 / 1024);
console.log(
`Package created at: ${tarballPath} with size ${packageSize} MB`
);
} catch (error) {
// Error with a command
if (Object.keys(error).includes('stderr')) {
Expand Down
4 changes: 2 additions & 2 deletions api/src/graphql/generated/client/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-
*/
const documents = {
"\n mutation sendRemoteGraphQLResponse($input: RemoteGraphQLServerInput!) {\n remoteGraphQLResponse(input: $input)\n }\n": types.sendRemoteGraphQLResponseDocument,
"\n fragment RemoteGraphQLEventFragment on RemoteGraphQLEvent {\n remoteGraphQLEventData: data {\n type\n body\n sha256\n }\n }\n": types.RemoteGraphQLEventFragmentFragmentDoc,
"\n fragment RemoteGraphQLEventFragment on RemoteGraphQLEvent {\n remoteGraphQLEventData: data {\n type\n body\n sha256\n }\n }\n": types.RemoteGraphQLEventFragmentFragmentDoc,
"\n subscription events {\n events {\n __typename\n ... on ClientConnectedEvent {\n connectedData: data {\n type\n version\n apiKey\n }\n connectedEvent: type\n }\n ... on ClientDisconnectedEvent {\n disconnectedData: data {\n type\n version\n apiKey\n }\n disconnectedEvent: type\n }\n ...RemoteGraphQLEventFragment\n }\n }\n": types.eventsDocument,
};

Expand All @@ -40,7 +40,7 @@ export function graphql(source: "\n mutation sendRemoteGraphQLResponse($input
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n fragment RemoteGraphQLEventFragment on RemoteGraphQLEvent {\n remoteGraphQLEventData: data {\n type\n body\n sha256\n }\n }\n"): (typeof documents)["\n fragment RemoteGraphQLEventFragment on RemoteGraphQLEvent {\n remoteGraphQLEventData: data {\n type\n body\n sha256\n }\n }\n"];
export function graphql(source: "\n fragment RemoteGraphQLEventFragment on RemoteGraphQLEvent {\n remoteGraphQLEventData: data {\n type\n body\n sha256\n }\n }\n"): (typeof documents)["\n fragment RemoteGraphQLEventFragment on RemoteGraphQLEvent {\n remoteGraphQLEventData: data {\n type\n body\n sha256\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
4 changes: 2 additions & 2 deletions api/src/graphql/generated/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './fragment-masking.js';
export * from './gql.js';
export * from "./fragment-masking.js";
export * from "./gql.js";