hubbe-sdk 1.2.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 (36) hide show
  1. package/bin/.token +1 -0
  2. package/bin/build.js +94 -0
  3. package/bin/defaultHtml.html +23 -0
  4. package/bin/defaultJs.js +49 -0
  5. package/bin/deploy.js +130 -0
  6. package/bin/deployTs.js +157 -0
  7. package/bin/fetch.js +118 -0
  8. package/bin/htmlu.js +116 -0
  9. package/bin/index.js +77 -0
  10. package/bin/react-template/html/eslint.config.js +28 -0
  11. package/bin/react-template/html/index.html +7 -0
  12. package/bin/react-template/html/package.json +34 -0
  13. package/bin/react-template/html/postcss.config.js +6 -0
  14. package/bin/react-template/html/src/App.tsx +33 -0
  15. package/bin/react-template/html/src/hooks/index.ts +3 -0
  16. package/bin/react-template/html/src/hooks/useDraggable.ts +69 -0
  17. package/bin/react-template/html/src/hooks/useMessageEvent.ts +120 -0
  18. package/bin/react-template/html/src/hooks/useUserContext.ts +24 -0
  19. package/bin/react-template/html/src/index.css +5 -0
  20. package/bin/react-template/html/src/main.tsx +10 -0
  21. package/bin/react-template/html/src/vite-env.d.ts +1 -0
  22. package/bin/react-template/html/tailwind.config.js +12 -0
  23. package/bin/react-template/html/tsconfig.app.json +24 -0
  24. package/bin/react-template/html/tsconfig.json +7 -0
  25. package/bin/react-template/html/tsconfig.node.json +22 -0
  26. package/bin/react-template/html/vite.config.ts +10 -0
  27. package/bin/react-template/room/global.d.ts +4222 -0
  28. package/bin/react-template/room/room.ts +36 -0
  29. package/bin/react-template/room/tsconfig.json +9 -0
  30. package/bin/react.js +60 -0
  31. package/bin/rollup.js +67 -0
  32. package/bin/rollupTs.js +72 -0
  33. package/bin/script.js +131 -0
  34. package/bin/tsconfig_template.json +9 -0
  35. package/bin/utils.js +35 -0
  36. package/package.json +57 -0
@@ -0,0 +1,36 @@
1
+ const isDebbuging = true;
2
+ const interfaceEnabled = true;
3
+
4
+ const events = new Map<string, (entity: ScriptEntity, value: unknown) => void>();
5
+
6
+ events.set("%workspaceName%-ready", (entity: ScriptEntity) => {
7
+ entity.sendUIMessage('%workspaceName%-update-user', JSON.stringify({ user: { name: entity.getUsername() } }));
8
+ });
9
+
10
+ const emitClientEvent = (entity: ScriptEntity, eventName: string, value: string) => {
11
+ if (!interfaceEnabled)
12
+ return;
13
+
14
+ if (isDebbuging)
15
+ Debug.log(`Received event: ${eventName} from ${entity.getUsername()}`);
16
+
17
+ const exec = events.get(eventName);
18
+ if (exec) {
19
+ try {
20
+ const parsed = JSON.parse(value);
21
+ exec(entity, parsed);
22
+ } catch (error) {
23
+ entity.notification('generic', 'Alguma coisa deu errado.');
24
+
25
+ if (isDebbuging)
26
+ Debug.log(`Error on event: ${eventName} - ${error}`);
27
+ }
28
+ }
29
+ };
30
+
31
+ Events.on('uiMessage', emitClientEvent);
32
+
33
+ Events.on('userJoin', (entity: ScriptEntity) => {
34
+ if (interfaceEnabled)
35
+ entity.loadUI('%workspaceName%', 'index');
36
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2019",
4
+ "module": "ESNext",
5
+ "esModuleInterop": true,
6
+ "forceConsistentCasingInFileNames": true,
7
+ "strict": true
8
+ }
9
+ }
package/bin/react.js ADDED
@@ -0,0 +1,60 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const {Signale} = require('signale');
4
+
5
+ class Script {
6
+ constructor(name) {
7
+ this.name = name;
8
+ this.directory = path.join(process.cwd(), name);
9
+ this.templateDir = path.join(__dirname, 'react-template');
10
+ this.exec();
11
+ }
12
+
13
+ exec() {
14
+ this.copyTemplate(this.templateDir, this.directory);
15
+ const signale = new Signale();
16
+ signale.success(`Projeto "${this.name}" criado com sucesso.`);
17
+
18
+ signale.info('Iniciando a instalação das dependências...');
19
+
20
+ const { exec } = require('child_process');
21
+
22
+ exec('npm install', { cwd: `${this.directory}/html` }, (error, stdout, stderr) => {
23
+ if (error) {
24
+ signale.error(`Erro ao instalar dependências: ${error.message}`);
25
+ return;
26
+ }
27
+
28
+ if (stderr) {
29
+ signale.error(`Erro: ${stderr}`);
30
+ return;
31
+ }
32
+
33
+ signale.success('Dependências instaladas com sucesso!');
34
+ });
35
+ }
36
+
37
+ copyTemplate(src, dest) {
38
+ if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
39
+ else {
40
+ const signale = new Signale();
41
+ signale.error('Script already exists!');
42
+ return;
43
+ }
44
+
45
+ fs.readdirSync(src).forEach(file => {
46
+ const srcPath = path.join(src, file);
47
+ const destPath = path.join(dest, file);
48
+
49
+ if (fs.lstatSync(srcPath).isDirectory()) {
50
+ this.copyTemplate(srcPath, destPath);
51
+ } else {
52
+ let content = fs.readFileSync(srcPath, 'utf8');
53
+ content = content.replace(/%workspaceName%/g, this.name);
54
+ fs.writeFileSync(destPath, content);
55
+ }
56
+ });
57
+ }
58
+ }
59
+
60
+ module.exports = Script;
package/bin/rollup.js ADDED
@@ -0,0 +1,67 @@
1
+ const { rollup } = require('rollup');
2
+ const terser = require('@rollup/plugin-terser');
3
+ const { join } = require('path');
4
+ const UglifyJS = require('uglify-js');
5
+
6
+ class Script {
7
+ constructor(name, production = false) {
8
+ this.name = name;
9
+ this.directory = process.cwd();
10
+ this.exec();
11
+ }
12
+
13
+
14
+ async exec() {
15
+ try {
16
+ const clipboardy = await import('clipboardy');
17
+
18
+ const script = await this.getScript();
19
+ clipboardy.default.writeSync(script);
20
+ console.log('O código foi copiado para a área de transferência!');
21
+ } catch (err) {
22
+ console.error('Erro:', err);
23
+ }
24
+ }
25
+
26
+ async getScript() {
27
+ const file = join(this.directory + `/${this.name}`, 'room.js');
28
+ const input = await rollup({ input: file });
29
+ const config = this.getOutputConfig();
30
+ const output = await input.generate(config);
31
+ const script = output?.output[0];
32
+
33
+ if (!script) {
34
+ const err = new Error('Failed to generate script!');
35
+ throw err;
36
+ }
37
+
38
+ const minified = UglifyJS.minify(script.code).code;
39
+
40
+ if (minified.error) {
41
+ const err = new Error('Error during minification: \n' + minified.error);
42
+ throw err;
43
+ }
44
+
45
+ return minified;
46
+ }
47
+
48
+ getOutputConfig() {
49
+ const config = {
50
+ format: 'cjs',
51
+ file: `room-${new Date().getTime()}.js`
52
+ }
53
+
54
+ if (this.production) {
55
+ const options = {
56
+ toplevel: false,
57
+ mangle: false,
58
+ compress: false
59
+ }
60
+ config.plugins = [terser(options)]
61
+ }
62
+
63
+ return config;
64
+ }
65
+ }
66
+
67
+ module.exports = Script;
@@ -0,0 +1,72 @@
1
+ const { rollup } = require('rollup');
2
+ const terser = require('@rollup/plugin-terser');
3
+ const { existsSync } = require('fs');
4
+ const { join } = require('path');
5
+ const typescript = require("@rollup/plugin-typescript");
6
+
7
+ class Script {
8
+ constructor(name) {
9
+ this.name = name;
10
+ this.directory = process.cwd();
11
+ this.exec();
12
+ }
13
+
14
+ async exec() {
15
+ try {
16
+ const clipboardy = await import('clipboardy');
17
+
18
+ const script = await this.getScript();
19
+ clipboardy.default.writeSync(script);
20
+ console.log('O código foi copiado para a área de transferência!');
21
+ } catch (err) {
22
+ console.error('Erro:', err);
23
+ }
24
+ }
25
+
26
+ async getScript() {
27
+ let file = join(this.directory + `/${this.name}`, 'room.ts');
28
+ let tsconfigPath = join(this.directory + `/${this.name}`, 'tsconfig.json');
29
+
30
+ if (!existsSync(file)) {
31
+ file = join(this.directory + `/${this.name}`, '/room', 'room.ts');
32
+ tsconfigPath = join(this.directory + `/${this.name}`, '/room', 'tsconfig.json');
33
+ }
34
+
35
+ if (!existsSync(file)) {
36
+ const err = new Error('Missing room.ts!');
37
+ throw err;
38
+ }
39
+
40
+ if (!existsSync(tsconfigPath)) {
41
+ const err = new Error('Missing tsconfig.json!');
42
+ throw err;
43
+ }
44
+
45
+ const bundle = await rollup({
46
+ input: file,
47
+ plugins: [
48
+ typescript({ tsconfig: tsconfigPath }),
49
+ terser(),
50
+ ],
51
+ }).catch(err => {
52
+ throw `Bundle failed: ${err}`;
53
+ });
54
+
55
+ const { output } = await bundle.generate({ format: "cjs" });
56
+ const script = output[0];
57
+
58
+ if (!script) {
59
+ throw new Error('Failed to generate script!');
60
+ }
61
+
62
+ script.code = script.code
63
+ .replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '')
64
+ .replace(/(\r\n|\n|\r)/gm, '')
65
+ .replace(/(\s\s\s+)/gm, '')
66
+ .replace(/(\s\s+)/gm, '');
67
+
68
+ return script.code;
69
+ }
70
+ }
71
+
72
+ module.exports = Script;
package/bin/script.js ADDED
@@ -0,0 +1,131 @@
1
+ const { rollup } = require('rollup');
2
+ const terser = require('@rollup/plugin-terser');
3
+ const typescript = require('@rollup/plugin-typescript');
4
+ const { existsSync, readFileSync } = require('fs');
5
+ const { join } = require('path');
6
+ const { Signale } = require('signale');
7
+ const axios = require('axios');
8
+ const commonjs = require('@rollup/plugin-commonjs');
9
+ const resolve = require('@rollup/plugin-node-resolve');
10
+
11
+ class Script {
12
+ constructor(name, production = false) {
13
+ this.name = name;
14
+ this.production = production;
15
+ this.url = 'https://hubbe.biz';
16
+ this.directory = process.cwd();
17
+ this.config = this.getFile(this.directory + `/${name}`, 'config.json');
18
+ this.token = this.getFile(__dirname, '.token', true);
19
+ this.exec();
20
+ }
21
+
22
+ exec() {
23
+ const signale = new Signale();
24
+ this.getScript()
25
+ .then(this.deploy.bind(this))
26
+ .then(() => signale.success('Script Deployed!'))
27
+ .catch(err => signale.error(`Deploy Failed! ${err}`));
28
+ }
29
+
30
+ deploy(script) {
31
+ const roomid = this.config.roomid;
32
+ const url = `${this.url}/scriptApi?roomid=${roomid}`;
33
+
34
+ const options = {
35
+ method: 'POST',
36
+ headers: { 'token': this.token },
37
+ data: { code: script },
38
+ url,
39
+ }
40
+
41
+ return axios(options);
42
+ }
43
+
44
+ async getScript() {
45
+ const file = join(this.directory + `/${this.name}`, 'room.ts');
46
+ const tsconfigPath = join(this.directory + `/${this.name}`, 'tsconfig.json');
47
+
48
+ if (!existsSync(tsconfigPath)) {
49
+ const err = new Error('Missing tsconfig.json!');
50
+ throw err;
51
+ }
52
+
53
+ // const input = await rollup({ input: file });
54
+ // const config = this.getOutputConfig();
55
+ // const output = await input.generate(config);
56
+ // const script = output?.output[0];
57
+
58
+ const bundle = await rollup({
59
+ input: file,
60
+ plugins: [
61
+ // resolve(), // Para resolver módulos node
62
+ // commonjs(), // Para converter módulos CommonJS para ES6
63
+ typescript({
64
+ tsconfig: tsconfigPath,
65
+ }),
66
+ terser(),
67
+ ],
68
+ }).catch(err => {
69
+ throw `Bundle failed: ${err}`;
70
+ });
71
+
72
+ const { output } = await bundle.generate({
73
+ format: "cjs"
74
+ });
75
+
76
+ const script = output[0];
77
+
78
+ if (!script) {
79
+ const err = new Error('Failed to generate script!');
80
+ throw err;
81
+ }
82
+
83
+ script.code = script.code
84
+ .replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '')
85
+ .replace(/(\r\n|\n|\r)/gm, '')
86
+ .replace(/(\s\s\s+)/gm, '')
87
+ .replace(/(\s\s+)/gm, '');// Remove comments, line breaks and multiple spaces
88
+
89
+ return script.code;
90
+ }
91
+
92
+ getOutputConfig() {
93
+ const config = {
94
+ format: 'cjs',
95
+ file: `room-${this.config.roomid}.js`
96
+ }
97
+
98
+ if (this.production) {
99
+ const options = {
100
+ toplevel: false,
101
+ mangle: false,
102
+ compress: false
103
+ }
104
+ config.plugins = [
105
+ typescript({
106
+ tsconfig: join(this.directory + `/${this.name}`, 'tsconfig.json')
107
+ }),
108
+ terser(options)
109
+ ]
110
+ }
111
+
112
+ return config;
113
+ }
114
+
115
+ getFile(directory, file, read) {
116
+ const dir = join(directory, file);
117
+
118
+ if (!existsSync(dir)) {
119
+ const err = new Error(`Missing ${file}!`);
120
+ throw err;
121
+ }
122
+
123
+ if (!read) {
124
+ return require(dir);
125
+ }
126
+
127
+ return readFileSync(dir, 'utf-8');
128
+ }
129
+ }
130
+
131
+ module.exports = Script;
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2019",
4
+ "module": "ESNext",
5
+ "esModuleInterop": true,
6
+ "forceConsistentCasingInFileNames": true,
7
+ "strict": true
8
+ }
9
+ }
package/bin/utils.js ADDED
@@ -0,0 +1,35 @@
1
+ const {writeFileSync, mkdirSync, existsSync, readFileSync} = require('fs');
2
+ const {join} = require('path');
3
+ const {Signale} = require('signale');
4
+ const React = require('./react');
5
+
6
+ const setToken = token => {
7
+ writeFileSync(__dirname + '/.token', token);
8
+ const signale = new Signale();
9
+ signale.success('Token setted!');
10
+ };
11
+
12
+ const newScript = name => {
13
+ const directory = process.cwd();
14
+ const resolved = join(directory, name);
15
+
16
+ if (!existsSync(resolved)) {
17
+ mkdirSync(resolved);
18
+ }
19
+ else {
20
+ const signale = new Signale();
21
+ signale.error('Script already exists!');
22
+ return;
23
+ }
24
+
25
+ React(name);
26
+
27
+ writeFileSync(join(resolved, 'room.ts'), '');
28
+ writeFileSync(join(resolved, 'tsconfig.json'), JSON.stringify(require("./tsconfig_template.json"), null, 4));
29
+ writeFileSync(join(resolved, 'config.json'), `{ "roomid": 0 }`);
30
+
31
+ const signale = new Signale();
32
+ signale.success('New script created!');
33
+ };
34
+
35
+ module.exports = {setToken, newScript};
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "hubbe-sdk",
3
+ "version": "1.2.0",
4
+ "description": "SDK for deploying Hubbe-Script",
5
+ "author": "Divine",
6
+ "license": "GPL-3.0",
7
+ "main": "bin/index.js",
8
+ "scripts": {
9
+ "docs:generate": "typedoc",
10
+ "docs:dev": "npm run docs:generate && vitepress dev",
11
+ "docs:build": "npm run docs:generate && vitepress build",
12
+ "docs:preview": "vitepress preview"
13
+ },
14
+ "bin": {
15
+ "hubbe": "./bin/index.js"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/Iron-Org/iron-script-sdk.git"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/Iron-Org/iron-script-sdk/issues"
23
+ },
24
+ "homepage": "https://github.com/Iron-Org/iron-script-sdk#readme",
25
+ "dependencies": {
26
+ "@mdx-js/loader": "^3.1.1",
27
+ "@mdx-js/react": "^3.1.1",
28
+ "@next/mdx": "^16.1.1",
29
+ "archiver": "^6.0.1",
30
+ "axios": "^1.7.2",
31
+ "cheerio": "1.0.0-rc.12",
32
+ "clipboardy": "^4.0.0",
33
+ "commander": "^11.1.0",
34
+ "docusaurus-plugin-typedoc": "^1.4.2",
35
+ "dotenv": "^16.3.1",
36
+ "fs": "^0.0.1-security",
37
+ "glob": "^11.0.0",
38
+ "path": "^0.12.7",
39
+ "signale": "^1.4.0",
40
+ "ssh2-sftp-client": "^9.1.0",
41
+ "uglify-js": "^3.17.4",
42
+ "use-between": "^1.3.5"
43
+ },
44
+ "devDependencies": {
45
+ "@rollup/plugin-commonjs": "^26.0.1",
46
+ "@rollup/plugin-node-resolve": "^15.2.3",
47
+ "@rollup/plugin-terser": "^0.4.4",
48
+ "@rollup/plugin-typescript": "^11.1.6",
49
+ "@types/node": "^22.15.17",
50
+ "rollup": "^4.18.0",
51
+ "tslib": "^2.6.3",
52
+ "typedoc": "^0.28.15",
53
+ "typedoc-plugin-markdown": "^4.9.0",
54
+ "typescript": "^5.4.5",
55
+ "vitepress": "^1.6.4"
56
+ }
57
+ }