zoho-sites-dev-cli 0.0.0-stage → 1.0.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 (52) hide show
  1. package/README.md +401 -2
  2. package/bin/zoho-sites-dev-cli.js +107 -0
  3. package/config/default.json +18 -0
  4. package/index.js +6 -0
  5. package/package.json +55 -4
  6. package/src/commands/auth.js +136 -0
  7. package/src/commands/create.js +175 -0
  8. package/src/commands/deploy.js +380 -0
  9. package/src/commands/generate-zip.js +49 -0
  10. package/src/commands/index.js +23 -0
  11. package/src/commands/init-tailwind.js +57 -0
  12. package/src/commands/init.js +448 -0
  13. package/src/commands/install.js +89 -0
  14. package/src/commands/login.js +248 -0
  15. package/src/commands/pull.js +41 -0
  16. package/src/commands/serve.js +162 -0
  17. package/src/compilers/css-compiler.js +230 -0
  18. package/src/compilers/css-ignore-loader.js +33 -0
  19. package/src/compilers/plugins/index.js +12 -0
  20. package/src/compilers/plugins/root-selector-transform-plugin.js +79 -0
  21. package/src/compilers/tailwind-compiler.js +102 -0
  22. package/src/compilers/webpack-compiler.js +512 -0
  23. package/src/compilers/webpack-config.js +103 -0
  24. package/src/config/constants.js +125 -0
  25. package/src/config/environments/audiences.js +19 -0
  26. package/src/config/environments/index.js +78 -0
  27. package/src/config/environments/internal.js +72 -0
  28. package/src/config/environments/production.js +39 -0
  29. package/src/locales/en.json +216 -0
  30. package/src/services/devServer.js +489 -0
  31. package/src/services/oauthService.js +672 -0
  32. package/src/templates/component/fields.json +6 -0
  33. package/src/templates/component/index.js +11 -0
  34. package/src/templates/component/llm.md +9 -0
  35. package/src/templates/component/meta.json +9 -0
  36. package/src/templates/component/styles.css +3 -0
  37. package/src/templates/oauth/complete.html +41 -0
  38. package/src/templates/oauth/error.html +69 -0
  39. package/src/templates/oauth/invalid-request.html +58 -0
  40. package/src/templates/oauth/loading.html +80 -0
  41. package/src/templates/oauth/not-found.html +33 -0
  42. package/src/templates/oauth/success.html +70 -0
  43. package/src/templates/oauth/timeout.html +56 -0
  44. package/src/templates/oauth/token-error.html +57 -0
  45. package/src/utils/configUtil.js +66 -0
  46. package/src/utils/httpUtil.js +351 -0
  47. package/src/utils/i18n.js +205 -0
  48. package/src/utils/loadingUtil.js +190 -0
  49. package/src/utils/secureConfig.js +75 -0
  50. package/src/utils/secureStorage.js +230 -0
  51. package/src/utils/templateLoader.js +89 -0
  52. package/src/utils/urlUtil.js +371 -0
@@ -0,0 +1,33 @@
1
+ /**
2
+ * CSS Ignore Loader
3
+ *
4
+ * This loader is used to handle CSS imports in component files during webpack compilation.
5
+ * In the ZS SDK architecture, CSS files are processed separately using PostCSS and combined
6
+ * into a single dist/styles.css file. Therefore, CSS imports in JavaScript files should be
7
+ * ignored during webpack compilation.
8
+ *
9
+ * Usage in webpack config:
10
+ * {
11
+ * test: /\.css$/,
12
+ * use: [{ loader: path.resolve(__dirname, 'css-ignore-loader.js') }]
13
+ * }
14
+ */
15
+
16
+ const { i18n } = require("../utils/i18n.js");
17
+
18
+ let warningShown = false;
19
+
20
+ module.exports = function cssIgnoreLoader(source) {
21
+ const resourcePath = this.resourcePath;
22
+
23
+ // Show warning once about CSS imports (not for every file)
24
+ if (!warningShown) {
25
+ warningShown = true;
26
+ i18n.warning("compile.cssImportWarning");
27
+ }
28
+
29
+ // Return an empty module export
30
+ // This prevents webpack from trying to parse CSS as JavaScript
31
+ return "module.exports = {};";
32
+ };
33
+
@@ -0,0 +1,12 @@
1
+ /**
2
+ * PostCSS Plugins
3
+ *
4
+ * This module exports PostCSS plugins used by the CSS compiler
5
+ * for transforming CSS selectors and rules.
6
+ */
7
+
8
+ const { createRootSelectorTransformPlugin } = require('./root-selector-transform-plugin.js');
9
+
10
+ module.exports = {
11
+ createRootSelectorTransformPlugin
12
+ };
@@ -0,0 +1,79 @@
1
+ /**
2
+ * PostCSS Plugin: Root Selector Transformer
3
+ *
4
+ * This plugin transforms :root selectors to component-specific selectors
5
+ * instead of throwing errors, allowing CSS custom properties to be scoped
6
+ * to components while maintaining their functionality.
7
+ */
8
+
9
+ /**
10
+ * Creates a PostCSS plugin to transform :root selectors to component-specific selectors
11
+ * @param {string} componentPrefix - The component prefix to use for transformation
12
+ * @returns {Object} PostCSS plugin object
13
+ */
14
+ const createRootSelectorTransformPlugin = (componentPrefix) => {
15
+ return {
16
+ postcssPlugin: 'root-selector-transformer',
17
+ Rule(rule) {
18
+ // Skip @rules (media queries, keyframes, etc.)
19
+ if (rule.parent && rule.parent.type === 'atrule') {
20
+ return;
21
+ }
22
+
23
+ // Skip root-level @rules
24
+ if (rule.selector && rule.selector.startsWith('@')) {
25
+ return;
26
+ }
27
+
28
+ // Transform :root selectors to component-specific selectors
29
+ if (rule.selector && rule.selector.includes(':root')) {
30
+ const selectors = rule.selector.split(',').map(s => s.trim());
31
+ const transformedSelectors = selectors.map(selector => {
32
+ // Replace :root with the component prefix
33
+ if (selector === ':root') {
34
+ return componentPrefix;
35
+ }
36
+
37
+ // Handle cases where :root is part of a compound selector
38
+ if (selector.includes(':root')) {
39
+ return selector.replace(/:root/g, componentPrefix);
40
+ }
41
+
42
+ return selector;
43
+ });
44
+
45
+ rule.selector = transformedSelectors.join(', ');
46
+ }
47
+ },
48
+ AtRule(atrule) {
49
+ // Handle :root inside @media queries and other at-rules
50
+ if (atrule.nodes) {
51
+ atrule.nodes.forEach(node => {
52
+ if (node.type === 'rule' && node.selector && node.selector.includes(':root')) {
53
+ const selectors = node.selector.split(',').map(s => s.trim());
54
+ const transformedSelectors = selectors.map(selector => {
55
+ // Replace :root with the component prefix
56
+ if (selector === ':root') {
57
+ return componentPrefix;
58
+ }
59
+
60
+ // Handle cases where :root is part of a compound selector
61
+ if (selector.includes(':root')) {
62
+ return selector.replace(/:root/g, componentPrefix);
63
+ }
64
+
65
+ return selector;
66
+ });
67
+
68
+ node.selector = transformedSelectors.join(', ');
69
+ }
70
+ });
71
+ }
72
+ }
73
+ };
74
+ };
75
+
76
+ // Set the postcss property for compatibility
77
+ createRootSelectorTransformPlugin.postcss = true;
78
+
79
+ module.exports = { createRootSelectorTransformPlugin };
@@ -0,0 +1,102 @@
1
+ // tailwind-compiler.js - Build Tailwind CSS with namespace scoping for widgets
2
+ // Tailwind is required from the SDK's node_modules; user project only provides tailwind.config.js
3
+
4
+ const path = require("path");
5
+ const fs = require("fs");
6
+ const postcss = require("postcss");
7
+ const postcssPrefixSelector = require("postcss-prefix-selector");
8
+ const cssnano = require("cssnano");
9
+ const {
10
+ TAILWIND_CONFIG_FILE,
11
+ TAILWIND_CONFIG_CJS
12
+ } = require("../config/constants.js");
13
+
14
+ const TAILWIND_ENTRY_CSS = [
15
+ "@tailwind base;",
16
+ "@tailwind components;",
17
+ "@tailwind utilities;"
18
+ ].join("\n");
19
+
20
+ /**
21
+ * Resolve path to Tailwind config file in contentRoot (tailwind.config.js or tailwind.config.cjs).
22
+ * @param {string} contentRoot - Absolute path to project/content root
23
+ * @returns {string|null} Absolute path to config file or null if not found
24
+ */
25
+ function resolveTailwindConfigPath(contentRoot) {
26
+ if (!contentRoot || !fs.existsSync(contentRoot)) {
27
+ return null;
28
+ }
29
+ const jsPath = path.resolve(contentRoot, TAILWIND_CONFIG_FILE);
30
+ const cjsPath = path.resolve(contentRoot, TAILWIND_CONFIG_CJS);
31
+ if (fs.existsSync(jsPath)) {
32
+ return jsPath;
33
+ }
34
+ if (fs.existsSync(cjsPath)) {
35
+ return cjsPath;
36
+ }
37
+ return null;
38
+ }
39
+
40
+ /**
41
+ * Build Tailwind CSS and scope it with [data-element-type^="namespace_"] so utilities
42
+ * only apply inside widget roots. Uses tailwindcss from the SDK's node_modules.
43
+ *
44
+ * @param {Object} options
45
+ * @param {string} options.namespace - Namespace for the selector prefix (e.g. "myApp")
46
+ * @param {string} options.contentRoot - Absolute path to project root (where tailwind.config.js lives)
47
+ * @param {string} [options.tailwindConfigPath] - Optional explicit path to tailwind.config.js; otherwise resolved from contentRoot
48
+ * @returns {Promise<string>} Scoped, minified Tailwind CSS, or empty string if Tailwind is not enabled
49
+ */
50
+ async function compileTailwindToScopedCSS({
51
+ namespace,
52
+ contentRoot,
53
+ tailwindConfigPath
54
+ }) {
55
+ const configPath =
56
+ tailwindConfigPath || (contentRoot && resolveTailwindConfigPath(contentRoot));
57
+ if (!configPath || !namespace) {
58
+ return "";
59
+ }
60
+
61
+ // Require tailwindcss from SDK's node_modules (this file is in src/compilers/)
62
+ const tailwindcss = require("tailwindcss");
63
+
64
+ const prefixSelector = `[data-element-type^="${namespace}_"]`;
65
+
66
+ const processor = postcss([
67
+ tailwindcss({ config: configPath }),
68
+ postcssPrefixSelector({
69
+ prefix: prefixSelector,
70
+ exclude: [/^\d+%$/, "from", "to"]
71
+ }),
72
+ cssnano({
73
+ preset: [
74
+ "default",
75
+ {
76
+ discardComments: { removeAll: true },
77
+ normalizeWhitespace: true,
78
+ colormin: true,
79
+ autoprefixer: {
80
+ browsers: ["> 1%", "last 2 versions", "ie >= 9"],
81
+ add: true,
82
+ remove: true,
83
+ flexbox: "no-2009"
84
+ }
85
+ }
86
+ ]
87
+ })
88
+ ]);
89
+
90
+ const result = await processor.process(TAILWIND_ENTRY_CSS, {
91
+ from: undefined,
92
+ to: undefined,
93
+ map: false
94
+ });
95
+
96
+ return (result.css || "").trim();
97
+ }
98
+
99
+ module.exports = {
100
+ compileTailwindToScopedCSS,
101
+ resolveTailwindConfigPath
102
+ };