@weme-ui/weme-ui 0.2.5 → 0.2.6
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/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { defineCommand, runMain } from "citty";
|
|
3
3
|
|
|
4
4
|
// package.json
|
|
5
|
-
var version = "0.2.
|
|
5
|
+
var version = "0.2.6";
|
|
6
6
|
var description = "A CLI to manage Weme UI projects.";
|
|
7
7
|
|
|
8
8
|
// src/constants.ts
|
|
@@ -40,7 +40,7 @@ const cli = defineCommand({
|
|
|
40
40
|
* @example
|
|
41
41
|
* ```bunx @weme-ui/weme-ui init```
|
|
42
42
|
*/
|
|
43
|
-
init: () => import("./init-
|
|
43
|
+
init: () => import("./init-BRUpnSvB.js").then((r) => r.default),
|
|
44
44
|
/**
|
|
45
45
|
* 添加组件
|
|
46
46
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as DEFAULT_PATHS, o as PROJECT_CONFIG_FILENAME, r as DEFAULT_REGISTRIES, t as CLI_TMP_DIR } from "./index.js";
|
|
2
1
|
import { a as parseRepoURL, c as writeFile, i as existsFile, l as useRegistry, n as callWhen, o as randomColor, r as ensureDir, s as unwrapError, t as Project } from "./project-DgAuYtns.js";
|
|
2
|
+
import { n as DEFAULT_PATHS, o as PROJECT_CONFIG_FILENAME, r as DEFAULT_REGISTRIES, t as CLI_TMP_DIR } from "./index.js";
|
|
3
3
|
import { defineCommand } from "citty";
|
|
4
4
|
import { dirname, join, resolve } from "node:path/posix";
|
|
5
5
|
import { cwd, exit } from "node:process";
|
|
@@ -216,4 +216,4 @@ var init_default = defineCommand({
|
|
|
216
216
|
});
|
|
217
217
|
|
|
218
218
|
export { init_default as default };
|
|
219
|
-
//# sourceMappingURL=init-
|
|
219
|
+
//# sourceMappingURL=init-BRUpnSvB.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-DXWOjwh_.js","names":[],"sources":["../src/commands/init/config.ts","../src/commands/init/template.ts","../src/commands/init/unocss.ts","../src/commands/init/index.ts"],"sourcesContent":["import { CONFIG_SCHEMA_URL, ProjectConfigSchema } from '@weme-ui/schema'\nimport * as v from 'valibot'\nimport { DEFAULT_PATHS, DEFAULT_REGISTRIES, PROJECT_CONFIG_FILENAME } from '../../constants'\nimport { parseRepoURL, writeFile } from '../../utils'\n\n/**\n * Generate the default config for the project.\n *\n * @param root - The root directory of the project.\n * @returns Whether the default config was generated successfully.\n * @throws If the default config fails to generate.\n */\nexport async function generateDefaultConfig(root: string, repo?: string) {\n const { name } = parseRepoURL(repo)\n\n const registries = repo ? [{ registry: name, repo }] : DEFAULT_REGISTRIES\n\n const schema = v.safeParse(ProjectConfigSchema, {\n $schema: CONFIG_SCHEMA_URL,\n registries,\n paths: DEFAULT_PATHS,\n })\n\n if (!schema.success) {\n throw new Error('Failed to generate default config')\n }\n\n return await writeFile(root, PROJECT_CONFIG_FILENAME, JSON.stringify(schema.output, null, 2))\n}\n","// oxlint-disable no-await-in-loop\nimport { existsSync } from 'node:fs'\nimport { copyFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path/posix'\nimport { x } from 'tinyexec'\nimport { glob } from 'tinyglobby'\nimport { CLI_TMP_DIR } from '../../constants'\nimport { ensureDir, existsFile } from '../../utils'\n\n/**\n * Initialize the project template.\n *\n * @param cwd - The current working directory.\n * @param template - The template to initialize.\n * @throws If the template is not found.\n */\nexport async function initProjectTemplate(cwd: string, template: string = 'vite') {\n const templatePath = join(cwd, CLI_TMP_DIR, 'repository', 'templates', template)\n\n if (!existsSync(templatePath)) {\n throw new Error(`Template ${template} not found`)\n }\n\n const files = await glob('**', { cwd: templatePath, onlyFiles: true })\n\n for (const file of files) {\n const filePath = join(cwd, file)\n const fileDir = dirname(filePath)\n\n if (!existsSync(fileDir)) {\n ensureDir(fileDir)\n }\n\n if (!(await existsFile(cwd, file))) {\n await copyFile(join(templatePath, file), filePath)\n }\n }\n\n // Clean the template repository finally.\n await cleanTemplateRepository(cwd)\n}\n\n/**\n * Clone the template repository.\n *\n * @returns The result of the clone operation.\n * @throws If the clone operation fails.\n */\nexport async function cloneTemplateRepository(cwd: string) {\n const repositoryPath = join(cwd, CLI_TMP_DIR, 'repository')\n\n await cleanTemplateRepository(cwd)\n\n const result = await x('git', [\n 'clone',\n '--depth',\n '1',\n 'https://github.com/weme-ui/weme-ui.git',\n repositoryPath,\n ])\n\n if (result.exitCode !== 0) {\n throw new Error(`Failed to clone template repository: ${result.stderr}`)\n }\n\n return result.stdout\n}\n\n/**\n * Clean the template repository.\n *\n * @param cwd - The current working directory.\n * @returns The result of the clean operation.\n * @throws If the clean operation fails.\n */\nexport async function cleanTemplateRepository(cwd: string) {\n const repositoryPath = join(cwd, CLI_TMP_DIR, 'repository')\n\n if (existsSync(repositoryPath)) {\n await x('rm', ['-rf', repositoryPath])\n }\n}\n","import { join } from 'node:path/posix'\nimport { CLI_TMP_DIR, PROJECT_CONFIG_FILENAME } from '../../constants'\nimport { writeFile } from '../../utils'\n\nconst baseUnoConfig = `import type { Theme } from '@weme-ui/unocss-preset/types'\nimport { defineConfig } from 'unocss'\n\nexport default defineConfig<Theme>({\n // Configure the content pipeline to include *.style.ts files in the project.\n content: {\n pipeline: {\n include: [\n /\\\\.(vue|[jt]sx|style\\\\.[jt]s|vine\\\\.[jt]s|mdx?|astro|elm|php|phtml|html)($|\\\\?)/,\n ],\n },\n },\n})\n`\nconst unoConfig = `import type { ProjectConfigSchema } from '@weme-ui/schema'\nimport type { Theme } from '@weme-ui/unocss-preset/types'\nimport type { InferInput } from 'valibot'\nimport { presetWemeUI } from '@weme-ui/unocss-preset'\nimport { mergeConfigs } from 'unocss'\nimport baseConfig from './${CLI_TMP_DIR}/uno.config'\nimport wemeConfigJson from './${PROJECT_CONFIG_FILENAME}' with { type: 'json' }\n\nconst wemeConfig = wemeConfigJson as InferInput<typeof ProjectConfigSchema>\n\nexport default mergeConfigs<Theme>([\n baseConfig,\n {\n presets: [\n presetWemeUI({\n colors: wemeConfig.unocss?.colors || {},\n cssVars: wemeConfig.unocss?.cssVars || {},\n }),\n ],\n },\n])\n`\n\nexport async function generateDefaultUnoCSSConfigs(root: string) {\n const createdBaseConfig = await writeFile(\n join(root, CLI_TMP_DIR),\n 'uno.config.ts',\n baseUnoConfig.trim(),\n )\n const createdUnoConfig = await writeFile(root, 'uno.config.ts', unoConfig.trim())\n\n return createdBaseConfig && createdUnoConfig\n}\n","// oxlint-disable no-await-in-loop\nimport { defineCommand } from 'citty'\nimport { resolve } from 'node:path/posix'\nimport { cwd, exit } from 'node:process'\nimport { installDependencies } from 'nypm'\nimport ora from 'ora'\nimport { callWhen, parseRepoURL, Project, randomColor, unwrapError, useRegistry } from '../../utils'\nimport { generateDefaultConfig } from './config'\nimport { cloneTemplateRepository, initProjectTemplate } from './template'\nimport { generateDefaultUnoCSSConfigs } from './unocss'\n\n/**\n * 初始化项目\n */\nexport default defineCommand({\n meta: {\n name: 'init',\n description: 'Initialize a new Weme UI project',\n },\n\n args: {\n cwd: {\n type: 'positional',\n description: 'Change working directory to the project root.',\n default: cwd(),\n },\n repo: {\n type: 'string',\n description: 'Specify the registry repository of the project.',\n valueHint: 'weme-ui/slim',\n },\n },\n\n async run({ args }) {\n const cwd = resolve(args.cwd)\n\n try {\n const project = new Project(cwd)\n\n if (await project.isInitialized()) {\n throw new Error('Project already initialized')\n }\n\n const spinner = ora({ text: 'Initializing project...' }).start()\n\n const { name, branch } = parseRepoURL(args.repo)\n\n // 1. Initialize project from clone template repository\n await callWhen(!(await project.hasPackageJson()), async () => {\n spinner.color = randomColor()\n spinner.text = 'Cloning template repository...'\n await cloneTemplateRepository(cwd)\n\n spinner.text = 'Initializing project structure...'\n spinner.color = randomColor()\n await initProjectTemplate(cwd)\n })\n\n // 2. Generate the default project config file\n await callWhen(!(await project.hasProjectConfig()), async () => {\n spinner.text = 'Generating project config file...'\n spinner.color = randomColor()\n await generateDefaultConfig(cwd, args.repo)\n })\n\n // 3. Generate the default UnoCSS config file\n await callWhen(!(await project.hasUnoConfig()), async () => {\n spinner.color = randomColor()\n spinner.text = 'Generating UnoCSS config file...'\n await generateDefaultUnoCSSConfigs(cwd)\n })\n\n // 4. Install dependencies\n await callWhen(await project.hasPackageJson(), async () => {\n spinner.text = 'Install dependencies...'\n spinner.color = randomColor()\n await installDependencies({\n cwd,\n silent: true,\n })\n })\n\n // 5. Add dependencies to the project\n await callWhen(await project.hasPackageJson(), async () => {\n const registry = useRegistry(name, branch)\n\n spinner.text = 'Adding dependencies to the project...'\n spinner.color = randomColor()\n const dependencies = await registry.dependencies()\n if (dependencies.length > 0) {\n await project.addDependencies(dependencies)\n }\n\n spinner.text = 'Adding dev dependencies to the project...'\n spinner.color = randomColor()\n const devDependencies = await registry.devDependencies()\n if (devDependencies.length > 0) {\n await project.addDevDependencies(devDependencies)\n }\n })\n\n // 6. Add `on-init` items to the project\n await callWhen(await project.hasPackageJson(), async () => {\n const registry = useRegistry(name, branch)\n\n spinner.text = 'Adding `on-init` items to the project...'\n spinner.color = randomColor()\n const onInitItems = await registry.getItems((item) => item.when === 'on-init')\n if (onInitItems.length > 0) {\n for (const item of onInitItems) {\n const itemName = `${name}/${item.name}`\n if (!(await project.hasAddedItem(itemName))) {\n await project.addItem(itemName)\n }\n }\n }\n })\n\n spinner.succeed('Project initialized successfully')\n } catch (err) {\n console.error(unwrapError(err))\n exit(1)\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAYA,eAAsB,sBAAsB,MAAc,MAAe;CACvE,MAAM,EAAE,SAAS,aAAa,IAAI;CAElC,MAAM,aAAa,OAAO,CAAC;EAAE,UAAU;EAAM;CAAK,CAAC,IAAI;CAEvD,MAAM,SAAS,EAAE,UAAU,qBAAqB;EAC9C,SAAS;EACT;EACA,OAAO;CACT,CAAC;CAED,IAAI,CAAC,OAAO,SACV,MAAM,IAAI,MAAM,mCAAmC;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,QAAQ,YAAY;IAC5B,MAAM,oBAAoB;KACxB;KACA,QAAQ;IACV,CAAC;GACH,CAAC;GAGD,MAAM,SAAS,MAAM,QAAQ,eAAe,GAAG,YAAY;IACzD,MAAM,WAAW,YAAY,MAAM,MAAM;IAEzC,QAAQ,OAAO;IACf,QAAQ,QAAQ,YAAY;IAC5B,MAAM,eAAe,MAAM,SAAS,aAAa;IACjD,IAAI,aAAa,SAAS,GACxB,MAAM,QAAQ,gBAAgB,YAAY;IAG5C,QAAQ,OAAO;IACf,QAAQ,QAAQ,YAAY;IAC5B,MAAM,kBAAkB,MAAM,SAAS,gBAAgB;IACvD,IAAI,gBAAgB,SAAS,GAC3B,MAAM,QAAQ,mBAAmB,eAAe;GAEpD,CAAC;GAGD,MAAM,SAAS,MAAM,QAAQ,eAAe,GAAG,YAAY;IACzD,MAAM,WAAW,YAAY,MAAM,MAAM;IAEzC,QAAQ,OAAO;IACf,QAAQ,QAAQ,YAAY;IAC5B,MAAM,cAAc,MAAM,SAAS,UAAU,SAAS,KAAK,SAAS,SAAS;IAC7E,IAAI,YAAY,SAAS,GACvB,KAAK,MAAM,QAAQ,aAAa;KAC9B,MAAM,WAAW,GAAG,KAAK,GAAG,KAAK;KACjC,IAAI,CAAE,MAAM,QAAQ,aAAa,QAAQ,GACvC,MAAM,QAAQ,QAAQ,QAAQ;IAElC;GAEJ,CAAC;GAED,QAAQ,QAAQ,kCAAkC;EACpD,SAAS,KAAK;GACZ,QAAQ,MAAM,YAAY,GAAG,CAAC;GAC9B,KAAK,CAAC;EACR;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"init-BRUpnSvB.js","names":[],"sources":["../src/commands/init/config.ts","../src/commands/init/template.ts","../src/commands/init/unocss.ts","../src/commands/init/index.ts"],"sourcesContent":["import { CONFIG_SCHEMA_URL, ProjectConfigSchema } from '@weme-ui/schema'\nimport * as v from 'valibot'\nimport { DEFAULT_PATHS, DEFAULT_REGISTRIES, PROJECT_CONFIG_FILENAME } from '../../constants'\nimport { parseRepoURL, writeFile } from '../../utils'\n\n/**\n * Generate the default config for the project.\n *\n * @param root - The root directory of the project.\n * @returns Whether the default config was generated successfully.\n * @throws If the default config fails to generate.\n */\nexport async function generateDefaultConfig(root: string, repo?: string) {\n const { name } = parseRepoURL(repo)\n\n const registries = repo ? [{ registry: name, repo }] : DEFAULT_REGISTRIES\n\n const schema = v.safeParse(ProjectConfigSchema, {\n $schema: CONFIG_SCHEMA_URL,\n registries,\n paths: DEFAULT_PATHS,\n })\n\n if (!schema.success) {\n throw new Error('Failed to generate default config')\n }\n\n return await writeFile(root, PROJECT_CONFIG_FILENAME, JSON.stringify(schema.output, null, 2))\n}\n","// oxlint-disable no-await-in-loop\nimport { existsSync } from 'node:fs'\nimport { copyFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path/posix'\nimport { x } from 'tinyexec'\nimport { glob } from 'tinyglobby'\nimport { CLI_TMP_DIR } from '../../constants'\nimport { ensureDir, existsFile } from '../../utils'\n\n/**\n * Initialize the project template.\n *\n * @param cwd - The current working directory.\n * @param template - The template to initialize.\n * @throws If the template is not found.\n */\nexport async function initProjectTemplate(cwd: string, template: string = 'vite') {\n const templatePath = join(cwd, CLI_TMP_DIR, 'repository', 'templates', template)\n\n if (!existsSync(templatePath)) {\n throw new Error(`Template ${template} not found`)\n }\n\n const files = await glob('**', { cwd: templatePath, onlyFiles: true })\n\n for (const file of files) {\n const filePath = join(cwd, file)\n const fileDir = dirname(filePath)\n\n if (!existsSync(fileDir)) {\n ensureDir(fileDir)\n }\n\n if (!(await existsFile(cwd, file))) {\n await copyFile(join(templatePath, file), filePath)\n }\n }\n\n // Clean the template repository finally.\n await cleanTemplateRepository(cwd)\n}\n\n/**\n * Clone the template repository.\n *\n * @returns The result of the clone operation.\n * @throws If the clone operation fails.\n */\nexport async function cloneTemplateRepository(cwd: string) {\n const repositoryPath = join(cwd, CLI_TMP_DIR, 'repository')\n\n await cleanTemplateRepository(cwd)\n\n const result = await x('git', [\n 'clone',\n '--depth',\n '1',\n 'https://github.com/weme-ui/weme-ui.git',\n repositoryPath,\n ])\n\n if (result.exitCode !== 0) {\n throw new Error(`Failed to clone template repository: ${result.stderr}`)\n }\n\n return result.stdout\n}\n\n/**\n * Clean the template repository.\n *\n * @param cwd - The current working directory.\n * @returns The result of the clean operation.\n * @throws If the clean operation fails.\n */\nexport async function cleanTemplateRepository(cwd: string) {\n const repositoryPath = join(cwd, CLI_TMP_DIR, 'repository')\n\n if (existsSync(repositoryPath)) {\n await x('rm', ['-rf', repositoryPath])\n }\n}\n","import { join } from 'node:path/posix'\nimport { CLI_TMP_DIR, PROJECT_CONFIG_FILENAME } from '../../constants'\nimport { writeFile } from '../../utils'\n\nconst baseUnoConfig = `import type { Theme } from '@weme-ui/unocss-preset/types'\nimport { defineConfig } from 'unocss'\n\nexport default defineConfig<Theme>({\n // Configure the content pipeline to include *.style.ts files in the project.\n content: {\n pipeline: {\n include: [\n /\\\\.(vue|[jt]sx|style\\\\.[jt]s|vine\\\\.[jt]s|mdx?|astro|elm|php|phtml|html)($|\\\\?)/,\n ],\n },\n },\n})\n`\nconst unoConfig = `import type { ProjectConfigSchema } from '@weme-ui/schema'\nimport type { Theme } from '@weme-ui/unocss-preset/types'\nimport type { InferInput } from 'valibot'\nimport { presetWemeUI } from '@weme-ui/unocss-preset'\nimport { mergeConfigs } from 'unocss'\nimport baseConfig from './${CLI_TMP_DIR}/uno.config'\nimport wemeConfigJson from './${PROJECT_CONFIG_FILENAME}' with { type: 'json' }\n\nconst wemeConfig = wemeConfigJson as InferInput<typeof ProjectConfigSchema>\n\nexport default mergeConfigs<Theme>([\n baseConfig,\n {\n presets: [\n presetWemeUI({\n colors: wemeConfig.unocss?.colors || {},\n cssVars: wemeConfig.unocss?.cssVars || {},\n }),\n ],\n },\n])\n`\n\nexport async function generateDefaultUnoCSSConfigs(root: string) {\n const createdBaseConfig = await writeFile(\n join(root, CLI_TMP_DIR),\n 'uno.config.ts',\n baseUnoConfig.trim(),\n )\n const createdUnoConfig = await writeFile(root, 'uno.config.ts', unoConfig.trim())\n\n return createdBaseConfig && createdUnoConfig\n}\n","// oxlint-disable no-await-in-loop\nimport { defineCommand } from 'citty'\nimport { resolve } from 'node:path/posix'\nimport { cwd, exit } from 'node:process'\nimport { installDependencies } from 'nypm'\nimport ora from 'ora'\nimport { callWhen, parseRepoURL, Project, randomColor, unwrapError, useRegistry } from '../../utils'\nimport { generateDefaultConfig } from './config'\nimport { cloneTemplateRepository, initProjectTemplate } from './template'\nimport { generateDefaultUnoCSSConfigs } from './unocss'\n\n/**\n * 初始化项目\n */\nexport default defineCommand({\n meta: {\n name: 'init',\n description: 'Initialize a new Weme UI project',\n },\n\n args: {\n cwd: {\n type: 'positional',\n description: 'Change working directory to the project root.',\n default: cwd(),\n },\n repo: {\n type: 'string',\n description: 'Specify the registry repository of the project.',\n valueHint: 'weme-ui/slim',\n },\n },\n\n async run({ args }) {\n const cwd = resolve(args.cwd)\n\n try {\n const project = new Project(cwd)\n\n if (await project.isInitialized()) {\n throw new Error('Project already initialized')\n }\n\n const spinner = ora({ text: 'Initializing project...' }).start()\n\n const { name, branch } = parseRepoURL(args.repo)\n\n // 1. Initialize project from clone template repository\n await callWhen(!(await project.hasPackageJson()), async () => {\n spinner.color = randomColor()\n spinner.text = 'Cloning template repository...'\n await cloneTemplateRepository(cwd)\n\n spinner.text = 'Initializing project structure...'\n spinner.color = randomColor()\n await initProjectTemplate(cwd)\n })\n\n // 2. Generate the default project config file\n await callWhen(!(await project.hasProjectConfig()), async () => {\n spinner.text = 'Generating project config file...'\n spinner.color = randomColor()\n await generateDefaultConfig(cwd, args.repo)\n })\n\n // 3. Generate the default UnoCSS config file\n await callWhen(!(await project.hasUnoConfig()), async () => {\n spinner.color = randomColor()\n spinner.text = 'Generating UnoCSS config file...'\n await generateDefaultUnoCSSConfigs(cwd)\n })\n\n // 4. Install dependencies\n await callWhen(await project.hasPackageJson(), async () => {\n spinner.text = 'Install dependencies...'\n spinner.color = randomColor()\n await installDependencies({\n cwd,\n silent: true,\n })\n })\n\n // 5. Add dependencies to the project\n await callWhen(await project.hasPackageJson(), async () => {\n const registry = useRegistry(name, branch)\n\n spinner.text = 'Adding dependencies to the project...'\n spinner.color = randomColor()\n const dependencies = await registry.dependencies()\n if (dependencies.length > 0) {\n await project.addDependencies(dependencies)\n }\n\n spinner.text = 'Adding dev dependencies to the project...'\n spinner.color = randomColor()\n const devDependencies = await registry.devDependencies()\n if (devDependencies.length > 0) {\n await project.addDevDependencies(devDependencies)\n }\n })\n\n // 6. Add `on-init` items to the project\n await callWhen(await project.hasPackageJson(), async () => {\n const registry = useRegistry(name, branch)\n\n spinner.text = 'Adding `on-init` items to the project...'\n spinner.color = randomColor()\n const onInitItems = await registry.getItems((item) => item.when === 'on-init')\n if (onInitItems.length > 0) {\n for (const item of onInitItems) {\n const itemName = `${name}/${item.name}`\n if (!(await project.hasAddedItem(itemName))) {\n await project.addItem(itemName)\n }\n }\n }\n })\n\n spinner.succeed('Project initialized successfully')\n } catch (err) {\n console.error(unwrapError(err))\n exit(1)\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAYA,eAAsB,sBAAsB,MAAc,MAAe;CACvE,MAAM,EAAE,SAAS,aAAa,IAAI;CAElC,MAAM,aAAa,OAAO,CAAC;EAAE,UAAU;EAAM;CAAK,CAAC,IAAI;CAEvD,MAAM,SAAS,EAAE,UAAU,qBAAqB;EAC9C,SAAS;EACT;EACA,OAAO;CACT,CAAC;CAED,IAAI,CAAC,OAAO,SACV,MAAM,IAAI,MAAM,mCAAmC;CAGrD,OAAO,MAAM,UAAU,MAAM,yBAAyB,KAAK,UAAU,OAAO,QAAQ,MAAM,CAAC,CAAC;AAC9F;;;;;;;;;;ACZA,eAAsB,oBAAoB,KAAa,WAAmB,QAAQ;CAChF,MAAM,eAAe,KAAK,KAAK,aAAa,cAAc,aAAa,QAAQ;CAE/E,IAAI,CAAC,WAAW,YAAY,GAC1B,MAAM,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a;IACjD,IAAI,aAAa,SAAS,GACxB,MAAM,QAAQ,gBAAgB,YAAY;IAG5C,QAAQ,OAAO;IACf,QAAQ,QAAQ,YAAY;IAC5B,MAAM,kBAAkB,MAAM,SAAS,gBAAgB;IACvD,IAAI,gBAAgB,SAAS,GAC3B,MAAM,QAAQ,mBAAmB,eAAe;GAEpD,CAAC;GAGD,MAAM,SAAS,MAAM,QAAQ,eAAe,GAAG,YAAY;IACzD,MAAM,WAAW,YAAY,MAAM,MAAM;IAEzC,QAAQ,OAAO;IACf,QAAQ,QAAQ,YAAY;IAC5B,MAAM,cAAc,MAAM,SAAS,UAAU,SAAS,KAAK,SAAS,SAAS;IAC7E,IAAI,YAAY,SAAS,GACvB,KAAK,MAAM,QAAQ,aAAa;KAC9B,MAAM,WAAW,GAAG,KAAK,GAAG,KAAK;KACjC,IAAI,CAAE,MAAM,QAAQ,aAAa,QAAQ,GACvC,MAAM,QAAQ,QAAQ,QAAQ;IAElC;GAEJ,CAAC;GAED,QAAQ,QAAQ,kCAAkC;EACpD,SAAS,KAAK;GACZ,QAAQ,MAAM,YAAY,GAAG,CAAC;GAC9B,KAAK,CAAC;EACR;CACF;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weme-ui/weme-ui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "A CLI to manage Weme UI projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"component",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@weme-ui/schema": "^5.0.1",
|
|
64
|
-
"@weme-ui/unocss-preset": "^0.
|
|
64
|
+
"@weme-ui/unocss-preset": "^0.4.0",
|
|
65
65
|
"citty": "^0.2.2",
|
|
66
66
|
"defu": "^6.1.7",
|
|
67
67
|
"diff": "^9.0.0",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"make-fetch-happen": "^16.0.1",
|
|
70
70
|
"nypm": "^0.6.12",
|
|
71
71
|
"ora": "^10.0.0",
|
|
72
|
-
"semver": "^7.8.
|
|
72
|
+
"semver": "^7.8.6",
|
|
73
73
|
"tinyexec": "^1.3.1",
|
|
74
74
|
"tinyglobby": "^0.2.17",
|
|
75
75
|
"ufo": "^1.6.4",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"pkg-types": "^2.4.0",
|
|
83
83
|
"tsdown": "^0.22.3",
|
|
84
84
|
"typescript": "6.0.3",
|
|
85
|
-
"unocss": "66.
|
|
85
|
+
"unocss": "^66.12.0",
|
|
86
86
|
"vitest": "^4.1.8"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|