Skip to content

Commit 384a13a

Browse files
committed
feat(stackblitz): change to embed method
1 parent 164ed23 commit 384a13a

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

integrations/stackblitz/src/index.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ const exampleBlock = createComponent({
3333
},
3434
render: async (element, action, context) => {
3535
console.log('RENDER');
36-
await createProject();
36+
try{
37+
await createProject();
38+
} catch (e) {
39+
console.log(e);
40+
}
3741
return (
3842
<block>
3943
<button label={element.state.message} onPress={{ action: 'click' }} />
+25-25
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
import sdk from '@stackblitz/sdk';
2-
// THIS IS OPTION FIVE - OPEN PROJECT (Creates a new project and opens it in a new tab (or in the current window).)
3-
// (project, openOptions)
2+
43
export const createProject = async () => {
5-
console.log('CREATE_PROJECT');
6-
sdk.openProject(
7-
{
8-
title: 'Banana Project',
9-
description: 'Blank starter project for building ES6 apps.',
10-
template: 'javascript',
11-
files: {
12-
'index.html': `<div id='app'></div>`,
13-
'index.js': `import './style.css';
14-
const appDiv = document.getElementById('app');
15-
appDiv.innerHTML = '<h1>JS Starter</h1>';`,
16-
'style.css': `body { font-family: system-ui, sans-serif; }`,
17-
},
18-
settings: {
19-
compile: {
20-
trigger: 'auto',
21-
clearConsole: false,
4+
try {
5+
await sdk.embedProject(
6+
'stackblitz',
7+
{
8+
title: 'Node Starter',
9+
description: 'A basic Node.js project',
10+
template: 'node',
11+
files: {
12+
'index.js': `console.log('Hello World!');`,
13+
'package.json': `{
14+
"name": "my-project",
15+
"scripts": { "hello": "node index.js", "start": "serve node_modules" },
16+
"dependencies": { "serve": "^14.0.0" },
17+
"stackblitz": { "installDependencies": true, "startCommand": "npm start" },
18+
}`,
2219
},
2320
},
24-
},
25-
{
26-
newWindow: false,
27-
openFile: ['index.js', 'index.html,style.css'],
28-
}
29-
);
21+
{
22+
clickToLoad: true,
23+
openFile: 'index.js',
24+
terminalHeight: 50,
25+
}
26+
);
27+
} catch (e) {
28+
console.log('ERROR_CAUGHT: ', e);
29+
}
3030
};

0 commit comments

Comments
 (0)