create-switch-framework-app 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +25 -25
  2. package/bin/create-switch-framework-app.js +510 -502
  3. package/package.json +31 -31
  4. package/templates/electron/base/app/(tabs)/+not-found.js +157 -157
  5. package/templates/electron/base/app/(tabs)/_layout.js +57 -93
  6. package/templates/electron/base/app/(tabs)/explore.js +55 -44
  7. package/templates/electron/base/app/(tabs)/index.js +10 -24
  8. package/templates/electron/base/app/+not-found.js +148 -158
  9. package/templates/electron/base/app/_layout.js +24 -44
  10. package/templates/electron/base/app/index.js +16 -30
  11. package/templates/electron/base/assets/logo.svg +5 -5
  12. package/templates/electron/base/components/SwSplashScreen.js +1 -1
  13. package/templates/electron/base/components/SwStarterSplashScreen.js +130 -140
  14. package/templates/electron/base/components/SwTabBar.js +146 -153
  15. package/templates/electron/base/electron/electron-builder.json +19 -19
  16. package/templates/electron/base/electron/main.js +30 -30
  17. package/templates/electron/base/electron/preload.js +5 -5
  18. package/templates/electron/base/index.js +2 -3
  19. package/templates/electron/base/main.js +1 -1
  20. package/templates/electron/base/preload.js +1 -1
  21. package/templates/electron/base/server.js +27 -42
  22. package/templates/web/base/app/(tabs)/+not-found.js +157 -157
  23. package/templates/web/base/app/(tabs)/_layout.js +57 -93
  24. package/templates/web/base/app/(tabs)/explore.js +55 -44
  25. package/templates/web/base/app/(tabs)/index.js +10 -24
  26. package/templates/web/base/app/+not-found.js +148 -158
  27. package/templates/web/base/app/_layout.js +24 -44
  28. package/templates/web/base/app/index.js +16 -30
  29. package/templates/web/base/assets/logo.svg +5 -5
  30. package/templates/web/base/components/SwSplashScreen.js +1 -1
  31. package/templates/web/base/components/SwStarterSplashScreen.js +130 -140
  32. package/templates/web/base/components/SwTabBar.js +146 -153
  33. package/templates/web/base/index.js +2 -3
  34. package/templates/electron/base/app/(tabs)/register.js +0 -12
  35. package/templates/electron/base/app/register.js +0 -12
  36. package/templates/web/base/app/(tabs)/register.js +0 -12
  37. package/templates/web/base/app/register.js +0 -12
@@ -1,30 +1,30 @@
1
- const { app, BrowserWindow } = require('electron');
2
- const path = require('node:path');
3
-
4
- const port = process.env.PORT ? Number(process.env.PORT) : 3000;
5
- let mainWindow;
6
-
7
- function createWindow() {
8
- mainWindow = new BrowserWindow({
9
- width: 1200,
10
- height: 800,
11
- webPreferences: {
12
- preload: path.join(__dirname, 'preload.js')
13
- }
14
- });
15
-
16
- mainWindow.loadURL(`http://localhost:${port}`);
17
- }
18
-
19
- app.whenReady().then(() => {
20
- require('../server.js');
21
- setTimeout(createWindow, 350);
22
-
23
- app.on('activate', () => {
24
- if (BrowserWindow.getAllWindows().length === 0) createWindow();
25
- });
26
- });
27
-
28
- app.on('window-all-closed', () => {
29
- if (process.platform !== 'darwin') app.quit();
30
- });
1
+ const { app, BrowserWindow } = require('electron');
2
+ const path = require('node:path');
3
+
4
+ const port = process.env.PORT ? Number(process.env.PORT) : 3000;
5
+ let mainWindow;
6
+
7
+ function createWindow() {
8
+ mainWindow = new BrowserWindow({
9
+ width: 1200,
10
+ height: 800,
11
+ webPreferences: {
12
+ preload: path.join(__dirname, 'preload.js')
13
+ }
14
+ });
15
+
16
+ mainWindow.loadURL(`http://localhost:${port}`);
17
+ }
18
+
19
+ app.whenReady().then(() => {
20
+ require('../server.js');
21
+ setTimeout(createWindow, 350);
22
+
23
+ app.on('activate', () => {
24
+ if (BrowserWindow.getAllWindows().length === 0) createWindow();
25
+ });
26
+ });
27
+
28
+ app.on('window-all-closed', () => {
29
+ if (process.platform !== 'darwin') app.quit();
30
+ });
@@ -1,5 +1,5 @@
1
- const { contextBridge } = require('electron');
2
-
3
- contextBridge.exposeInMainWorld('switchApp', {
4
- ping: () => 'pong'
5
- });
1
+ const { contextBridge } = require('electron');
2
+
3
+ contextBridge.exposeInMainWorld('switchApp', {
4
+ ping: () => 'pong'
5
+ });
@@ -1,5 +1,4 @@
1
- import { startApp } from '/switch-framework/index.js';
1
+ import { startApp } from 'switch-framework';
2
2
  import layout from './app/_layout.js';
3
- import { appRegisters } from './app/register.js';
4
3
 
5
- startApp(layout, appRegisters);
4
+ startApp(layout);
@@ -1 +1 @@
1
- module.exports = require('./electron/main.js');
1
+ module.exports = require('./electron/main.js');
@@ -1 +1 @@
1
- module.exports = require('./electron/preload.js');
1
+ module.exports = require('./electron/preload.js');
@@ -1,42 +1,27 @@
1
- const express = require('express');
2
- const session = require('express-session');
3
- const path = require('node:path');
4
- require('dotenv').config();
5
-
6
- const { checkRestrict } = require('switch-framework-backend/middleware');
7
-
8
- const app = express();
9
- const PORT = process.env.PORT ? Number(process.env.PORT) : 3000;
10
-
11
- app.use(express.json({ limit: '25mb' }));
12
-
13
- app.use(session({
14
- secret: process.env.SESSION_SECRET || 'dev-secret',
15
- resave: false,
16
- saveUninitialized: false
17
- }));
18
-
19
- // Serve switch-framework to the browser from node_modules
20
- app.use('/switch-framework', express.static(path.join(__dirname, 'node_modules', 'switch-framework')));
21
-
22
- // Serve project files
23
- app.use(express.static(path.join(__dirname, '.')));
24
-
25
- const restrictConfig = {
26
- public: ['/', '/login'],
27
- rules: [
28
- { prefix: '/admin', roles: ['admin'] },
29
- { prefix: '/billing', roles: ['billing', 'admin'] },
30
- { path: '/login', roles: ['*'] }
31
- ]
32
- };
33
-
34
- app.use(checkRestrict(restrictConfig));
35
-
36
- app.get('*', (req, res) => {
37
- res.sendFile(path.join(__dirname, '.', 'index.html'));
38
- });
39
-
40
- app.listen(PORT, () => {
41
- console.log('Switch Framework app running at http://localhost:' + PORT);
42
- });
1
+ require('dotenv').config();
2
+
3
+ const switchFrameworkBackend = require('switch-framework-backend');
4
+
5
+ switchFrameworkBackend.config({
6
+ PORT: process.env.PORT ? Number(process.env.PORT) : 3000,
7
+ staticRoot: __dirname,
8
+ session: {
9
+ secret: process.env.SESSION_SECRET || 'dev-secret',
10
+ resave: false,
11
+ saveUninitialized: false
12
+ }
13
+ });
14
+
15
+ const app = switchFrameworkBackend();
16
+
17
+ app.initServer((server) => {
18
+ const restrictConfig = {
19
+ public: ['/', '/login'],
20
+ rules: [
21
+ { prefix: '/admin', roles: ['admin'] },
22
+ { prefix: '/billing', roles: ['billing', 'admin'] },
23
+ { path: '/login', roles: ['*'] }
24
+ ]
25
+ };
26
+ server.use(switchFrameworkBackend.checkRestrict(restrictConfig));
27
+ });
@@ -1,158 +1,158 @@
1
- export const screen = {
2
- name: '+not-found',
3
- path: '/+not-found',
4
- title: 'Not Found',
5
- tag: 'sw-user-not-found-screen',
6
- layout: 'stack'
7
- };
8
-
9
- export class SwUserNotFoundScreen extends HTMLElement {
10
- constructor() {
11
- super();
12
- this.attachShadow({ mode: 'open' });
13
- }
14
-
15
- static get observedAttributes() {
16
- return ['path'];
17
- }
18
-
19
- connectedCallback() {
20
- this.render();
21
- }
22
-
23
- attributeChangedCallback() {
24
- this.render();
25
- }
26
-
27
- render() {
28
- const path = this.getAttribute('path') || window.location.pathname || '';
29
-
30
- this.shadowRoot.innerHTML = `
31
- ${this.styleSheet()}
32
- <div class="wrap">
33
- <div class="card">
34
- <div class="code">404</div>
35
- <div class="h">This screen does not exist</div>
36
- <div class="p">No screen is registered for:</div>
37
- <div class="path">${path}</div>
38
-
39
- <div class="row">
40
- <button class="btn" id="home">Go to Home</button>
41
- <button class="btn secondary" id="back">Go Back</button>
42
- </div>
43
- </div>
44
- </div>
45
- `;
46
-
47
- this.shadowRoot.getElementById('home')?.addEventListener('click', () => {
48
- const navigate = globalStates?.getState ? globalStates.getState('navigate') : null;
49
- if (typeof navigate === 'function') navigate('home');
50
- });
51
-
52
- this.shadowRoot.getElementById('back')?.addEventListener('click', () => {
53
- const goBack = globalStates?.getState ? globalStates.getState('go_back') : null;
54
- if (typeof goBack === 'function') goBack();
55
- else window.history.back();
56
- });
57
- }
58
-
59
- styleSheet() {
60
- return `
61
- <style>
62
- :host {
63
- display: block;
64
- width: 100%;
65
- min-height: 100dvh;
66
- font-family: var(--font);
67
- }
68
-
69
- * {
70
- box-sizing: border-box;
71
- font-family: inherit;
72
- }
73
-
74
- .wrap {
75
- min-height: 100vh;
76
- display: flex;
77
- align-items: center;
78
- justify-content: center;
79
- padding: 18px;
80
- }
81
-
82
- .card {
83
- width: min(680px, 100%);
84
- background: transparent;
85
- border: none;
86
- border-radius: 18px;
87
- padding: 18px;
88
- box-shadow: none;
89
- }
90
-
91
- .code {
92
- font-weight: 1000;
93
- font-size: 44px;
94
- line-height: 1;
95
- color: var(--main_text);
96
- }
97
-
98
- .h {
99
- margin-top: 10px;
100
- font-weight: 1000;
101
- font-size: 20px;
102
- color: var(--main_text);
103
- }
104
-
105
- .p {
106
- margin-top: 6px;
107
- color: var(--sub_text);
108
- font-weight: 800;
109
- }
110
-
111
- .path {
112
- margin-top: 10px;
113
- padding: 10px 12px;
114
- border-radius: 14px;
115
- background: var(--surface_2);
116
- border: 1px solid var(--border_light);
117
- font-weight: 900;
118
- color: var(--main_text);
119
- word-break: break-word;
120
- }
121
-
122
- .row {
123
- margin-top: 14px;
124
- display: flex;
125
- gap: 10px;
126
- flex-wrap: wrap;
127
- }
128
-
129
- .btn {
130
- border: none;
131
- background: linear-gradient(135deg, #0091ff 0%, #0073e6 100%);
132
- color: #fff;
133
- font-weight: 1000;
134
- border-radius: 999px;
135
- padding: 10px 14px;
136
- cursor: pointer;
137
- }
138
-
139
- .btn:hover {
140
- opacity: 0.9;
141
- }
142
-
143
- .btn.secondary {
144
- background: var(--surface_2);
145
- color: var(--main_text);
146
- }
147
-
148
- .btn.secondary:hover {
149
- background: var(--surface_3);
150
- }
151
- </style>
152
- `;
153
- }
154
- }
155
-
156
- if (!customElements.get('sw-user-not-found-screen')) {
157
- customElements.define('sw-user-not-found-screen', SwUserNotFoundScreen);
1
+ export const screen = {
2
+ name: '+not-found',
3
+ path: '/+not-found',
4
+ title: 'Not Found',
5
+ tag: 'sw-user-not-found-screen',
6
+ layout: 'stack'
7
+ };
8
+
9
+ export class SwUserNotFoundScreen extends HTMLElement {
10
+ constructor() {
11
+ super();
12
+ this.attachShadow({ mode: 'open' });
13
+ }
14
+
15
+ static get observedAttributes() {
16
+ return ['path'];
17
+ }
18
+
19
+ connectedCallback() {
20
+ this.render();
21
+ }
22
+
23
+ attributeChangedCallback() {
24
+ this.render();
25
+ }
26
+
27
+ render() {
28
+ const path = this.getAttribute('path') || window.location.pathname || '';
29
+
30
+ this.shadowRoot.innerHTML = `
31
+ ${this.styleSheet()}
32
+ <div class="wrap">
33
+ <div class="card">
34
+ <div class="code">404</div>
35
+ <div class="h">This screen does not exist</div>
36
+ <div class="p">No screen is registered for:</div>
37
+ <div class="path">${path}</div>
38
+
39
+ <div class="row">
40
+ <button class="btn" id="home">Go to Home</button>
41
+ <button class="btn secondary" id="back">Go Back</button>
42
+ </div>
43
+ </div>
44
+ </div>
45
+ `;
46
+
47
+ this.shadowRoot.getElementById('home')?.addEventListener('click', () => {
48
+ const navigate = globalStates?.getState ? globalStates.getState('navigate') : null;
49
+ if (typeof navigate === 'function') navigate('home');
50
+ });
51
+
52
+ this.shadowRoot.getElementById('back')?.addEventListener('click', () => {
53
+ const goBack = globalStates?.getState ? globalStates.getState('go_back') : null;
54
+ if (typeof goBack === 'function') goBack();
55
+ else window.history.back();
56
+ });
57
+ }
58
+
59
+ styleSheet() {
60
+ return `
61
+ <style>
62
+ :host {
63
+ display: block;
64
+ width: 100%;
65
+ min-height: 100dvh;
66
+ font-family: var(--font);
67
+ }
68
+
69
+ * {
70
+ box-sizing: border-box;
71
+ font-family: inherit;
72
+ }
73
+
74
+ .wrap {
75
+ min-height: 100vh;
76
+ display: flex;
77
+ align-items: center;
78
+ justify-content: center;
79
+ padding: 18px;
80
+ }
81
+
82
+ .card {
83
+ width: min(680px, 100%);
84
+ background: transparent;
85
+ border: none;
86
+ border-radius: 18px;
87
+ padding: 18px;
88
+ box-shadow: none;
89
+ }
90
+
91
+ .code {
92
+ font-weight: 1000;
93
+ font-size: 44px;
94
+ line-height: 1;
95
+ color: var(--main_text);
96
+ }
97
+
98
+ .h {
99
+ margin-top: 10px;
100
+ font-weight: 1000;
101
+ font-size: 20px;
102
+ color: var(--main_text);
103
+ }
104
+
105
+ .p {
106
+ margin-top: 6px;
107
+ color: var(--sub_text);
108
+ font-weight: 800;
109
+ }
110
+
111
+ .path {
112
+ margin-top: 10px;
113
+ padding: 10px 12px;
114
+ border-radius: 14px;
115
+ background: var(--surface_2);
116
+ border: 1px solid var(--border_light);
117
+ font-weight: 900;
118
+ color: var(--main_text);
119
+ word-break: break-word;
120
+ }
121
+
122
+ .row {
123
+ margin-top: 14px;
124
+ display: flex;
125
+ gap: 10px;
126
+ flex-wrap: wrap;
127
+ }
128
+
129
+ .btn {
130
+ border: none;
131
+ background: linear-gradient(135deg, #0091ff 0%, #0073e6 100%);
132
+ color: #fff;
133
+ font-weight: 1000;
134
+ border-radius: 999px;
135
+ padding: 10px 14px;
136
+ cursor: pointer;
137
+ }
138
+
139
+ .btn:hover {
140
+ opacity: 0.9;
141
+ }
142
+
143
+ .btn.secondary {
144
+ background: var(--surface_2);
145
+ color: var(--main_text);
146
+ }
147
+
148
+ .btn.secondary:hover {
149
+ background: var(--surface_3);
150
+ }
151
+ </style>
152
+ `;
153
+ }
154
+ }
155
+
156
+ if (!customElements.get('sw-user-not-found-screen')) {
157
+ customElements.define('sw-user-not-found-screen', SwUserNotFoundScreen);
158
158
  }
@@ -1,16 +1,22 @@
1
- import { Tabs } from '/switch-framework/index.js';
1
+ import { TabLayout, registerComponents } from 'switch-framework';
2
+ import { SwTabBar } from '../../components/SwTabBar.js';
3
+ import { SwHomeScreen } from './index.js';
4
+ import { SwExploreScreen } from './explore.js';
2
5
 
3
- export const tabsLayout = Tabs({
4
- name: 'sw-tabs-layout',
5
- initialTab: 'home',
6
- tabs: [
6
+ registerComponents([SwTabBar]);
7
+
8
+ export class SwTabsLayout extends TabLayout {
9
+ static tag = 'sw-tabs-layout';
10
+ static initialTab = 'home';
11
+ static tabs = [
7
12
  {
8
13
  name: 'home',
9
14
  title: 'Home',
10
15
  icon: 'home',
11
16
  path: '/home',
12
17
  screen: 'sw-home-screen',
13
- match: ['home']
18
+ match: ['home'],
19
+ initialRoute: 'home'
14
20
  },
15
21
  {
16
22
  name: 'explore',
@@ -18,31 +24,15 @@ export const tabsLayout = Tabs({
18
24
  icon: 'compass',
19
25
  path: '/explore',
20
26
  screen: 'sw-explore-screen',
21
- match: ['explore']
27
+ match: ['explore'],
28
+ initialRoute: 'explore'
22
29
  }
23
- ],
24
- options: {
25
- position: 'bottom'
26
- }
27
- });
28
-
29
- export class SwTabsLayout extends HTMLElement {
30
- constructor() {
31
- super();
32
- this.attachShadow({ mode: 'open' });
33
- }
34
-
35
- connectedCallback() {
36
- this.render();
37
- }
38
-
39
- getContentContainer() {
40
- return this.shadowRoot.querySelector('.tabcontainer');
41
- }
30
+ ];
31
+ static options = { position: 'bottom' };
32
+ static screens = [SwHomeScreen, SwExploreScreen];
42
33
 
43
34
  render() {
44
- this.shadowRoot.innerHTML = `
45
- ${this.styleSheet()}
35
+ return `
46
36
  <div class="layout">
47
37
  <div class="tabcontainer"></div>
48
38
  <div class="tabbar">
@@ -54,72 +44,46 @@ export class SwTabsLayout extends HTMLElement {
54
44
 
55
45
  styleSheet() {
56
46
  return `
57
- <style>
58
- :host {
59
- display: flex;
60
- flex-direction: column;
61
- width: 100%;
62
- height: inherit;
63
- overflow: hidden;
64
- font-family: "Poppins", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif
65
- }
66
-
67
- * {
68
- box-sizing: border-box;
69
- font-family: inherit
70
- }
71
-
72
-
73
- .layout {
74
- min-height: 0;
75
- height: 100%;
76
- display: grid;
77
- grid-template-rows: minmax(0, 1fr) auto;
78
- overflow: hidden;
79
- }
80
-
81
- .tabbar {
82
- height: auto;
83
- position: sticky;
84
- bottom: 0;
85
- z-index: 50;
86
- }
87
-
88
-
89
- .tabcontainer {
90
- z-index: 1;
91
- min-height: 0;
92
- overflow: auto;
93
- overflow-x: hidden;
94
- padding-bottom: calc(12px + 56px + env(safe-area-inset-bottom, 0px));
95
- }
96
-
97
- </style>
47
+ <style>
48
+ :host {
49
+ display: flex;
50
+ flex-direction: column;
51
+ width: 100%;
52
+ height: inherit;
53
+ overflow: hidden;
54
+ font-family: "Poppins", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
55
+ }
56
+
57
+ * {
58
+ box-sizing: border-box;
59
+ font-family: inherit;
60
+ }
61
+
62
+ .layout {
63
+ min-height: 0;
64
+ height: 100%;
65
+ display: grid;
66
+ grid-template-rows: minmax(0, 1fr) auto;
67
+ overflow: hidden;
68
+ }
69
+
70
+ .tabbar {
71
+ height: auto;
72
+ position: sticky;
73
+ bottom: 0;
74
+ z-index: 50;
75
+ }
76
+
77
+ .tabcontainer {
78
+ z-index: 1;
79
+ min-height: 0;
80
+ overflow: auto;
81
+ overflow-x: hidden;
82
+ padding-bottom: calc(12px + 56px + env(safe-area-inset-bottom, 0px));
83
+ }
84
+ </style>
98
85
  `;
99
86
  }
100
87
  }
101
88
 
102
- if (!customElements.get('sw-tabs-layout')) {
103
- customElements.define('sw-tabs-layout', SwTabsLayout);
104
- }
105
-
106
- export const screens = [
107
- Tabs.screen({
108
- name: 'home',
109
- path: '/home',
110
- title: 'Home',
111
- tag: 'sw-home-screen',
112
- layout: 'tabs'
113
- }),
114
- Tabs.screen({
115
- name: 'explore',
116
- path: '/explore',
117
- title: 'Explore',
118
- tag: 'sw-explore-screen',
119
- layout: 'tabs'
120
- })
121
- ];
122
-
123
- tabsLayout.screens = screens;
124
-
125
- export default tabsLayout;
89
+ export default SwTabsLayout;