Skip to content

Commit

Permalink
chore: generic run method
Browse files Browse the repository at this point in the history
  • Loading branch information
deleonio committed Jan 29, 2021
1 parent a1e22f8 commit b861a61
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 235 deletions.
2 changes: 1 addition & 1 deletion packages/cli/core/template/public/index.html
Expand Up @@ -36,6 +36,6 @@
<!-- <script type="module" src="/dist/main.js"></script> -->

<!-- webpack -->
<script src="app.js"></script>
<script type="module" src="app.js"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions packages/cli/core/template/src/app.run.ts
@@ -0,0 +1,21 @@
import { DI } from '@leanup/lib/helpers/injector';

export const importCatch = (error: unknown): void => {
console.warn(error);
};

export const run = (name: string, packageJson: { default: Object }, bootstrap: Function): void => {
DI.register('Framework', {
...packageJson.default,
name: name,
});
import('./shares/register')
.then(() => {
import('./shares/routing')
.then(() => {
bootstrap();
})
.catch(importCatch);
})
.catch(importCatch);
};
26 changes: 8 additions & 18 deletions packages/cli/frameworks/angular/template/src/angular.module.ts
@@ -1,8 +1,8 @@
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { DI } from '@leanup/lib/helpers/injector';

import { importCatch, run } from './app.run';
import { AppComponent } from './components/app/component.angular';
import { InputComponent } from './components/input/component.angular';
import { CreateSerieComponent } from './components/series/create/component.angular';
Expand All @@ -11,25 +11,15 @@ import { EditorSerieComponent } from './components/series/editor/component.angul
import { ListSerieComponent } from './components/series/list/component.angular';
import { APP_HTML_ELEMENT } from './shares/constant';

import('@angular/core/package.json')
.then((packageJson: any) => {
DI.register('Framework', {
...packageJson.default,
name: 'Angular',
import(`@angular/core/package.json`)
.then((packageJson: { default: Object }) => {
run('Angular', packageJson, () => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#angular');
htmlDivElement.style.display = 'inline';
htmlDivElement.appendChild(APP_HTML_ELEMENT);
});
import('./shares/register')
.then(() => {
import('./shares/routing')
.then(() => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#angular');
htmlDivElement.style.display = 'inline';
htmlDivElement.appendChild(APP_HTML_ELEMENT);
})
.catch();
})
.catch();
})
.catch();
.catch(importCatch);

@NgModule({
bootstrap: [AppComponent],
Expand Down
33 changes: 11 additions & 22 deletions packages/cli/frameworks/angularjs/template/src/angularjs.main.ts
Expand Up @@ -8,29 +8,18 @@ import './components/series/list/component.angularjs';

import * as angular from 'angular';

import { DI } from '@leanup/lib/helpers/injector';

import { importCatch, run } from './app.run';
import { APP_HTML_ELEMENT } from './shares/constant';

import('angular/package.json')
.then((packageJson: any) => {
DI.register('Framework', {
...packageJson.default,
name: 'AngularJS',
import(`angular/package.json`)
.then((packageJson: { default: Object }) => {
run('AngularJS', packageJson, () => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#angularjs');
if (htmlDivElement instanceof HTMLDivElement) {
htmlDivElement.style.display = 'inline';
htmlDivElement.appendChild(APP_HTML_ELEMENT);
angular.bootstrap(htmlDivElement, ['app']);
}
});
import('./shares/register')
.then(() => {
import('./shares/routing')
.then(() => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#angularjs');
if (htmlDivElement instanceof HTMLDivElement) {
htmlDivElement.style.display = 'inline';
htmlDivElement.appendChild(APP_HTML_ELEMENT);
angular.bootstrap(htmlDivElement, ['app']);
}
})
.catch();
})
.catch();
})
.catch();
.catch(importCatch);
28 changes: 9 additions & 19 deletions packages/cli/frameworks/aurelia/template/src/aurelia.main.ts
Expand Up @@ -2,7 +2,7 @@ import { bootstrap } from 'aurelia-bootstrapper';
import { Aurelia } from 'aurelia-framework';
import { PLATFORM } from 'aurelia-pal';

import { DI } from '@leanup/lib/helpers/injector';
import { importCatch, run } from './app.run';

export function configure(aurelia: Aurelia): void {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#aurelia');
Expand All @@ -23,23 +23,13 @@ export function configure(aurelia: Aurelia): void {
}
}

import('aurelia-framework/package.json')
.then((packageJson: any) => {
DI.register('Framework', {
...packageJson.default,
name: 'Aurelia',
import(`aurelia-framework/package.json`)
.then((packageJson: { default: Object }) => {
run('Aurelia', packageJson, () => {
bootstrap(configure)
.then(() => {})
.catch(() => {})
.finally(() => {});
});
import('./shares/register')
.then(() => {
import('./shares/routing')
.then(() => {
bootstrap(configure)
.then(() => {})
.catch(() => {})
.finally(() => {});
})
.catch();
})
.catch();
})
.catch();
.catch(importCatch);
31 changes: 10 additions & 21 deletions packages/cli/frameworks/inferno/template/src/inferno.main.tsx
@@ -1,27 +1,16 @@
import { render } from 'inferno';

import { DI } from '@leanup/lib/helpers/injector';

import { importCatch, run } from './app.run';
import { AppComponent } from './components/app/component.inferno';

import('inferno/package.json')
.then((packageJson: any) => {
DI.register('Framework', {
...packageJson.default,
name: 'Inferno',
import(`inferno/package.json`)
.then((packageJson: { default: Object }) => {
run('Inferno', packageJson, () => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#inferno');
if (htmlDivElement instanceof HTMLDivElement) {
htmlDivElement.style.display = 'inline';
render(<AppComponent />, htmlDivElement);
}
});
import('./shares/register')
.then(() => {
import('./shares/routing')
.then(() => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#inferno');
if (htmlDivElement instanceof HTMLDivElement) {
htmlDivElement.style.display = 'inline';
render(<AppComponent />, htmlDivElement);
}
})
.catch();
})
.catch();
})
.catch();
.catch(importCatch);
@@ -1,26 +1,16 @@
import './components/app/component.lit-element';

import { DI } from '@leanup/lib/helpers/injector';
import { importCatch, run } from './app.run';

import('lit-element/package.json')
.then((packageJson: any) => {
DI.register('Framework', {
...packageJson.default,
name: 'lit-element',
import(`lit-element/package.json`)
.then((packageJson: { default: Object }) => {
run('lit-element', packageJson, () => {
// Render the template to the document
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#lit-element');
if (htmlDivElement instanceof HTMLDivElement) {
htmlDivElement.style.display = 'inline';
htmlDivElement.innerHTML = '<app-component />';
}
});
import('./shares/register')
.then(() => {
import('./shares/routing')
.then(() => {
// Render the template to the document
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#lit-element');
if (htmlDivElement instanceof HTMLDivElement) {
htmlDivElement.style.display = 'inline';
htmlDivElement.innerHTML = '<app-component />';
}
})
.catch();
})
.catch();
})
.catch();
.catch(importCatch);
31 changes: 10 additions & 21 deletions packages/cli/frameworks/preact/template/src/preact.main.tsx
@@ -1,7 +1,6 @@
import { h, render } from 'preact';

import { DI } from '@leanup/lib/helpers/injector';

import { importCatch, run } from './app.run';
import { AppComponent } from './components/app/component.preact';

// https://github.com/preactjs/preact/blob/master/README.md#debug-mode
Expand All @@ -12,24 +11,14 @@ if (ENVs.NODE_ENV === 'development') {
require('preact/debug');
}

import('preact/package.json')
.then((packageJson: any) => {
DI.register('Framework', {
...packageJson.default,
name: 'Preact',
import(`preact/package.json`)
.then((packageJson: { default: Object }) => {
run('React', packageJson, () => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#preact');
if (htmlDivElement instanceof HTMLDivElement) {
htmlDivElement.style.display = 'inline';
render(<AppComponent />, htmlDivElement);
}
});
import('./shares/register')
.then(() => {
import('./shares/routing')
.then(() => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#preact');
if (htmlDivElement instanceof HTMLDivElement) {
htmlDivElement.style.display = 'inline';
render(<AppComponent />, htmlDivElement);
}
})
.catch();
})
.catch();
})
.catch();
.catch(importCatch);
31 changes: 10 additions & 21 deletions packages/cli/frameworks/react/template/src/react.main.tsx
@@ -1,28 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom';

import { DI } from '@leanup/lib/helpers/injector';

import { importCatch, run } from './app.run';
import { AppComponent } from './components/app/component.react';

import('react/package.json')
.then((packageJson: any) => {
DI.register('Framework', {
...packageJson.default,
name: 'React',
import(`react/package.json`)
.then((packageJson: { default: Object }) => {
run('React', packageJson, () => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#react');
if (htmlDivElement instanceof HTMLDivElement) {
htmlDivElement.style.display = 'inline';
ReactDOM.render(<AppComponent />, htmlDivElement);
}
});
import('./shares/register')
.then(() => {
import('./shares/routing')
.then(() => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#react');
if (htmlDivElement instanceof HTMLDivElement) {
htmlDivElement.style.display = 'inline';
ReactDOM.render(<AppComponent />, htmlDivElement);
}
})
.catch();
})
.catch();
})
.catch();
.catch(importCatch);
37 changes: 13 additions & 24 deletions packages/cli/frameworks/svelte/template/src/main.svelte.ts
@@ -1,32 +1,21 @@
import { DI } from '@leanup/lib/helpers/injector';

import { importCatch, run } from './app.run';
import App from './components/app/component.svelte';

let app: unknown;

import('svelte/package.json')
.then((packageJson: any) => {
DI.register('Framework', {
...packageJson.default,
name: 'Svelte',
import(`svelte/package.json`)
.then((packageJson: { default: Object }) => {
run('Svelte', packageJson, () => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#svelte');
if (htmlDivElement instanceof HTMLDivElement) {
htmlDivElement.style.display = 'inline';
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
app = new App({
target: htmlDivElement,
});
}
});
import('./shares/register')
.then(() => {
import('./shares/routing')
.then(() => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#svelte');
if (htmlDivElement instanceof HTMLDivElement) {
htmlDivElement.style.display = 'inline';
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
app = new App({
target: htmlDivElement,
});
}
})
.catch();
})
.catch();
})
.catch();
.catch(importCatch);

export default app;
32 changes: 15 additions & 17 deletions packages/cli/frameworks/vanilla/template/src/main.vanilla.ts
@@ -1,20 +1,18 @@
import './components/app/component.vanilla';

import { DI } from '@leanup/lib/helpers/injector';
import { importCatch, run } from './app.run';

DI.register('Framework', {
name: 'Vanilla',
version: null,
});
import('./shares/register')
.then(() => {
import('./shares/routing')
.then(() => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#vanilla');
htmlDivElement.style.display = 'inline';
const appElement: HTMLElement = document.createElement('wc-app');
htmlDivElement.appendChild(appElement);
})
.catch();
})
.catch();
run(
'Vanilla',
{
default: {
version: null,
},
},
() => {
const htmlDivElement: HTMLDivElement | null = document.querySelector('div#vanilla');
htmlDivElement.style.display = 'inline';
const appElement: HTMLElement = document.createElement('wc-app');
htmlDivElement.appendChild(appElement);
}
);

0 comments on commit b861a61

Please sign in to comment.