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
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
"@calycode/cli": patch
---

feat: added getStartDir() method to the ConfigStorage interface. Goal is to allow platform agnosticity in the context resolution.
fix: fixing an issue where xanoscript generation would fail due to missing context
fix: fixing package.json for package publishing, not building packages in the github action resulted with non-existent dist directory...
13 changes: 7 additions & 6 deletions packages/cli/src/commands/generate-xanoscript-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,27 @@ async function generateXanoscriptRepo({ instance, workspace, branch, core, print
workspace,
branch,
});
const { instanceConfig, workspaceConfig, branchConfig } = await resolveConfigs({
const { instanceConfig, workspaceConfig, branchConfig, context } = await resolveConfigs({
requiredFields: ['instance', 'workspace', 'branch'],
cliContext: { instance, workspace, branch },
core,
});

// Resolve output dir
const outputDir = replacePlaceholders(instanceConfig.xanoscript.output, {
'@': await core.findProjectRoot(),
'@': await findProjectRoot(),
instance: instanceConfig.name,
workspace: workspaceConfig.name,
branch: branchConfig.label,
});

clearDirectory(outputDir);
await mkdirSync(outputDir, { recursive: true });
mkdirSync(outputDir, { recursive: true });

const plannedWrites: { path: string; content: string }[] = await core.buildXanoscriptRepo({
instance,
workspace,
branch,
instance: context.instance,
workspace: context.workspace,
branch: context.branch,
});
await Promise.all(
plannedWrites.map(async ({ path, content }) => {
Expand Down
11 changes: 10 additions & 1 deletion packages/cli/src/node-config-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import os from 'os';
import { x } from 'tar';
import { tmpdir } from 'os';
import { join } from 'path';
import { ConfigStorage, CoreContext, InstanceConfig } from '@calycode/types';
import { ConfigStorage, InstanceConfig } from '@calycode/types';

const BASE_DIR = path.join(os.homedir(), '.xano-tools');
const GLOBAL_CONFIG_PATH = path.join(BASE_DIR, 'config.json');
Expand Down Expand Up @@ -219,6 +219,15 @@ export const nodeConfigStorage: ConfigStorage = {
fs.writeFileSync(p, token, { mode: 0o600 });
},

/**
* Get the current working directory as 'startDir' for reuse in the core methods.
*
* @return string
*/
getStartDir() {
return process.cwd();
},
//
// ----- FILESYSTEM OPS -----
async mkdir(dirPath, options) {
await fs.promises.mkdir(dirPath, options);
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/src/utils/commands/context-resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ async function promptForContext(
const selectedWorkspaceId = responses['workspace'] ?? knownContext.workspace;
// Workspace could be identified by id or label or name; adjust as needed:
let workspace = instanceConfig.workspaces.find(
(w) =>
w.id === selectedWorkspaceId ||
w.name === selectedWorkspaceId ||
w.label === selectedWorkspaceId
(w) => w.id === selectedWorkspaceId || w.name === selectedWorkspaceId
);
choices = workspace?.branches || [];
}
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/features/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async function testRunner({
groups,
testConfig,
core,
storage,
}: {
context: CoreContext;
groups: ApiGroupConfig[];
Expand All @@ -64,6 +65,7 @@ async function testRunner({
customAsserts: AssertDefinition;
}[];
core: Caly;
storage: Caly['storage'];
}): Promise<
{
group: ApiGroupConfig;
Expand All @@ -80,7 +82,7 @@ async function testRunner({
const { instance, workspace, branch } = context;

core.emit('start', { name: 'start-testing', payload: context });
const startDir = process.cwd();
const startDir = storage.getStartDir();
const { instanceConfig, workspaceConfig, branchConfig } = await core.loadAndValidateContext({
instance,
workspace,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/implementations/backups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function exportBackupImplementation({ instance, workspace, branch, core })
message: 'Loading context...',
percent: 5,
});
const startDir = process.cwd();
const startDir = core.storage.getStartDir();
const { instanceConfig, workspaceConfig, branchConfig } = await core.loadAndValidateContext({
instance,
workspace,
Expand Down Expand Up @@ -103,7 +103,7 @@ async function restoreBackupImplementation({ instance, workspace, formData, core
message: 'Loading context...',
percent: 5,
});
const startDir = process.cwd();
const startDir = core.storage.getStartDir();
const { instanceConfig, workspaceConfig } = await core.loadAndValidateContext({
instance,
workspace,
Expand Down
21 changes: 13 additions & 8 deletions packages/core/src/implementations/build-xanoscript-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,33 @@ async function fetchAndProcessEntities({
"description" = "Xanoscript fetching failed with message: ${xanoscript.message}"
}
`;
tempResults.push({ path: `${path}/script.xs`, content: xanoScriptContent });
tempResults.push({ path: `${path}/script.freezed.xs`, content: xanoScriptContent });
}

return tempResults;
}

async function buildXanoscriptRepoImplementation(
storage: Caly['storage'],
core: Caly,
options: CoreContext
): Promise<{ path: string; content: string }[]> {
async function buildXanoscriptRepoImplementation({
storage,
core,
options,
}: {
storage: Caly['storage'];
core: Caly;
options: CoreContext;
}): Promise<{ path: string; content: string }[]> {
const { instance, workspace, branch } = options;

core.emit('start', { name: 'xs-repo-generation', payload: options });

// [ ] THIS IS WHERE THE ROOT OF ALL EVIL IS
const results: { path: string; content: string }[] = [];
const startDir = process.cwd();
const startDir = storage.getStartDir();
const { instanceConfig, workspaceConfig, branchConfig } = await core.loadAndValidateContext({
instance,
workspace,
branch,
startDir
startDir,
});

const baseUrl = instanceConfig.url;
Expand Down
10 changes: 0 additions & 10 deletions packages/core/src/implementations/load-and-validate-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ import {
} from '@calycode/types';
import { getCurrentContextConfigImplementation } from './get-current-context';

function assignDefined<T>(base: T, overrides: Partial<T>): T {
const result = { ...base };
for (const key in overrides) {
if (overrides[key] !== undefined) {
result[key] = overrides[key]!;
}
}
return result;
}

export async function loadAndValidateContextImplementation({
storage,
overrides,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/implementations/run-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ async function runTestsImplementation({
groups,
testConfig,
core,
storage,
}: {
context: CoreContext;
groups: ApiGroupConfig[];
Expand All @@ -20,6 +21,7 @@ async function runTestsImplementation({
customAsserts: AssertDefinition;
}[];
core: Caly;
storage: Caly['storage'];
}): Promise<
{
group: ApiGroupConfig;
Expand All @@ -33,7 +35,7 @@ async function runTestsImplementation({
}[];
}[]
> {
return await testRunner({ context, groups, testConfig, core });
return await testRunner({ context, groups, testConfig, core, storage });
}

export { runTestsImplementation };
20 changes: 15 additions & 5 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,14 @@ export class Caly extends TypedEmitter<EventMap> {
workspace,
branch,
}): Promise<{ path: string; content: string }[]> {
const response = await buildXanoscriptRepoImplementation(this.storage, this, {
instance,
workspace,
branch,
const response = await buildXanoscriptRepoImplementation({
storage: this.storage,
core: this,
options: {
instance,
workspace,
branch,
},
});
return response;
}
Expand Down Expand Up @@ -301,7 +305,13 @@ export class Caly extends TypedEmitter<EventMap> {
}[];
}[]
> {
return await runTestsImplementation({ context, groups, testConfig, core: this });
return await runTestsImplementation({
context,
groups,
testConfig,
core: this,
storage: this.storage,
});
}

// ----- SEMI-UTIL METHODS ----- //
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface ConfigStorage {
saveGlobalConfig(config: any): Promise<void>;
saveInstanceConfig(projectRoot: string, data: InstanceConfig): Promise<void>;
saveToken(instance: string, token: string): Promise<void>;
getStartDir(): string;

// Add generic file/directory methods:
mkdir(path: string, options?: { recursive?: boolean }): Promise<void>;
Expand Down