@webmate-studio/cli 0.1.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.
package/bin/wm.js ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from 'commander';
4
+ import { buildCommand } from '../src/commands/build.js';
5
+ import { pushCommand } from '../src/commands/push.js';
6
+ import { devCommand } from '../src/commands/dev.js';
7
+ import { initCommand } from '../src/commands/init.js';
8
+ import { loginCommand } from '../src/commands/login.js';
9
+ import { generate } from '../src/commands/generate.js';
10
+ import { prop } from '../src/commands/prop.js';
11
+ import { logout } from '../src/commands/logout.js';
12
+ import { info } from '../src/commands/info.js';
13
+ import { switchCommand } from '../src/commands/switch.js';
14
+
15
+ const program = new Command();
16
+
17
+ program
18
+ .name('wm')
19
+ .description('Webmate Component CLI - Build and manage HTML-first components')
20
+ .version('0.1.0');
21
+
22
+ // wm login - Login to CMS
23
+ program
24
+ .command('login')
25
+ .description('Login to Webmate CMS')
26
+ .option('-u, --url <url>', 'CMS base URL')
27
+ .action(loginCommand);
28
+
29
+ // wm init - Create new component project
30
+ program
31
+ .command('init')
32
+ .description('Initialize a new Webmate component project')
33
+ .argument('[directory]', 'Directory to initialize', '.')
34
+ .action(initCommand);
35
+
36
+ // wm generate (g) - Generate new component or island
37
+ program
38
+ .command('generate [type] [name]')
39
+ .alias('g')
40
+ .description('Generate a new component or island')
41
+ .option('--skip-wizard', 'Skip interactive wizard and create basic skeleton')
42
+ .option('--islands', 'Create component with islands support')
43
+ .option('--assets', 'Create component with assets directory')
44
+ .option('--template <framework>', 'Island framework template (vanilla|react|svelte|preact|alpine|lit)')
45
+ .option('--list-templates', 'List available island templates')
46
+ .action(generate);
47
+
48
+ // wm prop - Add property to component
49
+ program
50
+ .command('prop [filename]')
51
+ .description('Add a property to a component (interactive)')
52
+ .action(prop);
53
+
54
+ // wm dev - Start development server
55
+ program
56
+ .command('dev')
57
+ .description('Start development server with live preview')
58
+ .option('-p, --port <port>', 'Port to run on', '5173')
59
+ .option('-o, --open', 'Open browser automatically')
60
+ .action(devCommand);
61
+
62
+ // wm build - Build components
63
+ program
64
+ .command('build')
65
+ .description('Build components for production')
66
+ .option('-o, --output <dir>', 'Output directory', './dist')
67
+ .option('-m, --minify', 'Minify output')
68
+ .option('--watch', 'Watch for changes')
69
+ .action(buildCommand);
70
+
71
+ // wm push - Upload to CMS
72
+ program
73
+ .command('push')
74
+ .description('Upload components to CMS (auto-builds by default)')
75
+ .option('-t, --target <url>', 'CMS target URL')
76
+ .option('--token <token>', 'Authentication token')
77
+ .option('-f, --force', 'Overwrite existing version (development only)')
78
+ .option('--patch', 'Increment patch version (x.y.Z)')
79
+ .option('--minor', 'Increment minor version (x.Y.0)')
80
+ .option('--major', 'Increment major version (X.0.0)')
81
+ .option('--no-build', 'Skip auto-build, use existing dist/ (for CI/CD)')
82
+ .action(pushCommand);
83
+
84
+ // wm logout - Logout from CMS
85
+ program
86
+ .command('logout')
87
+ .description('Logout from Webmate CMS')
88
+ .action(logout);
89
+
90
+ // wm info - Show current project information
91
+ program
92
+ .command('info')
93
+ .description('Show current project information')
94
+ .action(info);
95
+
96
+ // wm switch - Switch to a different project
97
+ program
98
+ .command('switch')
99
+ .description('Switch to a different project')
100
+ .action(switchCommand);
101
+
102
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@webmate-studio/cli",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Webmate Studio CLI - Build and manage your Webmate components",
6
+ "keywords": ["webmate", "cms", "cli", "web-components", "islands"],
7
+ "author": "Michael Wischang",
8
+ "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/webmate-studio/cli.git"
12
+ },
13
+ "bin": {
14
+ "wm": "./bin/wm.js"
15
+ },
16
+ "exports": {
17
+ ".": "./src/index.js"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "dependencies": {
23
+ "@inquirer/prompts": "^5.0.0",
24
+ "alpinejs": "^3.15.0",
25
+ "commander": "^11.0.0",
26
+ "esbuild": "^0.19.0",
27
+ "esbuild-svelte": "^0.9.3",
28
+ "lit": "^3.3.1",
29
+ "ora": "^8.0.0",
30
+ "picocolors": "^1.0.0",
31
+ "preact": "^10.27.2",
32
+ "react": "^19.2.0",
33
+ "react-dom": "^19.2.0",
34
+ "svelte": "^5.41.2",
35
+ "vue": "^3.5.22"
36
+ }
37
+ }
@@ -0,0 +1,113 @@
1
+ import { build as buildComponents } from '../../../builder/src/index.js';
2
+ import { logger } from '../../../core/src/logger.js';
3
+ import { isLoggedIn, loadAuth, getTenantCmsUrl } from '../utils/auth.js';
4
+ import ora from 'ora';
5
+ import pc from 'picocolors';
6
+
7
+ /**
8
+ * Load design tokens from CMS
9
+ */
10
+ async function loadDesignTokens() {
11
+ try {
12
+ const auth = loadAuth();
13
+ if (!auth || !auth.apiToken) {
14
+ return null;
15
+ }
16
+
17
+ const cmsUrl = getTenantCmsUrl();
18
+ if (!cmsUrl) {
19
+ return null;
20
+ }
21
+
22
+ // Disable SSL verification for localhost
23
+ const isLocalhost = cmsUrl.includes('localhost') || cmsUrl.includes('127.0.0.1');
24
+ if (isLocalhost) {
25
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
26
+ }
27
+
28
+ const response = await fetch(`${cmsUrl}/api/design-tokens`, {
29
+ headers: {
30
+ 'x-api-token': auth.apiToken
31
+ }
32
+ });
33
+
34
+ if (!response.ok) {
35
+ logger.warn('Could not load design tokens from CMS');
36
+ return null;
37
+ }
38
+
39
+ const data = await response.json();
40
+
41
+ // Restore SSL verification
42
+ if (isLocalhost) {
43
+ delete process.env.NODE_TLS_REJECT_UNAUTHORIZED;
44
+ }
45
+
46
+ return data.tokens || null;
47
+ } catch (error) {
48
+ logger.warn(`Error loading design tokens: ${error.message}`);
49
+ return null;
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Build command - compile components to distribution
55
+ * Requires login for project context
56
+ */
57
+ export async function buildCommand(options) {
58
+ // Check if logged in
59
+ if (!isLoggedIn()) {
60
+ console.log('');
61
+ logger.error('Nicht eingeloggt.');
62
+ logger.info(`Bitte zuerst einloggen: ${pc.cyan('wm login')}`);
63
+ console.log('');
64
+ process.exit(1);
65
+ }
66
+
67
+ const auth = loadAuth();
68
+ logger.info(`Projekt: ${pc.cyan(auth.tenant.name)}`);
69
+
70
+ // Load design tokens from CMS
71
+ const designTokens = await loadDesignTokens();
72
+ if (designTokens) {
73
+ logger.success('Loaded design tokens from CMS');
74
+ } else {
75
+ logger.info('Using default design tokens');
76
+ }
77
+
78
+ const spinner = ora('Building components...').start();
79
+
80
+ try {
81
+ const manifest = await buildComponents({
82
+ outputDir: options.output,
83
+ minify: options.minify || false,
84
+ designTokens: designTokens // Pass design tokens to builder
85
+ });
86
+
87
+ spinner.succeed('Build complete!');
88
+
89
+ logger.info(`\nšŸ“¦ Built ${manifest.components.length} components`);
90
+ logger.info(`šŸ“ Output: ${options.output}`);
91
+
92
+ if (manifest.styles.length > 0) {
93
+ logger.info(`šŸŽØ Styles: ${manifest.styles.length} files`);
94
+ }
95
+
96
+ if (manifest.islands) {
97
+ logger.info(`šŸļø Islands: ${manifest.islands.files.length} files`);
98
+ }
99
+
100
+ // Show component list
101
+ console.log('\nšŸ“‹ Components:');
102
+ for (const comp of manifest.components) {
103
+ const propsCount = comp.props ? Object.keys(comp.props).length : 0;
104
+ logger.info(` • ${comp.name} (${propsCount} props)`);
105
+ }
106
+
107
+ return manifest;
108
+ } catch (error) {
109
+ spinner.fail('Build failed');
110
+ logger.error(error.message);
111
+ process.exit(1);
112
+ }
113
+ }
@@ -0,0 +1,29 @@
1
+ import { startPreviewServer } from '../../../preview/src/index.js';
2
+ import { logger } from '../../../core/src/index.js';
3
+ import { isLoggedIn, loadAuth } from '../utils/auth.js';
4
+ import pc from 'picocolors';
5
+
6
+ /**
7
+ * Dev command - start preview server
8
+ * Requires login to load design system CSS
9
+ */
10
+ export async function devCommand(options) {
11
+ // Check if logged in
12
+ if (!isLoggedIn()) {
13
+ console.log('');
14
+ logger.error('Nicht eingeloggt.');
15
+ logger.info(`Bitte zuerst einloggen: ${pc.cyan('wm login')}`);
16
+ console.log('');
17
+ process.exit(1);
18
+ }
19
+
20
+ const auth = loadAuth();
21
+ logger.info(`Projekt: ${pc.cyan(auth.tenant.name)}`);
22
+
23
+ try {
24
+ await startPreviewServer(options);
25
+ } catch (error) {
26
+ logger.error('Failed to start preview server:', error.message);
27
+ process.exit(1);
28
+ }
29
+ }