vueless 0.0.674 → 0.0.675

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.
@@ -0,0 +1,77 @@
1
+ /* eslint-disable no-console */
2
+ import { existsSync } from "node:fs";
3
+ import path from "node:path";
4
+ import { cwd } from "node:process";
5
+ import { cp, readFile, writeFile, rename } from "node:fs/promises";
6
+ import { styleText } from "node:util";
7
+
8
+ import { getDirFiles } from "../../utils/node/helper.js";
9
+ import { replaceRelativeImports } from "../utils/formatUtil.js";
10
+ import { getLastStorybookId } from "../utils/dataUtils.js";
11
+
12
+ import { SRC_COMPONENTS_PATH, COMPONENTS_PATH } from "../constants.js";
13
+
14
+ import { COMPONENTS, VUELESS_DIR, VUELESS_LOCAL_DIR } from "../../constants.js";
15
+
16
+ const boilerplateName = "UBoilerplate";
17
+ const boilerplatePath = path.join(cwd(), VUELESS_DIR, "ui.boilerplate");
18
+
19
+ export async function createVuelessComponent(options) {
20
+ const [componentName] = options;
21
+
22
+ if (!componentName) {
23
+ throw new Error("Component name is required");
24
+ }
25
+
26
+ const isSrcDir = existsSync(path.join(cwd(), VUELESS_LOCAL_DIR));
27
+ const destPath = isSrcDir
28
+ ? path.join(cwd(), SRC_COMPONENTS_PATH, componentName)
29
+ : path.join(cwd(), COMPONENTS_PATH, componentName);
30
+
31
+ const isComponentExists = componentName in COMPONENTS || existsSync(destPath);
32
+
33
+ if (isComponentExists) {
34
+ throw new Error(`Component with name ${componentName} alrady exists`);
35
+ }
36
+
37
+ await cp(boilerplatePath, destPath, { recursive: true });
38
+
39
+ await modifyCreatedComponent(destPath, componentName);
40
+
41
+ const successMessage = styleText(
42
+ "green",
43
+ `Success: ${componentName} was created in ${destPath} directory`,
44
+ );
45
+
46
+ console.log(successMessage);
47
+ }
48
+
49
+ async function modifyCreatedComponent(destPath, componentName) {
50
+ const destFiles = await getDirFiles(destPath, "");
51
+ const lastStorybookId = await getLastStorybookId();
52
+
53
+ for await (const filePath of destFiles) {
54
+ const fileContent = await readFile(filePath, "utf-8");
55
+
56
+ let updatedContent = replaceRelativeImports(componentName, filePath, fileContent);
57
+ let targetPath = filePath;
58
+
59
+ if (filePath.endsWith("constants.ts")) {
60
+ updatedContent = updatedContent.replace(boilerplateName, componentName);
61
+ }
62
+
63
+ if (filePath.endsWith("stories.ts")) {
64
+ updatedContent = updatedContent
65
+ .replaceAll(boilerplateName, componentName)
66
+ .replace("{{component_id}}", String(lastStorybookId + 10));
67
+ }
68
+
69
+ if (targetPath.endsWith(`${boilerplateName}.vue`)) {
70
+ targetPath = targetPath.replace(boilerplateName, componentName);
71
+
72
+ await rename(filePath, targetPath);
73
+ }
74
+
75
+ await writeFile(targetPath, updatedContent);
76
+ }
77
+ }
@@ -1,5 +1,7 @@
1
1
  import { vuelssInit } from "./init.js";
2
+ import { createVuelessComponent } from "./create.js";
2
3
 
3
4
  export const commands = {
4
5
  init: vuelssInit,
6
+ create: createVuelessComponent,
5
7
  };
@@ -5,14 +5,10 @@ import path from "node:path";
5
5
  import { writeFile } from "node:fs/promises";
6
6
  import { styleText } from "node:util";
7
7
 
8
- import {
9
- DEFAULT_VUELESS_CONFIG_NAME,
10
- DEFAULT_VUELESS_CONFIG_CONTNET,
11
- TYPESCRIPT_EXT,
12
- JAVASCRIPT_EXT,
13
- } from "../constants.js";
14
-
15
- const destPath = path.join(cwd(), DEFAULT_VUELESS_CONFIG_NAME);
8
+ import { DEFAULT_VUELESS_CONFIG_CONTNET } from "../constants.js";
9
+ import { JAVASCRIPT_EXT, TYPESCRIPT_EXT, VUELESS_CONFIG_FILE_NAME } from "../../constants.js";
10
+
11
+ const destPath = path.join(cwd(), VUELESS_CONFIG_FILE_NAME);
16
12
 
17
13
  const vuelessInitOptions = ["--ts", "--js"];
18
14
 
package/bin/constants.js CHANGED
@@ -1,8 +1,5 @@
1
- export const DEFAULT_VUELESS_CONFIG_NAME = "vueless.config.js";
2
- export const DEFAULT_EXIT_CODE = 0;
3
- export const FAILURE_CODE = 1;
4
- export const TYPESCRIPT_EXT = ".ts";
5
- export const JAVASCRIPT_EXT = ".js";
1
+ export const SRC_COMPONENTS_PATH = "/src/components";
2
+ export const COMPONENTS_PATH = "/components";
6
3
  export const DEFAULT_VUELESS_CONFIG_CONTNET = `
7
4
  export default {
8
5
  /**
package/bin/index.js CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { commands } from "./commands/index.js";
6
6
 
7
- import { DEFAULT_EXIT_CODE, FAILURE_CODE } from "./constants.js";
7
+ import { DEFAULT_EXIT_CODE, FAILURE_CODE } from "../constants.js";
8
8
 
9
9
  const [command, ...options] = process.argv.slice(2);
10
10
 
@@ -0,0 +1,53 @@
1
+ import { existsSync } from "node:fs";
2
+ import { cwd } from "node:process";
3
+ import path from "node:path";
4
+ import { readFile } from "node:fs/promises";
5
+
6
+ import { getDirFiles } from "../../utils/node/helper.js";
7
+
8
+ import { SRC_COMPONENTS_PATH, COMPONENTS_PATH } from "../constants.js";
9
+ import { VUELESS_DIR } from "../../constants.js";
10
+
11
+ const storiesName = "stories.ts";
12
+
13
+ export async function getLastStorybookId() {
14
+ const srcComponentsDir = path.join(cwd(), SRC_COMPONENTS_PATH);
15
+ const componentsDir = path.join(cwd(), COMPONENTS_PATH);
16
+ const vuelessPackagePath = path.join(cwd(), VUELESS_DIR);
17
+ const isSrcComponentsDir = existsSync(srcComponentsDir);
18
+ const isComponentsDir = existsSync(componentsDir);
19
+
20
+ const stories = await getDirFiles(vuelessPackagePath, storiesName);
21
+
22
+ if (isSrcComponentsDir) {
23
+ const srcComponentsDirStories = await getDirFiles(srcComponentsDir, storiesName);
24
+
25
+ stories.push(...srcComponentsDirStories);
26
+ }
27
+
28
+ if (isComponentsDir) {
29
+ const componentsDirStories = await getDirFiles(componentsDir, storiesName);
30
+
31
+ stories.push(...componentsDirStories);
32
+ }
33
+
34
+ let id = 200000;
35
+
36
+ for await (const storyPath of stories) {
37
+ const storyContent = await readFile(storyPath, "utf-8");
38
+
39
+ const storyIdLine = storyContent.split("\n").find((line, idx, array) => {
40
+ return line.includes("id:") && idx && array[idx - 1].includes("export default");
41
+ });
42
+
43
+ if (!storyIdLine) continue;
44
+
45
+ const currentId = parseInt(storyIdLine.split(" ").at(-1).replaceAll('"', ""));
46
+
47
+ if (currentId > id && !Number.isNaN(currentId)) {
48
+ id = currentId;
49
+ }
50
+ }
51
+
52
+ return id;
53
+ }
@@ -0,0 +1,48 @@
1
+ import path from "node:path";
2
+
3
+ export function replaceRelativeImports(componentName, filePath, fileContent) {
4
+ const isTopLevelFile = path.dirname(filePath).endsWith(componentName);
5
+ const contentLines = fileContent.split("\n");
6
+
7
+ return contentLines.map((line) => replaceRelativeLineImports(line, isTopLevelFile)).join("\n");
8
+ }
9
+
10
+ function replaceRelativeLineImports(line, isTopLevelFile) {
11
+ const importRegex = /import\s+(?:[\w\s{},*]+)\s+from\s+(['"])(\.\.?\/.*?)(\.[tj]s)?\1(?!\?)/g;
12
+
13
+ const isTopLevelLocalImport = isTopLevelFile && !line.includes("../");
14
+ const isInnerLocalImport =
15
+ !isTopLevelFile && (line.includes("../") || line.includes("./")) && !line.includes("../../");
16
+
17
+ if (isTopLevelLocalImport || isInnerLocalImport) {
18
+ return line;
19
+ }
20
+
21
+ return line.replace(importRegex, (match, quote, oldPath, ext) => {
22
+ const isDefaultImport = match.includes("{");
23
+
24
+ if (!isDefaultImport) {
25
+ match = defaultToNamedImport(match);
26
+ }
27
+
28
+ return match.replace(oldPath + (ext || ""), "vueless");
29
+ });
30
+ }
31
+
32
+ function defaultToNamedImport(importString) {
33
+ const splittedImport = importString.split(" ");
34
+
35
+ return splittedImport
36
+ .map((importStringToken) => {
37
+ if (importStringToken.includes("import")) {
38
+ return `${importStringToken} { `;
39
+ }
40
+
41
+ if (importStringToken.includes("from")) {
42
+ return ` } ${importStringToken} `;
43
+ }
44
+
45
+ return importStringToken;
46
+ })
47
+ .join("");
48
+ }
package/constants.js CHANGED
@@ -221,6 +221,10 @@ export const VUELESS_ICONS_LOCAL_DIR = `src/${ICONS_DIR}`;
221
221
  export const VUELESS_ICONS_CACHED_DIR = `${VUELESS_CACHE_DIR}/${ICONS_DIR}`;
222
222
  export const VUELESS_CONFIGS_CACHED_DIR = `${VUELESS_CACHE_DIR}/configs`;
223
223
 
224
+ /* System error codes */
225
+ export const DEFAULT_EXIT_CODE = 0;
226
+ export const FAILURE_CODE = 1;
227
+
224
228
  /* Other */
225
229
  export const PX_IN_REM = 16;
226
230
  export const NESTED_COMPONENT_PATTERN_REG_EXP = /\{(U[^}]*)}/;
@@ -229,3 +233,5 @@ export const DYNAMIC_COLOR_PATTERN = "{color}";
229
233
  export const TAILWIND_COLOR_OPACITY_DELIMITER = "/";
230
234
  export const TAILWIND_VARIANT_DELIMITER = ":";
231
235
  export const TAILWIND_VARIANT_DELIMITER_REG_EXP = /:(?![^[]*])/;
236
+ export const JAVASCRIPT_EXT = ".js";
237
+ export const TYPESCRIPT_EXT = ".ts";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.674",
3
+ "version": "0.0.675",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
@@ -33,7 +33,7 @@
33
33
  "build": "npm run pre:start && storybook build --docs",
34
34
  "preview": "vite preview --host --outDir=storybook-static",
35
35
  "ts:check": "vue-tsc --build --force",
36
- "release:prepare": "npm run pre:start && rm -rf dist && mkdir -p dist && cp -r src/. package.json LICENSE README.md dist/ && cp -r bin dist/bin",
36
+ "release:prepare": "npm run pre:start && rm -rf dist && mkdir -p dist && cp -r src/. package.json LICENSE README.md dist/",
37
37
  "release:beta": "release-it --ci --npm.publish --preRelease=beta --increment=prerelease",
38
38
  "release:patch": "release-it patch --ci --npm.publish",
39
39
  "release:minor": "release-it minor --ci --npm.publish --git.tag --github.release",
package/plugin-vite.js CHANGED
@@ -14,6 +14,8 @@ import { setCustomPropTypes, removeCustomPropTypes } from "./utils/node/dynamicP
14
14
  import { buildWebTypes } from "./utils/node/webTypes.js";
15
15
  import { hideHiddenStories, showHiddenStories } from "./utils/node/dynamicStories.js";
16
16
 
17
+ import { DEFAULT_EXIT_CODE } from "./constants.js";
18
+
17
19
  /* Automatically importing Vueless components on demand */
18
20
  export const VuelessUnpluginComponents = (options) =>
19
21
  UnpluginVueComponents({
@@ -48,7 +50,7 @@ export const Vueless = function (options = {}) {
48
50
  clearTailwindSafelist(debug);
49
51
 
50
52
  /* stop command line process */
51
- process.exit(0);
53
+ process.exit(DEFAULT_EXIT_CODE);
52
54
  });
53
55
 
54
56
  return {
@@ -10,7 +10,7 @@ interface UBoilerplateArgs extends Props {
10
10
  }
11
11
 
12
12
  export default {
13
- id: "110010",
13
+ id: "{{component_id}}",
14
14
  title: "Custom / UBoilerplate",
15
15
  component: UBoilerplate,
16
16
  args: {