Skip to content

Commit

Permalink
feat(integration): Add support to execute packaged custom scripts (#2281
Browse files Browse the repository at this point in the history
)
  • Loading branch information
with-shrey authored Mar 8, 2024
1 parent 0389fa9 commit 291f01c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
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'
}
};

0 comments on commit 291f01c

Please sign in to comment.