Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(integration): Add support to execute packaged custom scripts #2281

Merged
merged 1 commit into from
Mar 8, 2024
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
7 changes: 5 additions & 2 deletions .github/workflows/update-origins.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const getOrigins = () => {
};

const formatOriginsFile = (origins) =>
`export default {\n${Object.entries(origins)
`export { CustomScripts } from './custom-scripts'

export default {\n${Object.entries(origins)
.sort((a, b) =>
a[1].name.toLowerCase() < b[1].name.toLowerCase() ? -1 : 1
)
Expand All @@ -40,11 +42,12 @@ const formatOriginsFile = (origins) =>
.join(",\n")}\n};\n`;

exec(`git diff --name-only HEAD^ HEAD`, (_, out) => {
const files = out.split(/[\r\n]+/).filter((name) => !!name && name.startsWith('src/content/'));
const files = out.split(/[\r\n]+/).filter((name) => !!name && name.startsWith('src/content/') && !path.basename(name).startsWith("_custom_"));
if (files.length === 0) {
console.log(`::No files to process`);
process.exit(0);
}

const infos = files
.map((file) => ({
...getFileInfo(readFileSync(file).toString()),
Expand Down
8 changes: 8 additions & 0 deletions src/content/_custom_SampleScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @name SampleScript
* @urlAlias script_a_shortcode
* @urlRegex app.sample.com
*/
'use strict'

console.log('Custom script executed')
6 changes: 6 additions & 0 deletions src/custom-scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const CustomScripts = {
'script_a_shortcode': {
name: 'Custom Script For XYZ',
file: '_custom_SampleScript.js',
},
}
9 changes: 8 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import origins from './origins';
import origins, { CustomScripts as customScripts } from './origins';

declare const _default = origins as {
[key: string]: {
Expand All @@ -9,3 +9,10 @@ declare const _default = origins as {
};

export default _default;

export declare const CustomScripts = customScripts as {
[key: string]: {
name: string;
file?: string;
};
}
3 changes: 3 additions & 0 deletions src/origins.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { CustomScripts } from './custom-scripts'

export default {
'airtable.com': {
url: '*://airtable.com/*',
Expand Down Expand Up @@ -707,3 +709,4 @@ export default {
name: 'Zube'
}
};

Loading