@galacean/cli 0.0.1-1 → 0.0.2

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/README.md CHANGED
@@ -1,66 +1,40 @@
1
- Galacean CLI
2
- =================
1
+ # Project Diff
3
2
 
4
- The all-in-one Galacean CLI that helps you build Galacean applications.
3
+ ## Usage
5
4
 
6
- <!-- toc -->
7
- * [Usage](#usage)
8
- * [Commands](#commands)
9
- <!-- tocstop -->
10
- # Usage
11
- <!-- usage -->
12
- ```sh-session
13
- $ npm install -g @galacean/cli
14
- $ galacean COMMAND
15
- running command...
16
- $ galacean (--version)
17
- @galacean/cli/0.0.1-1 darwin-x64 node-v16.17.0
18
- $ galacean --help [COMMAND]
19
- USAGE
20
- $ galacean COMMAND
21
- ...
22
- ```
23
- <!-- usagestop -->
24
- # Commands
25
- <!-- commands -->
26
- * [`galacean generate NAME`](#galacean-generate-name)
27
- * [`galacean help [COMMANDS]`](#galacean-help-commands)
28
-
29
- ## `galacean generate NAME`
30
-
31
- generate a new Galacean Editor plugin
5
+ ```bash
6
+ $ npm i -g @galacean/cli
32
7
 
8
+ galacean diff <project1-url> <project2-url>
33
9
  ```
34
- USAGE
35
- $ galacean generate NAME
36
10
 
37
- ARGUMENTS
38
- NAME directory name of new plugin
11
+ 执行命令后会在命令文件夹下生成『项目 diff.md』文件,可以打开查看 diff 数据。
39
12
 
40
- DESCRIPTION
41
- generate a new Galacean Editor plugin
42
- This will clone the specific folder in 'galacean/galacean-editor-plugin-examples' and update package properties
43
- ```
44
13
 
45
- _See code: [dist/commands/generate.ts](https://github.com/galacean/cli/blob/v0.0.1-1/dist/commands/generate.ts)_
46
14
 
47
- ## `galacean help [COMMANDS]`
15
+ ## 测试 case
48
16
 
49
- Display help for galacean.
17
+ project: https://local.alipay.net:4000/#/project/24400002
50
18
 
51
- ```
52
- USAGE
53
- $ galacean help [COMMANDS] [-n]
19
+ - 资产
54
20
 
55
- ARGUMENTS
56
- COMMANDS Command to show help for.
21
+ - [ ] 资产新增
22
+ - https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*3htQQZ8Fa0sAAAAAAAAAAAAADnN-AQ/project.json https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*smcAQqM3oy0AAAAAAAAAAAAADnN-AQ/project.json
23
+ - [ ] 资产移除
24
+ - https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*smcAQqM3oy0AAAAAAAAAAAAADnN-AQ/project.json https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*3htQQZ8Fa0sAAAAAAAAAAAAADnN-AQ/project.json
57
25
 
58
- FLAGS
59
- -n, --nested-commands Include all nested commands in the output.
26
+ - 场景
60
27
 
61
- DESCRIPTION
62
- Display help for galacean.
63
- ```
28
+ - Entity
29
+ - [x] Entity 新增
30
+ - https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*vuobSqCRjRcAAAAAAAAAAAAADnN-AQ/project.json https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*px25TbJo7CYAAAAAAAAAAAAADnN-AQ/project.json
31
+ - [x] Entity 移除
32
+ - https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*px25TbJo7CYAAAAAAAAAAAAADnN-AQ/project.json https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*vuobSqCRjRcAAAAAAAAAAAAADnN-AQ/project.json
33
+ - 组件
34
+ - [ ] 组件新增
35
+ - https://mdn.alipayobjects.com/oasis_be/afts/file/A*R9kHQZQhOtUAAAAAAAAAAAAADkp5AQ/project.json https://mdn.alipayobjects.com/oasis_be/afts/file/A*yB3uQKIU6HUAAAAAAAAAAAAADkp5AQ/project.json
36
+ - [ ] 组件移除
37
+ - https://mdn.alipayobjects.com/oasis_be/afts/file/A*yB3uQKIU6HUAAAAAAAAAAAAADkp5AQ/project.json https://mdn.alipayobjects.com/oasis_be/afts/file/A*R9kHQZQhOtUAAAAAAAAAAAAADkp5AQ/project.json
64
38
 
65
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.14/src/commands/help.ts)_
66
- <!-- commandsstop -->
39
+ - 复合 case
40
+ - https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*Y9y2R784BXUAAAAAAAAAAAAADnN-AQ/project.json https://mmtcdp.stable.alipay.net/oasis_be/afts/file/A*OsYURKUVT9YAAAAAAAAAAAAADnN-AQ/project.json
package/bin/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import "../lib/cli.js";
@@ -0,0 +1,18 @@
1
+ import fs from "fs-extra";
2
+ import path from "path";
3
+ export class Markdown {
4
+ _txt = "";
5
+ get txt() {
6
+ return this._txt;
7
+ }
8
+ addLine(line, tab = 0) {
9
+ for (let i = 0; i < tab; i++) {
10
+ line = "\t" + line;
11
+ }
12
+ this._txt += line + "\n";
13
+ }
14
+ generate() {
15
+ fs.writeFileSync(path.join(process.cwd(), "项目 Diff.md"), this._txt);
16
+ }
17
+ }
18
+ export const markdown = new Markdown();
package/lib/cli.js ADDED
@@ -0,0 +1,28 @@
1
+ import { cac } from "cac";
2
+ import path from "path";
3
+ import fs from "fs-extra";
4
+ import * as url from "url";
5
+ import { diffProjects } from "./diff.js";
6
+ import { getFileBufferFromUrl } from "./utils.js";
7
+ import { markdown } from "./Markdown.js";
8
+ const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
9
+ const cli = cac();
10
+ cli.command("diff [...files]", "diff files").action((files) => {
11
+ markdown.addLine("# 资产 Diff");
12
+ markdown.addLine(``);
13
+ markdown.addLine(`- ${files[0]}`);
14
+ markdown.addLine(`- ${files[1]}`);
15
+ markdown.addLine(``);
16
+ Promise.all([
17
+ getFileBufferFromUrl(files[0]),
18
+ getFileBufferFromUrl(files[1]),
19
+ ]).then(async (res) => {
20
+ const result = res.map((item) => JSON.parse(item.toString()));
21
+ await diffProjects(result[0], result[1]);
22
+ markdown.generate();
23
+ });
24
+ });
25
+ const pkg = fs.readJSONSync(path.join(__dirname, "../package.json"));
26
+ cli.help();
27
+ cli.version(pkg.version);
28
+ cli.parse();
package/lib/diff.js ADDED
@@ -0,0 +1,155 @@
1
+ import { Operation, diff, flattenChangeset } from "json-diff-ts";
2
+ import { groupBy, cloneDeep } from "lodash-es";
3
+ import { getFileBufferFromUrl } from "./utils.js";
4
+ import { markdown } from "./Markdown.js";
5
+ export async function diffProjects(project1, project2) {
6
+ const result = diff(project1, project2, { files: "id" });
7
+ const changes = flattenChangeset(result);
8
+ const assets1 = {};
9
+ const assets2 = {};
10
+ project1.files.forEach((item) => {
11
+ assets1[item.id] = item;
12
+ });
13
+ project2.files.forEach((item) => {
14
+ assets2[item.id] = item;
15
+ });
16
+ const diffs = groupBy(changes, "type");
17
+ const sceneChanges = [];
18
+ markdown.addLine("## 资产");
19
+ markdown.addLine(``);
20
+ markdown.addLine(`- 资产新增`);
21
+ diffs[Operation.ADD]?.forEach((item) => {
22
+ markdown.addLine(`- ${item.value.virtualPath}`, 1);
23
+ });
24
+ markdown.addLine(``);
25
+ markdown.addLine(`- 资产移除`);
26
+ diffs[Operation.REMOVE]?.forEach((item) => {
27
+ markdown.addLine(`- ${item.value.virtualPath}`, 1);
28
+ });
29
+ // markdown.addLine(``);
30
+ // markdown.addLine(`- 资产修改`);
31
+ // markdown.addLine(``);
32
+ diffs[Operation.UPDATE]?.forEach((item) => {
33
+ const id = getIdFromPath(item.path);
34
+ const asset = assets1[id];
35
+ if (asset.type === "Scene") {
36
+ sceneChanges.push(asset);
37
+ }
38
+ // markdown.addLine(`- ${asset.virtualPath}`, 1);
39
+ });
40
+ markdown.addLine(``);
41
+ markdown.addLine("## 场景");
42
+ markdown.addLine(``);
43
+ await Promise.all(sceneChanges.map((asset) => {
44
+ markdown.addLine(`### ${assets2[asset.id].virtualPath}`);
45
+ markdown.addLine(``);
46
+ return diffScene(asset.path, assets2[asset.id].path);
47
+ }));
48
+ }
49
+ async function diffScene(url1, url2) {
50
+ const [scene1, scene2] = await Promise.all([
51
+ getFileBufferFromUrl(url1),
52
+ getFileBufferFromUrl(url2),
53
+ ]).then((res) => res.map((item) => JSON.parse(item.toString())));
54
+ const { diffObj: diffObj1, entities } = getEntities(scene1);
55
+ const { diffObj: diffObj2, entities: newEntities } = getEntities(scene2);
56
+ const changes = flattenChangeset(diff(diffObj1, diffObj2));
57
+ // const changesGroup = groupBy(changes, "type");
58
+ // markdown.addLine(``);
59
+ // markdown.addLine(`- Entity 移除`);
60
+ // changesGroup[Operation.REMOVE]?.forEach((item) => {
61
+ // markdown.addLine(`- ${entities[item.key].name}`, 1);
62
+ // });
63
+ const groups = groupBy(changes, (item) => {
64
+ if (item.path.includes(".components")) {
65
+ return "components";
66
+ }
67
+ return "entities";
68
+ });
69
+ if (groups["entities"]) {
70
+ markdown.addLine(`#### Entities`);
71
+ markdown.addLine("");
72
+ const changesGroup = groupBy(groups["entities"], "type");
73
+ markdown.addLine(`- 新增`);
74
+ changesGroup[Operation.ADD]?.forEach((item) => {
75
+ const entityPath = getEntityPath(item.key, newEntities);
76
+ markdown.addLine(`- ${entityPath}`, 1);
77
+ });
78
+ markdown.addLine(`- 移除`);
79
+ changesGroup[Operation.REMOVE]?.forEach((item) => {
80
+ const entityPath = getEntityPath(item.key, entities);
81
+ markdown.addLine(`- ${entityPath}`, 1);
82
+ });
83
+ }
84
+ if (groups["components"]) {
85
+ markdown.addLine(``);
86
+ markdown.addLine(`#### 组件`);
87
+ markdown.addLine("");
88
+ const changesGroup = groupBy(groups["components"], "type");
89
+ markdown.addLine(`- 新增`);
90
+ changesGroup[Operation.ADD]?.forEach((item) => {
91
+ const entityId = getComponentEntityId(item.path);
92
+ const entityPath = getEntityPath(entityId, entities);
93
+ const comp = item.value;
94
+ markdown.addLine(`- ${entityPath} [${comp["class"]}]`, 1);
95
+ });
96
+ markdown.addLine(`- 移除`);
97
+ changesGroup[Operation.REMOVE]?.forEach((item) => {
98
+ const entityId = getComponentEntityId(item.path);
99
+ const entityPath = getEntityPath(entityId, entities);
100
+ const comp = item.value;
101
+ markdown.addLine(`- ${entityPath} [${comp["class"]}]`, 1);
102
+ });
103
+ }
104
+ }
105
+ function getComponentEntityId(str) {
106
+ let regex = /\.([^.]*?)\.components/;
107
+ let matches = str.match(regex);
108
+ if (matches) {
109
+ return matches[1];
110
+ }
111
+ }
112
+ function getEntityPath(id, entities) {
113
+ const routes = [];
114
+ let entity = entities[id];
115
+ while (entity) {
116
+ routes.unshift(entity.name);
117
+ entity = entities[entity.parent];
118
+ }
119
+ return routes.join("/");
120
+ }
121
+ function getEntities(scene) {
122
+ const obj = {};
123
+ scene.entities.forEach((item) => {
124
+ const comps = {};
125
+ item.components.forEach((comp) => {
126
+ comps[comp.id] = comp;
127
+ });
128
+ item.components = comps;
129
+ item.children = {};
130
+ obj[item.id] = item;
131
+ });
132
+ const entities = cloneDeep(obj);
133
+ const hasParentItems = [];
134
+ scene.entities.forEach((item) => {
135
+ if (item.parent) {
136
+ obj[item.parent].children[item.id] = item;
137
+ hasParentItems.push(item.id);
138
+ }
139
+ });
140
+ hasParentItems.forEach((id) => {
141
+ delete obj[id];
142
+ });
143
+ return { diffObj: obj, entities };
144
+ }
145
+ function getIdFromPath(str) {
146
+ const regex = /id=='([^']+)'/;
147
+ const match = str.match(regex);
148
+ if (match) {
149
+ const id = match[1]; // 提取的 id 值
150
+ return id;
151
+ }
152
+ else {
153
+ console.log("No match found");
154
+ }
155
+ }
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./cli.js";
package/lib/type.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/utils.js ADDED
@@ -0,0 +1,128 @@
1
+ import https from "https";
2
+ import http from "http";
3
+ import fs from "fs-extra";
4
+ import path from "path";
5
+ import fetch from "node-fetch";
6
+ import { URL } from "url";
7
+ export function streamToBuffer(stream) {
8
+ return new Promise((resolve, reject) => {
9
+ const buffers = [];
10
+ stream.on("error", reject);
11
+ // @ts-ignore
12
+ stream.on("data", (data) => buffers.push(data));
13
+ stream.on("end", () => resolve(Buffer.concat(buffers)));
14
+ });
15
+ }
16
+ export function streamToString(stream) {
17
+ const chunks = [];
18
+ return new Promise((resolve, reject) => {
19
+ stream.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
20
+ stream.on("error", (err) => reject(err));
21
+ stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
22
+ });
23
+ }
24
+ export function toBuffer(view) {
25
+ const buf = Buffer.alloc(view.byteLength);
26
+ for (let i = 0; i < buf.length; ++i) {
27
+ buf[i] = view[i];
28
+ }
29
+ return buf;
30
+ }
31
+ export function urlToBuffer(url) {
32
+ return new Promise((resolve) => {
33
+ let req = url.startsWith("https://")
34
+ ? https.get(url, callback)
35
+ : http.get(url, callback);
36
+ let body = "";
37
+ function callback(res) {
38
+ res.on("data", (chunk) => {
39
+ body += chunk;
40
+ });
41
+ res.on("end", () => {
42
+ resolve(Buffer.from(body));
43
+ });
44
+ }
45
+ });
46
+ }
47
+ export function getUrlSize(url, attempts = 0) {
48
+ return new Promise((res, rej) => {
49
+ let req = url.startsWith("https://") ? https.get(url) : http.get(url);
50
+ req.once("response", (r) => {
51
+ req.destroy();
52
+ if (r.statusCode >= 300 && r.statusCode < 400 && r.headers.location) {
53
+ if (attempts > 5) {
54
+ return rej(new Error("Too many redirects"));
55
+ }
56
+ return res(getUrlSize(r.headers.location, attempts + 1));
57
+ }
58
+ let c = parseInt(r.headers["content-length"]);
59
+ if (!isNaN(c))
60
+ res(c);
61
+ else
62
+ rej("Couldn't get file size");
63
+ });
64
+ req.once("error", (e) => rej(e));
65
+ });
66
+ }
67
+ export function sum(array) {
68
+ let sum = 0;
69
+ for (let i = 0; i < array.length; i++) {
70
+ sum += array[i];
71
+ }
72
+ return sum;
73
+ }
74
+ export async function getBufferAndNameFromUri(uri) {
75
+ let buffer;
76
+ let name;
77
+ const isUrl = /^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(uri);
78
+ if (isUrl) {
79
+ buffer = await urlToBuffer(uri);
80
+ const urlRegex = /\/([^/]+\.[^/.]+)$/;
81
+ const matches = uri.match(urlRegex);
82
+ if (matches) {
83
+ name = matches[1];
84
+ }
85
+ else {
86
+ name = "noname";
87
+ }
88
+ }
89
+ else {
90
+ uri = uri ?? ".";
91
+ const filepath = path.isAbsolute(uri) ? uri : path.join(process.cwd(), uri);
92
+ const stream = await fs.createReadStream(filepath);
93
+ buffer = await streamToBuffer(stream);
94
+ name = path.basename(filepath);
95
+ }
96
+ return { buffer, name };
97
+ }
98
+ export function stringIsAValidUrl(s) {
99
+ try {
100
+ new URL(s);
101
+ return true;
102
+ }
103
+ catch (err) {
104
+ return false;
105
+ }
106
+ }
107
+ export function getFileBufferFromUrl(url) {
108
+ if (stringIsAValidUrl(url)) {
109
+ return fetch(url)
110
+ .then((response) => response.arrayBuffer())
111
+ .then((ab) => Buffer.from(ab));
112
+ }
113
+ else {
114
+ const filepath = path.isAbsolute(url) ? url : path.join(process.cwd(), url);
115
+ return new Promise((resolve, reject) => {
116
+ fs.readFile(filepath, (err, data) => {
117
+ if (err)
118
+ reject(err);
119
+ resolve(data);
120
+ });
121
+ });
122
+ }
123
+ }
124
+ export function getNameFromUrl(uri) {
125
+ const urlRegex = /\/([^/]+\.[^/.]+)$/;
126
+ const matches = uri.match(urlRegex);
127
+ return matches ? matches[1] : "noname";
128
+ }
package/package.json CHANGED
@@ -1,73 +1,43 @@
1
1
  {
2
2
  "name": "@galacean/cli",
3
- "version": "0.0.1-1",
4
- "description": "All-in-one cli tool that help you using Galacean Framework.",
5
- "author": "Kbscript @MrKou47",
3
+ "version": "0.0.2",
4
+ "main": "index.js",
5
+ "type": "module",
6
+ "author": {
7
+ "name": "gz65555",
8
+ "email": "gz65555@gmail.com"
9
+ },
10
+ "scripts": {
11
+ "dev": "tsc -w",
12
+ "build": "tsc"
13
+ },
6
14
  "bin": {
7
- "galacean": "./bin/run"
15
+ "galacean": "./bin/cli.js"
8
16
  },
9
- "homepage": "https://github.com/galacean/cli",
10
- "license": "MIT",
11
- "main": "dist/index.js",
12
- "repository": "galacean/cli",
13
17
  "files": [
14
- "/bin",
15
- "/dist",
16
- "/npm-shrinkwrap.json",
17
- "/oclif.manifest.json"
18
+ "dist",
19
+ "bin",
20
+ "lib",
21
+ "types"
18
22
  ],
19
- "dependencies": {
20
- "@oclif/core": "^2",
21
- "@oclif/plugin-help": "^5",
22
- "@oclif/plugin-plugins": "^2.4.7",
23
- "yeoman-environment": "^3.19.3",
24
- "yeoman-generator": "^5.9.0"
25
- },
23
+ "types": "types",
24
+ "license": "MIT",
26
25
  "devDependencies": {
27
- "@oclif/test": "^2.4.0",
28
- "@types/chai": "^4",
29
- "@types/mocha": "^9.0.0",
30
- "@types/node": "^16.18.39",
31
- "@types/yeoman-generator": "^5.2.11",
32
- "chai": "^4",
33
- "eslint": "^7.32.0",
34
- "eslint-config-oclif": "^4",
35
- "eslint-config-oclif-typescript": "^1.0.3",
36
- "mocha": "^9",
37
- "oclif": "^3.10.0",
38
- "shx": "^0.3.3",
39
- "ts-node": "^10.9.1",
40
- "tslib": "^2.6.1",
41
- "typescript": "^4.9.5"
26
+ "@types/fs-extra": "^9.0.12",
27
+ "@types/inquirer": "^7.3.3",
28
+ "prettier": "^2.3.2",
29
+ "typescript": "^5"
42
30
  },
43
- "oclif": {
44
- "bin": "galacean",
45
- "dirname": "galacean",
46
- "commands": "./dist/commands",
47
- "plugins": [
48
- "@oclif/plugin-help"
49
- ]
50
- },
51
- "scripts": {
52
- "build": "shx rm -rf dist && tsc -b",
53
- "lint": "eslint . --ext .ts --config .eslintrc",
54
- "postpack": "shx rm -f oclif.manifest.json",
55
- "posttest": "npm run lint",
56
- "prepack": "npm run build && oclif manifest && oclif readme",
57
- "test": "mocha --forbid-only \"test/**/*.test.ts\"",
58
- "version": "oclif readme && git add README.md"
59
- },
60
- "engines": {
61
- "node": ">=12.0.0"
62
- },
63
- "bugs": "https://github.com/galacean/cli/issues",
64
- "keywords": [
65
- "galacean",
66
- "cli",
67
- "plugin"
68
- ],
69
- "types": "dist/index.d.ts",
70
- "publishConfig": {
71
- "registry": "https://registry.npmjs.org"
31
+ "dependencies": {
32
+ "@types/lodash": "^4.14.202",
33
+ "@types/lodash-es": "^4.17.12",
34
+ "cac": "^6.7.3",
35
+ "chalk": "^5.3.0",
36
+ "fs-extra": "^10.0.0",
37
+ "inquirer": "^8.1.2",
38
+ "json-diff-ts": "^2.2.1",
39
+ "lodash": "^4.17.21",
40
+ "lodash-es": "^4.17.21",
41
+ "node-fetch": "^3.3.2"
72
42
  }
73
43
  }
@@ -0,0 +1,7 @@
1
+ export declare class Markdown {
2
+ private _txt;
3
+ get txt(): string;
4
+ addLine(line: string, tab?: number): void;
5
+ generate(): void;
6
+ }
7
+ export declare const markdown: Markdown;
package/types/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare function diffProjects(project1: any, project2: any): Promise<void>;
@@ -0,0 +1 @@
1
+ export * from "./cli.js";
@@ -0,0 +1,15 @@
1
+ export type IVector3 = {
2
+ x: number;
3
+ y: number;
4
+ z: number;
5
+ };
6
+ export type IEntity = {
7
+ id: string;
8
+ name: string;
9
+ isActive: boolean;
10
+ position: IVector3;
11
+ rotation: IVector3;
12
+ scale: IVector3;
13
+ parent: string;
14
+ isClone: boolean;
15
+ };
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ export declare function streamToBuffer(stream: any): Promise<Buffer>;
3
+ export declare function streamToString(stream: any): Promise<string>;
4
+ export declare function toBuffer(view: Uint8Array): Buffer;
5
+ export declare function urlToBuffer(url: string): Promise<Buffer>;
6
+ export declare function getUrlSize(url: string, attempts?: number): Promise<number>;
7
+ export declare function sum(array: ArrayLike<number>): number;
8
+ export declare function getBufferAndNameFromUri(uri: any): Promise<{
9
+ buffer: any;
10
+ name: any;
11
+ }>;
12
+ export declare function stringIsAValidUrl(s: string): boolean;
13
+ export declare function getFileBufferFromUrl(url: string): Promise<Buffer>;
14
+ export declare function getNameFromUrl(uri: string): string;
package/bin/dev DELETED
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const oclif = require('@oclif/core')
4
-
5
- const path = require('path')
6
- const project = path.join(__dirname, '..', 'tsconfig.json')
7
-
8
- // In dev mode -> use ts-node and dev plugins
9
- process.env.NODE_ENV = 'development'
10
-
11
- require('ts-node').register({ project })
12
-
13
- // In dev mode, always show stack traces
14
- oclif.settings.debug = true;
15
-
16
- // Start the CLI
17
- oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
package/bin/dev.cmd DELETED
@@ -1,3 +0,0 @@
1
- @echo off
2
-
3
- node "%~dp0\dev" %*
package/bin/run DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const oclif = require('@oclif/core')
4
-
5
- oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'))
package/bin/run.cmd DELETED
@@ -1,3 +0,0 @@
1
- @echo off
2
-
3
- node "%~dp0\run" %*
@@ -1,10 +0,0 @@
1
- import { Command } from '@oclif/core';
2
- export default class Generate extends Command {
3
- static description: string;
4
- static flags: {};
5
- static args: {
6
- name: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
7
- };
8
- protected generate(type?: string, generatorOptions?: Record<string, unknown>): Promise<void>;
9
- run(): Promise<void>;
10
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@oclif/core");
4
- const yeoman_environment_1 = require("yeoman-environment");
5
- class Generate extends core_1.Command {
6
- async generate(type = 'plugin', generatorOptions = {}) {
7
- const env = (0, yeoman_environment_1.createEnv)();
8
- env.register(require.resolve(`../generators/${type}`), `galacean:${type}`);
9
- await env.run(`galacean:${type}`, generatorOptions);
10
- }
11
- async run() {
12
- const { args } = await this.parse(Generate);
13
- await this.generate('plugin', { name: args.name, force: true });
14
- }
15
- }
16
- exports.default = Generate;
17
- Generate.description = `generate a new Galacean Editor plugin
18
- This will clone the specific folder in 'galacean/galacean-editor-plugin-examples' and update package properties`;
19
- Generate.flags = {};
20
- Generate.args = {
21
- name: core_1.Args.string({ required: true, description: 'directory name of new plugin' }),
22
- };
@@ -1,33 +0,0 @@
1
- import * as Generator from 'yeoman-generator';
2
- export default class PluginGenerator extends Generator {
3
- options: {
4
- force: boolean;
5
- };
6
- exampleRepoUrl: string;
7
- name: string;
8
- pjson: any;
9
- githubUser: string;
10
- answers: {
11
- name: string;
12
- bin: string;
13
- description: string;
14
- version: string;
15
- github: {
16
- repo: string;
17
- user: string;
18
- };
19
- author: string;
20
- files: string;
21
- license: string;
22
- galacean: string;
23
- pkg: string;
24
- typescript: boolean;
25
- eslint: boolean;
26
- };
27
- repository?: string;
28
- constructor(args: string | string[], opts: Generator.GeneratorOptions);
29
- prompting(): Promise<void>;
30
- writing(): void;
31
- end(): void;
32
- private _gitignore;
33
- }
@@ -1,176 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const child_process_1 = require("child_process");
4
- const fs = require("fs");
5
- const _ = require("lodash");
6
- const path = require("path");
7
- const nodeDebug = require("debug");
8
- const Generator = require("yeoman-generator");
9
- const debug = nodeDebug('galacean-plugin-generator');
10
- const { version } = require('../../package.json');
11
- class PluginGenerator extends Generator {
12
- constructor(args, opts) {
13
- super(args, opts);
14
- this.exampleRepoUrl = 'https://github.com/galacean/galacean-editor-plugin-examples';
15
- this.githubUser = '';
16
- this.name = opts.name;
17
- this.options.force = opts.force;
18
- }
19
- async prompting() {
20
- this.log(`Galacean Editor Plugin Generator. version: ${version}`);
21
- const { pluginType } = await this.prompt([
22
- {
23
- type: 'list',
24
- name: 'pluginType',
25
- message: 'Select a plugin type',
26
- choices: [
27
- { name: 'Basic', value: 'basic' },
28
- { name: 'React', value: 'react' },
29
- ],
30
- default: 'blank',
31
- },
32
- ]);
33
- const targetDir = path.resolve(this.name);
34
- (0, child_process_1.execSync)(`git clone ${this.exampleRepoUrl} "${targetDir}" --depth=1`);
35
- for (const f of fs.readdirSync(path.resolve(this.name)).filter(file => file !== pluginType)) {
36
- const p = `${path.resolve(this.name, f)}`;
37
- this.log(p);
38
- fs.rmSync(p, { recursive: true, force: true });
39
- }
40
- (0, child_process_1.execSync)(`mv ${path.resolve(this.name, pluginType, '*')} ${path.resolve(this.name)}`);
41
- fs.rmSync(`${path.resolve(this.name, pluginType)}`, { recursive: true, force: true });
42
- this.destinationRoot(path.resolve(this.name));
43
- this.env.cwd = this.destinationPath();
44
- try {
45
- this.githubUser = await this.user.github.username();
46
- }
47
- catch (error) {
48
- debug(error);
49
- }
50
- this.pjson = {
51
- name: '',
52
- version: '',
53
- description: '',
54
- author: '',
55
- bin: {},
56
- homepage: '',
57
- license: '',
58
- main: '',
59
- repository: '',
60
- files: [],
61
- dependencies: {},
62
- devDependencies: {},
63
- galacean: '',
64
- scripts: {},
65
- engines: {},
66
- ...this.fs.readJSON(path.join(this.env.cwd, 'package.json'), {}),
67
- };
68
- let repository = this.destinationRoot().split(path.sep).slice(-2).join('/');
69
- if (this.githubUser) {
70
- repository = `${this.githubUser}/${repository.split('/')[1]}`;
71
- }
72
- const defaults = {
73
- ...this.pjson,
74
- name: (this.name || this.determineAppname()).replace(/ /g, '-'),
75
- version: '0.0.0',
76
- license: 'MIT',
77
- author: this.githubUser ? `${this.user.git.name()} @${this.githubUser}` : this.user.git.name(),
78
- dependencies: {},
79
- repository,
80
- engines: {
81
- node: '>=12.0.0',
82
- ...this.pjson.engines,
83
- },
84
- };
85
- this.repository = defaults.repository;
86
- if (this.repository && this.repository.url) {
87
- this.repository = this.repository.url;
88
- }
89
- this.answers = await this.prompt([
90
- {
91
- type: 'input',
92
- name: 'name',
93
- message: 'plugin package name',
94
- default: defaults.name,
95
- },
96
- {
97
- type: 'input',
98
- name: 'description',
99
- message: 'description',
100
- default: defaults.description,
101
- },
102
- {
103
- type: 'input',
104
- name: 'author',
105
- message: 'author',
106
- default: defaults.author,
107
- },
108
- {
109
- type: 'input',
110
- name: 'galacean',
111
- message: 'The minimum version of Galacean that this plugin supports',
112
- default: defaults.galacean,
113
- },
114
- {
115
- type: 'input',
116
- name: 'license',
117
- message: 'license',
118
- default: defaults.license,
119
- },
120
- {
121
- type: 'input',
122
- name: 'github.user',
123
- message: 'Who is the GitHub owner of repository (https://github.com/OWNER/repo)',
124
- default: repository.split('/').slice(0, -1).pop(),
125
- },
126
- {
127
- type: 'input',
128
- name: 'github.repo',
129
- message: 'What is the GitHub name of repository (https://github.com/owner/REPO)',
130
- default: (answers) => (answers.name || this.pjson.repository || this.pjson.name).split('/').pop(),
131
- },
132
- ]);
133
- debug(this.answers);
134
- this.pjson.name = this.answers.name || defaults.name;
135
- this.pjson.description = this.answers.description || defaults.description;
136
- this.pjson.version = this.answers.version || defaults.version;
137
- this.pjson.engines.node = defaults.engines.node;
138
- this.pjson.author = this.answers.author || defaults.author;
139
- this.pjson.files = this.answers.files || defaults.files || '/lib';
140
- this.pjson.license = this.answers.license || defaults.license;
141
- // eslint-disable-next-line no-multi-assign
142
- this.repository = this.pjson.repository = this.answers.github ? `${this.answers.github.user}/${this.answers.github.repo}` : defaults.repository;
143
- this.pjson.homepage = `https://github.com/${this.repository}`;
144
- this.pjson.bugs = `https://github.com/${this.repository}/issues`;
145
- }
146
- writing() {
147
- this.pjson.files = _.uniq((this.pjson.files || []).sort());
148
- this.fs.writeJSON(this.destinationPath('./package.json'), this.pjson);
149
- this.fs.write(this.destinationPath('.gitignore'), this._gitignore());
150
- this.fs.delete(this.destinationPath('LICENSE'));
151
- }
152
- end() {
153
- var _a;
154
- if ((_a = this.pjson.scripts) === null || _a === void 0 ? void 0 : _a.build) {
155
- this.spawnCommandSync(this.env.options.nodePackageManager, ['run', 'build'], { cwd: this.env.cwd });
156
- }
157
- this.log(`\nCreated ${this.pjson.name} in ${this.destinationRoot()}`);
158
- }
159
- _gitignore() {
160
- const existing = this.fs.exists(this.destinationPath('.gitignore')) ? this.fs.read(this.destinationPath('.gitignore')).split('\n') : [];
161
- return _([
162
- '*-debug.log',
163
- '*-error.log',
164
- 'node_modules',
165
- '/tmp',
166
- '/dist',
167
- '/lib',
168
- ])
169
- .concat(existing)
170
- .compact()
171
- .uniq()
172
- .sort()
173
- .join('\n') + '\n';
174
- }
175
- }
176
- exports.default = PluginGenerator;
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { run } from '@oclif/core';
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.run = void 0;
4
- var core_1 = require("@oclif/core");
5
- Object.defineProperty(exports, "run", { enumerable: true, get: function () { return core_1.run; } });
@@ -1,22 +0,0 @@
1
- {
2
- "version": "0.0.1-1",
3
- "commands": {
4
- "generate": {
5
- "id": "generate",
6
- "description": "generate a new Galacean Editor plugin\nThis will clone the specific folder in 'galacean/galacean-editor-plugin-examples' and update package properties",
7
- "strict": true,
8
- "pluginName": "@galacean/cli",
9
- "pluginAlias": "@galacean/cli",
10
- "pluginType": "core",
11
- "aliases": [],
12
- "flags": {},
13
- "args": {
14
- "name": {
15
- "name": "name",
16
- "description": "directory name of new plugin",
17
- "required": true
18
- }
19
- }
20
- }
21
- }
22
- }