@cdlab996/create-lowcode 0.0.0-stage → 2.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023, cdLab996
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,26 @@
1
- # Temporary Holding Version
1
+ # @cdlab996/create-lowcode
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Creates a [LowCode Engine](https://github.com/alibaba/lowcode-engine) material
4
+ project for Vue 2.7 or Vue 3, built with
5
+ [`@cdlab996/lowcode-material-builder`](../material-builder).
6
+
7
+ ```bash
8
+ pnpm create @cdlab996/lowcode my-materials
9
+ # or: npm create @cdlab996/lowcode@latest my-materials
10
+ ```
11
+
12
+ Options:
13
+
14
+ | Option | Description |
15
+ | ------------ | ------------------------------------------------- |
16
+ | `[dir]` | Project directory (asked when omitted). |
17
+ | `--vue 2\|3` | Vue version; `2` is Vue 2.7 (asked when omitted). |
18
+ | `--force` | Empty the directory when it is not empty. |
19
+
20
+ Without a terminal, omitted answers default to `lowcode-materials` and Vue 3,
21
+ and a non-empty directory needs `--force`.
22
+
23
+ The project contains an example `XButton` component (SFC) with its meta, a
24
+ Vite config declaring the material options, Biome and `vue-tsc`. Vue 2.7
25
+ projects compile SFCs with `@vitejs/plugin-vue2` and ship a
26
+ `pnpm-workspace.yaml` that allows esbuild's install script.
package/dist/cli.mjs ADDED
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env node
2
+ import { basename, join, relative, resolve } from "node:path";
3
+ import { createInterface } from "node:readline/promises";
4
+ import { parseArgs } from "node:util";
5
+ import { cp, mkdir, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
6
+ import { fileURLToPath } from "node:url";
7
+ // src/args.ts
8
+ function parseOptions(argv) {
9
+ const { positionals, values } = parseArgs({
10
+ args: argv,
11
+ allowPositionals: true,
12
+ options: {
13
+ vue: { type: "string" },
14
+ force: {
15
+ type: "boolean",
16
+ default: false
17
+ },
18
+ help: {
19
+ type: "boolean",
20
+ short: "h",
21
+ default: false
22
+ }
23
+ }
24
+ });
25
+ let vue;
26
+ if (values.vue !== void 0) {
27
+ if (values.vue !== "2" && values.vue !== "3") throw new Error(`--vue must be 2 or 3, got "${values.vue}"`);
28
+ vue = Number(values.vue);
29
+ }
30
+ return {
31
+ dir: positionals[0],
32
+ vue,
33
+ force: values.force,
34
+ help: values.help
35
+ };
36
+ }
37
+ /** A valid npm package name from a directory path. */
38
+ function toPackageName(dir) {
39
+ return basename(resolve(dir)).trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]+/, "").replace(/[^a-z0-9-~._]+/g, "-");
40
+ }
41
+ function isValidPackageName(name) {
42
+ return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(name);
43
+ }
44
+ // src/create.ts
45
+ const TEMPLATE_DIR = fileURLToPath(new URL("../template", import.meta.url));
46
+ /** Template files stored under another name so tools leave them alone. */
47
+ const RENAMED = {
48
+ _gitignore: ".gitignore",
49
+ "_biome.json": "biome.json"
50
+ };
51
+ /** Entries of `dir` other than `.git`; empty when it does not exist. */
52
+ async function existingEntries(dir) {
53
+ return (await readdir(dir).catch(() => [])).filter((name) => name !== ".git");
54
+ }
55
+ async function createProject({ targetDir, packageName, vue, force = false }) {
56
+ const entries = await existingEntries(targetDir);
57
+ if (entries.length && !force) throw new Error(`${targetDir} is not empty; use --force to overwrite it`);
58
+ for (const name of entries) await rm(join(targetDir, name), {
59
+ recursive: true,
60
+ force: true
61
+ });
62
+ await mkdir(targetDir, { recursive: true });
63
+ for (const part of ["common", `vue${vue}`]) await cp(join(TEMPLATE_DIR, part), targetDir, { recursive: true });
64
+ for (const [from, to] of Object.entries(RENAMED)) await rename(join(targetDir, from), join(targetDir, to));
65
+ const pkgPath = join(targetDir, "package.json");
66
+ const pkg = JSON.parse(await readFile(pkgPath, "utf8"));
67
+ await writeFile(pkgPath, `${JSON.stringify({
68
+ name: packageName,
69
+ ...pkg
70
+ }, null, 2)}\n`);
71
+ }
72
+ // src/cli.ts
73
+ const usage = `Usage: create-lowcode [dir] [--vue 2|3] [--force]
74
+
75
+ Creates a LowCode Engine material project.
76
+
77
+ --vue 2|3 Vue version (2 = Vue 2.7)
78
+ --force Empty the directory if it is not empty`;
79
+ const DEFAULT_DIR = "lowcode-materials";
80
+ /** The package manager that runs this script, from npm's user agent. */
81
+ function packageManager() {
82
+ const agent = process.env.npm_config_user_agent ?? "";
83
+ return [
84
+ "pnpm",
85
+ "yarn",
86
+ "bun"
87
+ ].find((pm) => agent.startsWith(`${pm}/`)) ?? "npm";
88
+ }
89
+ function fail(message) {
90
+ console.error(`✖ ${message}`);
91
+ process.exit(1);
92
+ }
93
+ async function main() {
94
+ let options;
95
+ try {
96
+ options = parseOptions(process.argv.slice(2));
97
+ } catch (error) {
98
+ console.error(usage);
99
+ fail(error.message);
100
+ }
101
+ if (options.help) {
102
+ console.log(usage);
103
+ return;
104
+ }
105
+ const rl = Boolean(process.stdin.isTTY && process.stdout.isTTY) ? createInterface({
106
+ input: process.stdin,
107
+ output: process.stdout
108
+ }) : void 0;
109
+ const ask = async (question, initial) => rl ? (await rl.question(`${question} (${initial}): `)).trim() || initial : initial;
110
+ try {
111
+ const dir = options.dir ?? await ask("Project directory", DEFAULT_DIR);
112
+ const vue = options.vue ?? (await ask("Vue version, 2 (2.7) or 3", "3") === "2" ? 2 : 3);
113
+ const targetDir = resolve(dir);
114
+ let force = options.force;
115
+ if (!force && (await existingEntries(targetDir)).length) {
116
+ if (!rl) fail(`${dir} is not empty; use --force to overwrite it`);
117
+ const answer = await ask(`${dir} is not empty. Remove its files? y/N`, "N");
118
+ force = /^y(es)?$/i.test(answer);
119
+ if (!force) fail("Cancelled");
120
+ }
121
+ let packageName = toPackageName(dir);
122
+ while (!isValidPackageName(packageName)) {
123
+ if (!rl) fail(`Cannot derive a package name from "${dir}"`);
124
+ packageName = await ask("Package name", "lowcode-materials");
125
+ }
126
+ await createProject({
127
+ targetDir,
128
+ packageName,
129
+ vue,
130
+ force
131
+ });
132
+ const pm = packageManager();
133
+ const cd = relative(process.cwd(), targetDir);
134
+ console.log(`\n✔ Created ${packageName} (Vue ${vue === 2 ? "2.7" : "3"})\n`);
135
+ if (cd) console.log(` cd ${cd.includes(" ") ? `"${cd}"` : cd}`);
136
+ console.log(` ${pm} install`);
137
+ console.log(` ${pm === "npm" || pm === "bun" ? `${pm} run` : pm} dev\n`);
138
+ } finally {
139
+ rl?.close();
140
+ }
141
+ }
142
+ main().catch((error) => fail(error instanceof Error ? error.message : String(error)));
143
+ export {};
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@cdlab996/create-lowcode",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "type": "module",
4
+ "version": "2.0.0",
5
+ "description": "Create a LowCode Engine material project for Vue 2.7 or Vue 3.",
6
+ "author": "wudi <wuchendi96@gmail.com>",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/wuchendi/lowcode-engine-vue/tree/main/packages/tools/create-lowcode",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/wuchendi/lowcode-engine-vue.git",
12
+ "directory": "packages/tools/create-lowcode"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/wuchendi/lowcode-engine-vue/issues"
16
+ },
17
+ "bin": {
18
+ "create-lowcode": "./dist/cli.mjs"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "template",
23
+ "README.md"
24
+ ],
25
+ "engines": {
26
+ "node": ">=20.19"
27
+ },
28
+ "devDependencies": {
29
+ "@cdlab996/lowcode-tsconfig": "1.0.0",
30
+ "@types/node": "^26.6.6",
31
+ "tsdown": "^0.23.7"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "registry": "https://registry.npmjs.org/"
36
+ },
37
+ "scripts": {
38
+ "build": "tsdown",
39
+ "lint:type": "tsc -p ./tsconfig.json --noEmit"
40
+ }
6
41
  }
@@ -0,0 +1,24 @@
1
+ # LowCode materials
2
+
3
+ Vue components and their [LowCode Engine](https://github.com/alibaba/lowcode-engine)
4
+ metas, built with `@cdlab996/lowcode-material-builder`.
5
+
6
+ ## Scripts
7
+
8
+ | Command | Description |
9
+ | ---------------- | ---------------------------------------------------------------------- |
10
+ | `pnpm dev` | Rebuild on change and serve `dist` (load `assets.json` in a designer). |
11
+ | `pnpm build` | Build the components, the metas and `assets.json` into `dist`. |
12
+ | `pnpm lint` | Biome lint and format check. |
13
+ | `pnpm lint:type` | Type-check the components and metas with `vue-tsc`. |
14
+
15
+ ## Layout
16
+
17
+ - `src/index.ts` exports the components.
18
+ - Each component has a `meta.ts` next to it (any `meta.*` / `*.meta.*` under
19
+ `src`); the builder collects them into the meta library.
20
+ - `vite.config.ts` declares the material options with `lowcodeMaterial()`.
21
+
22
+ `vue` is read from the page (`window.Vue`), so it is not bundled.
23
+
24
+ TypeScript stays on 5.x: `vue-tsc` does not run on TypeScript 7 yet.
@@ -0,0 +1,31 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.6.7/schema.json",
3
+ "vcs": {
4
+ "enabled": true,
5
+ "clientKind": "git",
6
+ "useIgnoreFile": true
7
+ },
8
+ "formatter": {
9
+ "indentStyle": "space",
10
+ "indentWidth": 2
11
+ },
12
+ "javascript": {
13
+ "formatter": {
14
+ "quoteStyle": "single",
15
+ "semicolons": "asNeeded"
16
+ }
17
+ },
18
+ "overrides": [
19
+ {
20
+ "includes": ["**/*.vue"],
21
+ "linter": {
22
+ "rules": {
23
+ "correctness": {
24
+ "noUnusedVariables": "off",
25
+ "noUnusedImports": "off"
26
+ }
27
+ }
28
+ }
29
+ }
30
+ ]
31
+ }
@@ -0,0 +1,4 @@
1
+ node_modules
2
+ dist
3
+ *.log
4
+ .DS_Store
@@ -0,0 +1 @@
1
+ export { default as XButton } from './x-button/x-button.vue'
@@ -0,0 +1,25 @@
1
+ import type { IPublicTypeComponentMetadata } from '@alilc/lowcode-types'
2
+
3
+ const meta: IPublicTypeComponentMetadata = {
4
+ componentName: 'XButton',
5
+ title: 'Button',
6
+ group: 'Components',
7
+ category: 'Basic',
8
+ configure: {
9
+ props: [
10
+ { name: 'text', title: 'Text', setter: 'StringSetter' },
11
+ { name: 'color', title: 'Color', setter: 'ColorSetter' },
12
+ ],
13
+ supports: {
14
+ events: [{ name: 'onClick', description: 'Fired when clicked' }],
15
+ },
16
+ },
17
+ snippets: [
18
+ {
19
+ title: 'Button',
20
+ schema: { componentName: 'XButton', props: { text: 'Button' } },
21
+ },
22
+ ],
23
+ }
24
+
25
+ export default meta
@@ -0,0 +1,21 @@
1
+ <template>
2
+ <button class="x-button" :style="{ color }" @click="emit('click', $event)">
3
+ <slot>{{ text }}</slot>
4
+ </button>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ defineProps<{ text?: string; color?: string }>()
9
+
10
+ const emit = defineEmits<{ click: [event: MouseEvent] }>()
11
+ </script>
12
+
13
+ <style scoped>
14
+ .x-button {
15
+ padding: 4px 12px;
16
+ border: 1px solid currentColor;
17
+ border-radius: 4px;
18
+ background: transparent;
19
+ cursor: pointer;
20
+ }
21
+ </style>
@@ -0,0 +1,26 @@
1
+ {
2
+ "type": "module",
3
+ "version": "0.1.0",
4
+ "main": "./dist/index.js",
5
+ "unpkg": "./dist/index.js",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "scripts": {
10
+ "dev": "lowcode-material dev",
11
+ "build": "lowcode-material build --clean",
12
+ "lint": "biome check .",
13
+ "lint:type": "vue-tsc --noEmit"
14
+ },
15
+ "devDependencies": {
16
+ "@alilc/lowcode-types": "^1.3.4",
17
+ "@biomejs/biome": "^2.6.7",
18
+ "@cdlab996/lowcode-material-builder": "^2.0.0",
19
+ "@vitejs/plugin-vue2": "^2.3.4",
20
+ "esbuild": "^0.28.2",
21
+ "typescript": "^5.9.3",
22
+ "vite": "^8.3.8",
23
+ "vue": "2.7.16",
24
+ "vue-tsc": "^3.3.14"
25
+ }
26
+ }
@@ -0,0 +1,8 @@
1
+ # @vitejs/plugin-vue2 compiles `lang="ts"` with esbuild
2
+ allowBuilds:
3
+ esbuild: true
4
+
5
+ peerDependencyRules:
6
+ allowedVersions:
7
+ # @vitejs/plugin-vue2 declares Vite up to 7; it builds with Vite 8
8
+ "@vitejs/plugin-vue2>vite": "8"
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "strict": true,
7
+ "jsx": "preserve",
8
+ "skipLibCheck": true,
9
+ "noEmit": true
10
+ },
11
+ "include": ["src/**/*.ts", "src/**/*.vue", "vite.config.ts"],
12
+ "vueCompilerOptions": {
13
+ "target": 2.7
14
+ }
15
+ }
@@ -0,0 +1,7 @@
1
+ import { lowcodeMaterial } from '@cdlab996/lowcode-material-builder'
2
+ import vue from '@vitejs/plugin-vue2'
3
+ import { defineConfig } from 'vite'
4
+
5
+ export default defineConfig({
6
+ plugins: [vue(), lowcodeMaterial()],
7
+ })
@@ -0,0 +1,25 @@
1
+ {
2
+ "type": "module",
3
+ "version": "0.1.0",
4
+ "main": "./dist/index.js",
5
+ "unpkg": "./dist/index.js",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "scripts": {
10
+ "dev": "lowcode-material dev",
11
+ "build": "lowcode-material build --clean",
12
+ "lint": "biome check .",
13
+ "lint:type": "vue-tsc --noEmit"
14
+ },
15
+ "devDependencies": {
16
+ "@alilc/lowcode-types": "^1.3.4",
17
+ "@biomejs/biome": "^2.6.7",
18
+ "@cdlab996/lowcode-material-builder": "^2.0.0",
19
+ "@vitejs/plugin-vue": "^6.0.11",
20
+ "typescript": "^5.9.3",
21
+ "vite": "^8.3.8",
22
+ "vue": "3.5.45",
23
+ "vue-tsc": "^3.3.14"
24
+ }
25
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "strict": true,
7
+ "jsx": "preserve",
8
+ "skipLibCheck": true,
9
+ "noEmit": true
10
+ },
11
+ "include": ["src/**/*.ts", "src/**/*.vue", "vite.config.ts"]
12
+ }
@@ -0,0 +1,7 @@
1
+ import { lowcodeMaterial } from '@cdlab996/lowcode-material-builder'
2
+ import vue from '@vitejs/plugin-vue'
3
+ import { defineConfig } from 'vite'
4
+
5
+ export default defineConfig({
6
+ plugins: [vue(), lowcodeMaterial()],
7
+ })