Skip to content

Commit

Permalink
✨ Chore: Implement @matthiesenxyz/astrodtsbuilder for DTS generation (#…
Browse files Browse the repository at this point in the history
…301)

* Create draft PR for #286
[skip ci]

* Update dependencies to include @matthiesenxyz/astrodtsbuilder for DTS generation

* Apply suggestions from code review

Co-authored-by: Louis Escher <[email protected]>

* lint

* Update packages/studiocms_core/src/stubs/dts.ts

Co-authored-by: Louis Escher <[email protected]>

* lint

* update renovate config

---------

Co-authored-by: create-issue-branch[bot] <53036503+create-issue-branch[bot]@users.noreply.github.com>
Co-authored-by: Adam Matthiesen <[email protected]>
Co-authored-by: Louis Escher <[email protected]>
  • Loading branch information
3 people authored Sep 25, 2024
1 parent a6b780e commit ebc297f
Show file tree
Hide file tree
Showing 23 changed files with 499 additions and 414 deletions.
9 changes: 9 additions & 0 deletions .changeset/silent-peas-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@studiocms/imagehandler": patch
"@studiocms/dashboard": patch
"@studiocms/renderers": patch
"@studiocms/auth": patch
"@studiocms/core": patch
---

Update `.d.ts` file generation (non breaking)
10 changes: 5 additions & 5 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
"customManagers:biomeVersions"
],
"dependencyDashboard": true,
"lockFileMaintenance": {
"enabled": true
},
"postUpdateOptions": ["pnpmDedupe"],
"ignorePaths": ["**/node_modules/**", "**/bower_components/**"],
"labels": ["dependencies"],
"additionalBranchPrefix": "{{parentDir}}-",
"gitIgnoredAuthors": ["github+renovate@astro-studiocms.xyz"],
"gitIgnoredAuthors": ["[email protected]"],
"prHourlyLimit": 3,
"rangeStrategy": "bump",
"reviewers": ["team:exalted"],
Expand All @@ -25,7 +22,10 @@
},
{
"matchDepTypes": ["packageManager", "engines"],
"labels": ["dependencies"],
"enabled": false
},
{
"matchFileNames": [".node-version"],
"enabled": false
}
]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/renovate-changesets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
token: ${{ secrets.DEPENDENCY_UPDATE_GITHUB_TOKEN }}
use-conventional-commits: true
author-name: Renovate Changesets
author-email: github+renovate@astro-studiocms.xyz
author-email: [email protected]
1 change: 1 addition & 0 deletions packages/studiocms_auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"dependencies": {
"@inox-tools/runtime-logger": "catalog:studiocms-shared",
"@matthiesenxyz/astrolace": "catalog:studiocms-shared",
"@matthiesenxyz/astrodtsbuilder": "catalog:studiocms-shared",
"@matthiesenxyz/integration-utils": "catalog:studiocms-shared",
"@noble/hashes": "catalog:studiocms-shared",
"@studiocms/assets": "workspace:*",
Expand Down
10 changes: 2 additions & 8 deletions packages/studiocms_auth/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,8 @@ export default defineIntegration({
},
'astro:config:done': async ({ injectTypes }) => {
// Inject Types
injectTypes({
filename: 'auth-config.d.ts',
content: authConfigDTS,
});
injectTypes({
filename: 'auth-helper.d.ts',
content: authHelperDTS,
});
injectTypes(authConfigDTS);
injectTypes(authHelperDTS);
},
},
};
Expand Down
35 changes: 24 additions & 11 deletions packages/studiocms_auth/src/stubs/auth-config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import fileFactory from '@matthiesenxyz/integration-utils/fileFactory';
import DTSBuilder from '@matthiesenxyz/astrodtsbuilder';

const authConfigDTS = fileFactory();
const authConfig = DTSBuilder();

authConfigDTS.addLines('// This file is generated by StudioCMS\n\n');

authConfigDTS.addLines(`declare module 'studiocms:auth/config' {`);
authConfigDTS.addLines(
` const AuthSecurityConfig: import('@studiocms/core').usernameAndPasswordConfig;`
authConfig.addSingleLineNote(
'This file is generated by StudioCMS and should not be modified manually.'
);
authConfigDTS.addLines(' export default AuthSecurityConfig;');
authConfigDTS.addLines('}');

const DTSFile = authConfigDTS.text();
authConfig.addModule('studiocms:auth/config', {
defaultExport: {
singleLineDescription: 'Auth Security Config for Username and Password Authentication.',
typeDef: `{
salt: string | Uint8Array;
opts: {
N: number;
r: number;
p: number;
dkLen?: number;
asyncTick?: number;
maxmem?: number;
onProgress?: (progress: number) => void;
};
}`,
},
});

const dtsFile = authConfig.makeAstroInjectedType('auth-config.d.ts');

export default DTSFile;
export default dtsFile;
60 changes: 32 additions & 28 deletions packages/studiocms_auth/src/stubs/auth-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
import fileFactory from '@matthiesenxyz/integration-utils/fileFactory';
import DTSBuilder from '@matthiesenxyz/astrodtsbuilder';
import { createResolver } from 'astro-integration-kit';

const { resolve } = createResolver(import.meta.url);

const authHelperDTS = fileFactory();

authHelperDTS.addLines('// This file is generated by StudioCMS\n\n');

authHelperDTS.addLines(`declare module 'studiocms:auth/helpers' {`);

authHelperDTS.addLines(`
/**
* # Auth Helper Function
*
* @param locals The Astro.locals object
* @returns The current user data and session information
*
* @example
* ---
* import { authHelper } from 'studiocms:auth/helpers'
*
* const { id, username, name, email, avatar, githubURL, permissionLevel, currentUserSession } = await authHelper(Astro.locals)
* ---
*/
export const authHelper: typeof import('${resolve('../helpers/authHelper.ts')}').default;`);

authHelperDTS.addLines('}');

const DTSFile = authHelperDTS.text();

export default DTSFile;
const authHelper = DTSBuilder();

authHelper.addSingleLineNote(
'This file is generated by StudioCMS and should not be modified manually.'
);

authHelper.addModule('studiocms:auth/helpers', {
namedExports: [
{
multiLineDescription: [
'# Auth Helper Function',
'',
'@param locals The Astro.locals object',
'@returns The current user data and session information',
'',
'@example',
'---',
"import { authHelper } from 'studiocms:auth/helpers'",
'',
'const { id, username, name, email, avatar, githubURL, permissionLevel, currentUserSession } = await authHelper(Astro.locals)',
'---',
],
name: 'authHelper',
typeDef: `typeof import('${resolve('../helpers/authHelper.ts')}').default`,
},
],
});

const dtsFile = authHelper.makeAstroInjectedType('auth-helper.d.ts');

export default dtsFile;
1 change: 1 addition & 0 deletions packages/studiocms_core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"dependencies": {
"@markdoc/markdoc": "catalog:studiocms-shared",
"@matthiesenxyz/astrolace": "catalog:studiocms-shared",
"@matthiesenxyz/astrodtsbuilder": "catalog:studiocms-shared",
"@matthiesenxyz/integration-utils": "catalog:studiocms-shared",
"@noble/hashes": "catalog:studiocms-shared",
"@studiocms/robotstxt": "workspace:*",
Expand Down
8 changes: 3 additions & 5 deletions packages/studiocms_core/src/integration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { integrationLogger } from '@matthiesenxyz/integration-utils/astroUtils';
import type { InjectedType } from 'astro';
import { createResolver, defineIntegration } from 'astro-integration-kit';
import { version } from '../package.json';
import { name } from '../package.json';
Expand All @@ -11,7 +12,7 @@ export default defineIntegration({
optionsSchema,
setup({ name, options }) {
// Declaration for Core DTS File
let coreDtsFile: string;
let coreDtsFile: InjectedType;

return {
hooks: {
Expand Down Expand Up @@ -47,10 +48,7 @@ export default defineIntegration({
},
'astro:config:done': async ({ injectTypes }) => {
// Inject the DTS File
injectTypes({
filename: 'core.d.ts',
content: coreDtsFile,
});
injectTypes(coreDtsFile);
},
},
};
Expand Down
Loading

0 comments on commit ebc297f

Please sign in to comment.