@linktr.ee/linkapp 0.0.1
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.
- package/bin/cli.js +6 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +52 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/add.d.ts +7 -0
- package/dist/commands/add.d.ts.map +1 -0
- package/dist/commands/add.js +141 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/build.d.ts +8 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +84 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/deploy.d.ts +12 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +158 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/dev.d.ts +7 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +73 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/login.d.ts +6 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +77 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +6 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +25 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/test-url-match-rules.d.ts +7 -0
- package/dist/commands/test-url-match-rules.d.ts.map +1 -0
- package/dist/commands/test-url-match-rules.js +55 -0
- package/dist/commands/test-url-match-rules.js.map +1 -0
- package/dist/lib/auth/config.d.ts +3 -0
- package/dist/lib/auth/config.d.ts.map +1 -0
- package/dist/lib/auth/config.js +5 -0
- package/dist/lib/auth/config.js.map +1 -0
- package/dist/lib/auth/device-flow.d.ts +15 -0
- package/dist/lib/auth/device-flow.d.ts.map +1 -0
- package/dist/lib/auth/device-flow.js +28 -0
- package/dist/lib/auth/device-flow.js.map +1 -0
- package/dist/lib/auth/fetch-config.d.ts +3 -0
- package/dist/lib/auth/fetch-config.d.ts.map +1 -0
- package/dist/lib/auth/fetch-config.js +15 -0
- package/dist/lib/auth/fetch-config.js.map +1 -0
- package/dist/lib/auth/token-storage.d.ts +10 -0
- package/dist/lib/auth/token-storage.d.ts.map +1 -0
- package/dist/lib/auth/token-storage.js +79 -0
- package/dist/lib/auth/token-storage.js.map +1 -0
- package/dist/lib/build/detect-layouts.d.ts +22 -0
- package/dist/lib/build/detect-layouts.d.ts.map +1 -0
- package/dist/lib/build/detect-layouts.js +58 -0
- package/dist/lib/build/detect-layouts.js.map +1 -0
- package/dist/lib/deploy/generate-manifest-files.d.ts +2 -0
- package/dist/lib/deploy/generate-manifest-files.d.ts.map +1 -0
- package/dist/lib/deploy/generate-manifest-files.js +81 -0
- package/dist/lib/deploy/generate-manifest-files.js.map +1 -0
- package/dist/lib/deploy/pack-project.d.ts +7 -0
- package/dist/lib/deploy/pack-project.d.ts.map +1 -0
- package/dist/lib/deploy/pack-project.js +76 -0
- package/dist/lib/deploy/pack-project.js.map +1 -0
- package/dist/lib/deploy/test-url-match-rules.d.ts +6 -0
- package/dist/lib/deploy/test-url-match-rules.d.ts.map +1 -0
- package/dist/lib/deploy/test-url-match-rules.js +21 -0
- package/dist/lib/deploy/test-url-match-rules.js.map +1 -0
- package/dist/lib/deploy/upload.d.ts +12 -0
- package/dist/lib/deploy/upload.d.ts.map +1 -0
- package/dist/lib/deploy/upload.js +90 -0
- package/dist/lib/deploy/upload.js.map +1 -0
- package/dist/lib/deploy/validation.d.ts +9 -0
- package/dist/lib/deploy/validation.d.ts.map +1 -0
- package/dist/lib/deploy/validation.js +160 -0
- package/dist/lib/deploy/validation.js.map +1 -0
- package/dist/lib/utils/create-project.d.ts +8 -0
- package/dist/lib/utils/create-project.d.ts.map +1 -0
- package/dist/lib/utils/create-project.js +48 -0
- package/dist/lib/utils/create-project.js.map +1 -0
- package/dist/lib/utils/init-git.d.ts +2 -0
- package/dist/lib/utils/init-git.d.ts.map +1 -0
- package/dist/lib/utils/init-git.js +34 -0
- package/dist/lib/utils/init-git.js.map +1 -0
- package/dist/lib/utils/install-dependencies.d.ts +2 -0
- package/dist/lib/utils/install-dependencies.d.ts.map +1 -0
- package/dist/lib/utils/install-dependencies.js +20 -0
- package/dist/lib/utils/install-dependencies.js.map +1 -0
- package/dist/lib/utils/setup-runtime.d.ts +6 -0
- package/dist/lib/utils/setup-runtime.d.ts.map +1 -0
- package/dist/lib/utils/setup-runtime.js +103 -0
- package/dist/lib/utils/setup-runtime.js.map +1 -0
- package/dist/lib/vite/config-factory.d.ts +12 -0
- package/dist/lib/vite/config-factory.d.ts.map +1 -0
- package/dist/lib/vite/config-factory.js +55 -0
- package/dist/lib/vite/config-factory.js.map +1 -0
- package/dist/lib/vite/plugins/asset-versioning.d.ts +11 -0
- package/dist/lib/vite/plugins/asset-versioning.d.ts.map +1 -0
- package/dist/lib/vite/plugins/asset-versioning.js +50 -0
- package/dist/lib/vite/plugins/asset-versioning.js.map +1 -0
- package/dist/lib/vite/plugins/route-handler.d.ts +16 -0
- package/dist/lib/vite/plugins/route-handler.d.ts.map +1 -0
- package/dist/lib/vite/plugins/route-handler.js +108 -0
- package/dist/lib/vite/plugins/route-handler.js.map +1 -0
- package/dist/lib/vite/plugins/window-context.d.ts +7 -0
- package/dist/lib/vite/plugins/window-context.d.ts.map +1 -0
- package/dist/lib/vite/plugins/window-context.js +68 -0
- package/dist/lib/vite/plugins/window-context.js.map +1 -0
- package/dist/schema/config.schema.d.ts +229 -0
- package/dist/schema/config.schema.d.ts.map +1 -0
- package/dist/schema/config.schema.js +116 -0
- package/dist/schema/config.schema.js.map +1 -0
- package/dist/schema/index.d.ts +8 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +8 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/types.d.ts +140 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +70 -0
- package/runtime/index.html +12 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join, dirname } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { detectLayouts } from '../build/detect-layouts.js';
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = dirname(__filename);
|
|
7
|
+
/**
|
|
8
|
+
* Generates main.tsx content with detected layouts
|
|
9
|
+
*/
|
|
10
|
+
function generateMainTsx(projectPath) {
|
|
11
|
+
const detection = detectLayouts(projectPath);
|
|
12
|
+
const layouts = detection.layouts;
|
|
13
|
+
// Generate import statements for each layout
|
|
14
|
+
const imports = layouts
|
|
15
|
+
.map(layout => `import ${layout.displayName} from '/app/${layout.fileName}'`)
|
|
16
|
+
.join('\n');
|
|
17
|
+
// Generate layouts object
|
|
18
|
+
const layoutsObj = layouts
|
|
19
|
+
.map(layout => ` ${layout.name}: ${layout.displayName},`)
|
|
20
|
+
.join('\n');
|
|
21
|
+
return `import { StrictMode } from 'react'
|
|
22
|
+
import { createRoot } from 'react-dom/client'
|
|
23
|
+
import Layout from '/app/layout'
|
|
24
|
+
${imports}
|
|
25
|
+
import '/app/globals.css'
|
|
26
|
+
|
|
27
|
+
// Map of available layouts
|
|
28
|
+
const layouts: Record<string, React.ComponentType<any>> = {
|
|
29
|
+
${layoutsObj}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function App() {
|
|
33
|
+
// Get layout from query parameter
|
|
34
|
+
const params = new URLSearchParams(window.location.search)
|
|
35
|
+
const layoutName = params.get('layout') || 'classic'
|
|
36
|
+
|
|
37
|
+
// Get the layout component
|
|
38
|
+
const LayoutComponent = layouts[layoutName] || layouts.classic
|
|
39
|
+
|
|
40
|
+
if (!LayoutComponent) {
|
|
41
|
+
return (
|
|
42
|
+
<div style={{ padding: '20px', fontFamily: 'system-ui' }}>
|
|
43
|
+
<h1>Error: Layout not found</h1>
|
|
44
|
+
<p>Layout "{layoutName}" does not exist.</p>
|
|
45
|
+
<p>Available layouts: {Object.keys(layouts).join(', ')}</p>
|
|
46
|
+
</div>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Mock context for development
|
|
51
|
+
const mockContext = {
|
|
52
|
+
linkUrl: 'https://example.com/demo',
|
|
53
|
+
showTitle: true,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Layout>
|
|
58
|
+
<LayoutComponent {...mockContext} />
|
|
59
|
+
</Layout>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const rootElement = document.getElementById('root')
|
|
64
|
+
if (!rootElement) {
|
|
65
|
+
throw new Error('Root element not found')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
createRoot(rootElement).render(
|
|
69
|
+
<StrictMode>
|
|
70
|
+
<App />
|
|
71
|
+
</StrictMode>
|
|
72
|
+
)
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sets up runtime files (.linkapp directory) in the user's project
|
|
77
|
+
* These files are managed by the CLI and should not be edited by users
|
|
78
|
+
*/
|
|
79
|
+
export function setupRuntime(projectPath) {
|
|
80
|
+
try {
|
|
81
|
+
const linkappDir = join(projectPath, '.linkapp');
|
|
82
|
+
const runtimeSourceDir = join(__dirname, '..', '..', '..', 'runtime');
|
|
83
|
+
// Create .linkapp directory if it doesn't exist
|
|
84
|
+
if (!existsSync(linkappDir)) {
|
|
85
|
+
mkdirSync(linkappDir, { recursive: true });
|
|
86
|
+
}
|
|
87
|
+
// Copy index.html
|
|
88
|
+
const indexHtmlPath = join(runtimeSourceDir, 'index.html');
|
|
89
|
+
if (!existsSync(indexHtmlPath)) {
|
|
90
|
+
throw new Error(`Runtime file not found: ${indexHtmlPath}`);
|
|
91
|
+
}
|
|
92
|
+
const indexHtml = readFileSync(indexHtmlPath, 'utf-8');
|
|
93
|
+
writeFileSync(join(linkappDir, 'index.html'), indexHtml, 'utf-8');
|
|
94
|
+
// Generate and write main.tsx dynamically based on detected layouts
|
|
95
|
+
const mainTsx = generateMainTsx(projectPath);
|
|
96
|
+
writeFileSync(join(linkappDir, 'main.tsx'), mainTsx, 'utf-8');
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
console.error('Failed to setup runtime files:', error);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=setup-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-runtime.js","sourceRoot":"","sources":["../../../src/lib/utils/setup-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE1D,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACjD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAErC;;GAEG;AACH,SAAS,eAAe,CAAC,WAAmB;IAC1C,MAAM,SAAS,GAAG,aAAa,CAAC,WAAW,CAAC,CAAA;IAC5C,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAA;IAEjC,6CAA6C;IAC7C,MAAM,OAAO,GAAG,OAAO;SACpB,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,MAAM,CAAC,WAAW,eAAe,MAAM,CAAC,QAAQ,GAAG,CAAC;SAC5E,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,0BAA0B;IAC1B,MAAM,UAAU,GAAG,OAAO;SACvB,GAAG,CAAC,MAAM,CA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gC,EAAE,KAAK,CAAC,CAAA;QACtD,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InlineConfig } from 'vite';
|
|
2
|
+
interface ViteConfigOptions {
|
|
3
|
+
mode: 'development' | 'production';
|
|
4
|
+
port?: number;
|
|
5
|
+
host?: string;
|
|
6
|
+
open?: boolean;
|
|
7
|
+
sourcemap?: boolean;
|
|
8
|
+
profile?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function createViteConfig(options: ViteConfigOptions): InlineConfig;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=config-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-factory.d.ts","sourceRoot":"","sources":["../../../src/lib/vite/config-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAMxC,UAAU,iBAAiB;IACzB,IAAI,EAAE,aAAa,GAAG,YAAY,CAAA;IAClC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,YAAY,CAgEzE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import react from '@vitejs/plugin-react';
|
|
2
|
+
import { resolve, join } from 'node:path';
|
|
3
|
+
import { assetVersioning } from './plugins/asset-versioning.js';
|
|
4
|
+
import { setupRuntime } from '../utils/setup-runtime.js';
|
|
5
|
+
export function createViteConfig(options) {
|
|
6
|
+
const { mode, port = 3000, host = 'localhost', open = false, sourcemap = false, profile = false, } = options;
|
|
7
|
+
const isDev = mode === 'development';
|
|
8
|
+
const projectRoot = process.cwd();
|
|
9
|
+
// Setup runtime files in user's project
|
|
10
|
+
setupRuntime(projectRoot);
|
|
11
|
+
const config = {
|
|
12
|
+
mode,
|
|
13
|
+
root: projectRoot,
|
|
14
|
+
plugins: [react()],
|
|
15
|
+
resolve: {
|
|
16
|
+
alias: {
|
|
17
|
+
'@': resolve(projectRoot, 'src'),
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
build: {
|
|
21
|
+
outDir: 'dist',
|
|
22
|
+
sourcemap: sourcemap ? 'hidden' : false,
|
|
23
|
+
minify: !isDev,
|
|
24
|
+
rollupOptions: {
|
|
25
|
+
input: join(projectRoot, '.linkapp', 'index.html'),
|
|
26
|
+
output: {
|
|
27
|
+
entryFileNames: '[name].[hash].js',
|
|
28
|
+
chunkFileNames: '[name].[hash].js',
|
|
29
|
+
assetFileNames: '[name].[hash].[ext]',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
server: {
|
|
34
|
+
port,
|
|
35
|
+
host,
|
|
36
|
+
open,
|
|
37
|
+
cors: true,
|
|
38
|
+
strictPort: false,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
// Add production-only plugins
|
|
42
|
+
if (!isDev) {
|
|
43
|
+
config.plugins?.push(assetVersioning({
|
|
44
|
+
manifestPath: 'build-manifest.json',
|
|
45
|
+
}));
|
|
46
|
+
// Add bundle analyzer if requested
|
|
47
|
+
if (profile) {
|
|
48
|
+
// Note: rollup-plugin-visualizer support disabled in ES module context
|
|
49
|
+
// To enable bundle analysis, use --sourcemap flag and analyze with external tools
|
|
50
|
+
console.warn('⚠️ Bundle profiling is not available in this version. Use --sourcemap flag and analyze with external tools.');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return config;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=config-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-factory.js","sourceRoot":"","sources":["../../../src/lib/vite/config-factory.ts"],"names":[],"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IAED,8BAA8B;IAC9B,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,CAAC,OAAO,EAAE,IAAI,CAClB,eAAe,CAAC;YACd,YAAY,EAAE,qBAAqB;SACpC,CAAC,CACH,CAAA;QAED,mCAAmC;QACnC,IAAI,OAAO,EAAE,CAAC;YACZ,uEAAuE;YACvE,kFAAkF;YAClF,OAAO,CAAC,IAAI,CAAC,8GAA8G,CAAC,CAAA;QAC9H,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
interface AssetVersioningOptions {
|
|
3
|
+
manifestPath?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Vite plugin that creates a build manifest with versioned assets
|
|
7
|
+
* This helps invalidate cache on deployment
|
|
8
|
+
*/
|
|
9
|
+
export declare function assetVersioning(options?: AssetVersioningOptions): Plugin;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=asset-versioning.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-versioning.d.ts","sourceRoot":"","sources":["../../../../src/lib/vite/plugins/asset-versioning.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC,UAAU,sBAAsB;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,MAAM,CA+C5E"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
/**
|
|
5
|
+
* Vite plugin that creates a build manifest with versioned assets
|
|
6
|
+
* This helps invalidate cache on deployment
|
|
7
|
+
*/
|
|
8
|
+
export function assetVersioning(options = {}) {
|
|
9
|
+
const manifestPath = options.manifestPath || 'build-manifest.json';
|
|
10
|
+
const manifest = {};
|
|
11
|
+
return {
|
|
12
|
+
name: 'linkapp:asset-versioning',
|
|
13
|
+
enforce: 'post',
|
|
14
|
+
generateBundle(_options, bundle) {
|
|
15
|
+
// Collect all asset mappings
|
|
16
|
+
for (const [fileName, asset] of Object.entries(bundle)) {
|
|
17
|
+
if (asset.type === 'asset' || asset.type === 'chunk') {
|
|
18
|
+
// Store original name -> hashed name mapping
|
|
19
|
+
const originalName = fileName.replace(/\.[a-f0-9]+\./, '.');
|
|
20
|
+
manifest[originalName] = fileName;
|
|
21
|
+
// Add metadata
|
|
22
|
+
if (asset.type === 'chunk' && asset.isEntry) {
|
|
23
|
+
manifest[`${originalName}.entry`] = 'true';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// Add build timestamp
|
|
28
|
+
manifest['_buildTime'] = new Date().toISOString();
|
|
29
|
+
manifest['_buildHash'] = createHash('sha256').update(JSON.stringify(manifest)).digest('hex').slice(0, 8);
|
|
30
|
+
// Emit manifest file
|
|
31
|
+
this.emitFile({
|
|
32
|
+
type: 'asset',
|
|
33
|
+
fileName: manifestPath,
|
|
34
|
+
source: JSON.stringify(manifest, null, 2),
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
closeBundle() {
|
|
38
|
+
// Also write manifest to disk for deployment process
|
|
39
|
+
const outDir = process.env.VITE_OUT_DIR || 'dist';
|
|
40
|
+
const fullPath = join(process.cwd(), outDir, manifestPath);
|
|
41
|
+
try {
|
|
42
|
+
writeFileSync(fullPath, JSON.stringify(manifest, null, 2));
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.warn('Failed to write build manifest:', error);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=asset-versioning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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S,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;YAExG,qBAAqB;YACrB,IAAI,CAAC,QAAQ,CAAC;gBACZ,IAAI,EAAE,OAAO;gBACb,QAAQ,EAAE,YAAY;gBACtB,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;aAC1C,CAAC,CAAA;QACJ,CAAC;QAED,WAAW;YACT,qDAAqD;YACrD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,MAAM,CAAA;YACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,YAAY,CAAC,CAAA;YAE1D,IAAI,CAAC;gBACH,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;YAC5D,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,IAAI,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAA;YACxD,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
interface RouteHandlerOptions {
|
|
3
|
+
userProjectPath: string;
|
|
4
|
+
previewPath: string;
|
|
5
|
+
devServerOrigin: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Vite plugin that handles multiple routes in a single dev server
|
|
9
|
+
* Routes:
|
|
10
|
+
* / → Preview UI (linkapp-preview)
|
|
11
|
+
* /classic, /featured, etc. → User layouts (runtime)
|
|
12
|
+
* /layouts.json → JSON endpoint
|
|
13
|
+
*/
|
|
14
|
+
export declare function routeHandler(options: RouteHandlerOptions): Plugin;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=route-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-handler.d.ts","sourceRoot":"","sources":["../../../../src/lib/vite/plugins/route-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAA;AASjD,UAAU,mBAAmB;IAC3B,eAAe,EAAE,MAAM,CAAA;IACvB,WAAW,EAAE,MAAM,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CA6GjE"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join, dirname } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { detectLayouts } from '../../build/detect-layouts.js';
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = dirname(__filename);
|
|
7
|
+
/**
|
|
8
|
+
* Vite plugin that handles multiple routes in a single dev server
|
|
9
|
+
* Routes:
|
|
10
|
+
* / → Preview UI (linkapp-preview)
|
|
11
|
+
* /classic, /featured, etc. → User layouts (runtime)
|
|
12
|
+
* /layouts.json → JSON endpoint
|
|
13
|
+
*/
|
|
14
|
+
export function routeHandler(options) {
|
|
15
|
+
const { userProjectPath, previewPath, devServerOrigin } = options;
|
|
16
|
+
// Read HTML templates
|
|
17
|
+
const previewHtmlPath = join(previewPath, 'index.html');
|
|
18
|
+
const runtimeHtmlPath = join(__dirname, '../../../../runtime/index.html');
|
|
19
|
+
return {
|
|
20
|
+
name: 'linkapp:route-handler',
|
|
21
|
+
configureServer(server) {
|
|
22
|
+
// Add middleware before Vite's internal middleware
|
|
23
|
+
server.middlewares.use((req, res, next) => {
|
|
24
|
+
const url = req.url || '/';
|
|
25
|
+
const pathname = url.split('?')[0];
|
|
26
|
+
// Handle /layouts.json endpoint
|
|
27
|
+
if (pathname === '/layouts.json') {
|
|
28
|
+
try {
|
|
29
|
+
const detection = detectLayouts(userProjectPath);
|
|
30
|
+
res.statusCode = 200;
|
|
31
|
+
res.setHeader('Content-Type', 'application/json');
|
|
32
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
33
|
+
res.end(JSON.stringify({
|
|
34
|
+
layouts: detection.layouts,
|
|
35
|
+
devServerUrl: devServerOrigin,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error('Failed to read layouts:', error);
|
|
40
|
+
res.statusCode = 500;
|
|
41
|
+
res.setHeader('Content-Type', 'application/json');
|
|
42
|
+
res.end(JSON.stringify({ error: 'Failed to read layouts' }));
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// Get available layouts
|
|
47
|
+
let layouts = [];
|
|
48
|
+
try {
|
|
49
|
+
layouts = detectLayouts(userProjectPath).layouts;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.error('Failed to detect layouts:', error);
|
|
53
|
+
}
|
|
54
|
+
// Check if this is a layout route
|
|
55
|
+
const matchedLayout = layouts.find(layout => pathname === `/${layout.name}`);
|
|
56
|
+
if (matchedLayout) {
|
|
57
|
+
// Serve runtime HTML with layout query param
|
|
58
|
+
try {
|
|
59
|
+
let html = readFileSync(runtimeHtmlPath, 'utf-8');
|
|
60
|
+
// Add layout query param to the script src
|
|
61
|
+
html = html.replace('src="/.linkapp/main.tsx"', `src="/.linkapp/main.tsx?layout=${matchedLayout.name}"`);
|
|
62
|
+
res.statusCode = 200;
|
|
63
|
+
res.setHeader('Content-Type', 'text/html');
|
|
64
|
+
res.end(html);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.error('Failed to serve runtime HTML:', error);
|
|
68
|
+
next();
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// Serve preview HTML at root
|
|
73
|
+
if (pathname === '/') {
|
|
74
|
+
try {
|
|
75
|
+
// Read preview HTML from linkapp-preview package
|
|
76
|
+
const html = readFileSync(previewHtmlPath, 'utf-8');
|
|
77
|
+
res.statusCode = 200;
|
|
78
|
+
res.setHeader('Content-Type', 'text/html');
|
|
79
|
+
res.end(html);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
console.error('Failed to serve preview HTML:', error);
|
|
83
|
+
next();
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// Let Vite handle everything else
|
|
88
|
+
next();
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
// Transform HTML to handle module resolution
|
|
92
|
+
transformIndexHtml: {
|
|
93
|
+
order: 'pre',
|
|
94
|
+
handler(html, ctx) {
|
|
95
|
+
const url = ctx.originalUrl || '/';
|
|
96
|
+
const pathname = url.split('?')[0];
|
|
97
|
+
// For preview route, update paths to use linkapp-preview alias
|
|
98
|
+
if (pathname === '/') {
|
|
99
|
+
return html
|
|
100
|
+
.replace('href="/src/index.css"', 'href="/linkapp-preview/src/index.css"')
|
|
101
|
+
.replace('src="/src/main.tsx"', 'src="/linkapp-preview/src/main.tsx"');
|
|
102
|
+
}
|
|
103
|
+
return html;
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=route-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-handler.js","sourceRoot":"","sources":["../../../../src/lib/vite/plugins/route-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA;AAE7D,MAAM,UAAU,GAAG,aAAa,CAAC,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,CAAC;gBAED,6BAA6B;gBAC7B,IAAI,QAAQ,KAAK,GAAG,EAAE,CAAC;oBACrB,IAAI,CAAC;wBACH,iDAAiD;wBACjD,MAAM,IAAI,GAAG,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAA;wBAEnD,GAAG,CAAC,UAAU,GAAG,GAAG,CAAA;wBACpB,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,CAAA;wBAC1C,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;oBACf,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAA;wBACrD,IAAI,EAAE,CAAA;oBACR,CAAC;oBACD,OAAM;gBACR,CAAC;gBAED,kCAAkC;gBAClC,IAAI,EAAE,CAAA;YACR,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,6CAA6C;QAC7C,kBAAkB,EAAE;YAClB,KAAK,EAAE,KAAK;YACZ,OAAO,CAAC,IAAI,EAAE,GAAG;gBACf,MAAM,GAAG,GAAG,GAAG,CAAC,WAAW,IAAI,GAAG,CAAA;gBAClC,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;gBAElC,+DAA+D;gBAC/D,IAAI,QAAQ,KAAK,GAAG,EAAE,CAAC;oBACrB,OAAO,IAAI;yBACR,OAAO,CAAC,uBAAuB,EAAE,uCAAuC,CAAC;yBACzE,OAAO,CAAC,qBAAqB,EAAE,qCAAqC,CAAC,CAAA;gBAC1E,CAAC;gBAED,OAAO,IAAI,CAAA;YACb,CAAC;SACF;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Vite plugin that injects window.linktree context for development
|
|
4
|
+
* In production, this is handled by the parent Linktree frame
|
|
5
|
+
*/
|
|
6
|
+
export declare function windowContext(): Plugin;
|
|
7
|
+
//# sourceMappingURL=window-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"window-context.d.ts","sourceRoot":"","sources":["../../../../src/lib/vite/plugins/window-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAIlC;;;GAGG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAkEtC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
/**
|
|
4
|
+
* Vite plugin that injects window.linktree context for development
|
|
5
|
+
* In production, this is handled by the parent Linktree frame
|
|
6
|
+
*/
|
|
7
|
+
export function windowContext() {
|
|
8
|
+
return {
|
|
9
|
+
name: 'linkapp:window-context',
|
|
10
|
+
transformIndexHtml: {
|
|
11
|
+
order: 'pre',
|
|
12
|
+
async handler(html) {
|
|
13
|
+
// Only inject in development
|
|
14
|
+
if (process.env.NODE_ENV === 'production') {
|
|
15
|
+
return html;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const configPath = join(process.cwd(), 'linkapp.config.ts');
|
|
19
|
+
const configUrl = pathToFileURL(configPath).href;
|
|
20
|
+
// Dynamic import the config
|
|
21
|
+
const { default: config } = await import(configUrl);
|
|
22
|
+
const previewProps = config.previewProps || {};
|
|
23
|
+
// Inject window.linktree with preview props
|
|
24
|
+
const script = `
|
|
25
|
+
<script>
|
|
26
|
+
// Development context - in production this comes from parent frame
|
|
27
|
+
window.linktree = ${JSON.stringify(previewProps, null, 2)};
|
|
28
|
+
|
|
29
|
+
// Apply theme CSS variables
|
|
30
|
+
if (window.linktree?.theme) {
|
|
31
|
+
const theme = window.linktree.theme;
|
|
32
|
+
document.documentElement.style.setProperty('--linktree-bg-color', theme.backgroundColor);
|
|
33
|
+
document.documentElement.style.setProperty('--linktree-text-color', theme.textColor);
|
|
34
|
+
document.documentElement.style.setProperty('--linktree-border-color', theme.borderColor);
|
|
35
|
+
document.documentElement.style.setProperty('--linktree-border-radius', theme.borderRadius);
|
|
36
|
+
}
|
|
37
|
+
</script>`;
|
|
38
|
+
return html.replace('</head>', `${script}</head>`);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.warn('Failed to load config, using defaults:', error);
|
|
42
|
+
// Fallback to minimal context
|
|
43
|
+
const fallbackScript = `
|
|
44
|
+
<script>
|
|
45
|
+
window.linktree = {
|
|
46
|
+
linkUrl: 'https://example.com',
|
|
47
|
+
theme: {
|
|
48
|
+
textColor: '#000000',
|
|
49
|
+
backgroundColor: '#ffffff',
|
|
50
|
+
borderRadius: '12px',
|
|
51
|
+
borderColor: '#e5e7eb',
|
|
52
|
+
isOutlineStyle: false,
|
|
53
|
+
contrastColor: '#ffffff',
|
|
54
|
+
textHoverColor: '#111827'
|
|
55
|
+
},
|
|
56
|
+
locale: 'en-US',
|
|
57
|
+
currency: 'USD',
|
|
58
|
+
username: 'dev-user',
|
|
59
|
+
viewport: { width: 680, height: 800 }
|
|
60
|
+
};
|
|
61
|
+
</script>`;
|
|
62
|
+
return html.replace('</head>', `${fallbackScript}</head>`);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=window-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"window-context.js","sourceRoot":"","sources":["../../../../src/lib/vite/plugins/window-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO;QACL,IAAI,EAAE,wBAAwB;QAE9B,kBAAkB,EAAE;YAClB,KAAK,EAAE,KAAK;YACZ,KAAK,CAAC,OAAO,CAAC,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