create-alemonjs 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ # 工程模板
2
+
3
+ https://github.com/lemonade-lab/alemonjs
4
+
5
+ ```sh
6
+ npm create alemonjs@latest -y
7
+ ```
package/bin/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/bin/index.js ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync, cpSync, writeFileSync } from 'fs';
3
+ import { dirname, resolve, join } from 'path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import GitBody from './str-git.js';
6
+ import NpmPublish from './str-npm.js';
7
+ import NpmrcBody from './str-npmr.js';
8
+ import { readFileSync } from 'node:fs';
9
+
10
+ const currentFilePath = fileURLToPath(import.meta.url);
11
+ const currentDirPath = dirname(currentFilePath);
12
+ const alemonjsCliPath = resolve(currentDirPath);
13
+ function createTemplate(name) {
14
+ const dirPath = `./${name}`;
15
+ if (existsSync(dirPath)) {
16
+ console.error('Robot name already exists!');
17
+ return;
18
+ }
19
+ console.info('\n');
20
+ try {
21
+ const data = join(alemonjsCliPath, '../', 'package.json');
22
+ const pkg = readFileSync(data, 'utf-8');
23
+ const version = JSON.parse(pkg).version;
24
+ const templatePath = join(alemonjsCliPath, '../', 'template', name);
25
+ console.info(`[V${version}] Copying template...`);
26
+ cpSync(templatePath, dirPath, { recursive: true });
27
+ writeFileSync(join(dirPath, '.npmrc'), NpmrcBody);
28
+ writeFileSync(join(dirPath, '.gitignore'), GitBody);
29
+ writeFileSync(join(dirPath, '.npmignore'), NpmPublish);
30
+ process.chdir(dirPath);
31
+ console.info('------------------------------------');
32
+ console.info(`cd ${name}`);
33
+ console.info('npm i yarn -g && yarn');
34
+ console.info('------------------------------------');
35
+ }
36
+ catch (error) {
37
+ console.info(`${name} ${error}`);
38
+ }
39
+ }
40
+ void createTemplate('alemonjs');
@@ -0,0 +1,2 @@
1
+ declare const _default: "node_modules\n/data\n/public\n/logs\n/lib\n/log\n*.logs\n*.log\nyarn.lock\n.cache\n";
2
+ export default _default;
package/bin/str-git.js ADDED
@@ -0,0 +1,13 @@
1
+ var GitBody = `node_modules
2
+ /data
3
+ /public
4
+ /logs
5
+ /lib
6
+ /log
7
+ *.logs
8
+ *.log
9
+ yarn.lock
10
+ .cache
11
+ `;
12
+
13
+ export { GitBody as default };
@@ -0,0 +1,2 @@
1
+ declare const _default: "# \u5FFD\u7565\u6240\u6709\n/* \n# \u4E0D\u5FFD\u7565\n!/assets\n!/lib\n!/public\n";
2
+ export default _default;
package/bin/str-npm.js ADDED
@@ -0,0 +1,9 @@
1
+ var NpmPublish = `# 忽略所有
2
+ /*
3
+ # 不忽略
4
+ !/assets
5
+ !/lib
6
+ !/public
7
+ `;
8
+
9
+ export { NpmPublish as default };
@@ -0,0 +1,2 @@
1
+ declare const _default: "# \u4E3A\u9879\u76EE\u5355\u72EC\u8BBE\u7F6E\u955C\u50CF\nregistry=https://registry.npmmirror.com\n# canvas\ncanvas_binary_host_mirror=https://ghproxy.com/https://github.com/Automattic/node-canvas/releases/download/\n# node-sass\nsass_binary_site=https://npmmirror.com/mirrors/node-sass/\n# sqlite3\nnode_sqlite3_binary_host_mirror=https://npmmirror.com/mirrors/sqlite3\n# TFJS\nTFJS_NODE_CDN_STORAGE=https://cdn.npmmirror.com/binaries/\n# pup\nPUPPETER_DOWNLOAD_BASE_URL=https://npmmirror.com/mirrors/chrome-for-testing\n# \u4E0D\u751F\u6210lock\npackage-lock=false\n# \u6539\u4E3A npm \u4F9D\u8D56\u5B89\u88C5\u65B9\u5F0F\nnode-linker=hoisted\n# \u53EF\u803B\u7684\u63D0\u5347\nshamefully-hoist=true\n# \u4E25\u683C\u7684\u5BF9\u7B49\u4F9D\u8D56\u5173\u7CFB\nstrict-peer-dependencies=false";
2
+ export default _default;
@@ -0,0 +1,22 @@
1
+ var NpmrcBody = `# 为项目单独设置镜像
2
+ registry=https://registry.npmmirror.com
3
+ # canvas
4
+ canvas_binary_host_mirror=https://ghproxy.com/https://github.com/Automattic/node-canvas/releases/download/
5
+ # node-sass
6
+ sass_binary_site=https://npmmirror.com/mirrors/node-sass/
7
+ # sqlite3
8
+ node_sqlite3_binary_host_mirror=https://npmmirror.com/mirrors/sqlite3
9
+ # TFJS
10
+ TFJS_NODE_CDN_STORAGE=https://cdn.npmmirror.com/binaries/
11
+ # pup
12
+ PUPPETER_DOWNLOAD_BASE_URL=https://npmmirror.com/mirrors/chrome-for-testing
13
+ # 不生成lock
14
+ package-lock=false
15
+ # 改为 npm 依赖安装方式
16
+ node-linker=hoisted
17
+ # 可耻的提升
18
+ shamefully-hoist=true
19
+ # 严格的对等依赖关系
20
+ strict-peer-dependencies=false`;
21
+
22
+ export { NpmrcBody as default };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "create-alemonjs",
3
+ "version": "0.0.1",
4
+ "description": "alemonjs dev template",
5
+ "author": "ningmengchongshui",
6
+ "main": "bin/index.js",
7
+ "type": "module",
8
+ "scripts": {
9
+ "build": "npx lvyjs build"
10
+ },
11
+ "dependencies": {
12
+ "enquirer": "^2.4.1"
13
+ },
14
+ "devDependencies": {
15
+ "@types/node": "^18"
16
+ },
17
+ "bin": {
18
+ "create-alemonjs": "bin/index.js"
19
+ },
20
+ "keywords": [
21
+ "alemonjs"
22
+ ],
23
+ "publishConfig": {
24
+ "registry": "https://registry.npmjs.org",
25
+ "access": "public"
26
+ },
27
+ "bugs": "https://github.com/lemonade-lab/alemonjs/issues",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/lemonade-lab/alemonjs.git"
31
+ }
32
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @type {import("puppeteer").Configuration}
3
+ */
4
+ module.exports = require('jsxp/.puppeteerrc');
@@ -0,0 +1,22 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "name": "dev",
6
+ "type": "node",
7
+ "request": "launch",
8
+ "runtimeArgs": ["dev"],
9
+ "runtimeExecutable": "yarn",
10
+ "skipFiles": ["<node_internals>/**"]
11
+ },
12
+ {
13
+ "name": "view",
14
+ "type": "node",
15
+ "request": "launch",
16
+ "runtimeArgs": ["dev", "--view"],
17
+ "runtimeExecutable": "yarn",
18
+ "skipFiles": ["<node_internals>/**"],
19
+ "preLaunchTask": "open-browser"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "label": "open-browser",
6
+ "type": "shell",
7
+ "command": "open http://localhost:8080",
8
+ "presentation": {
9
+ "reveal": "never"
10
+ }
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,7 @@
1
+ # 具体见 pm2.config.cjs
2
+ pm2:
3
+ apps:
4
+ - name: 'gui'
5
+ script: 'node index.js --login gui'
6
+ env:
7
+ NODE_ENV: 'production'
@@ -0,0 +1,2 @@
1
+ import { start } from 'alemonjs';
2
+ start();
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { defineConfig } from 'jsxp';
3
+ import Word from '@src/image/component/help';
4
+ export default defineConfig({
5
+ routes: {
6
+ '/': {
7
+ component: <Word data={'AlemonJS 跨平台开发框架'} />
8
+ }
9
+ }
10
+ });
@@ -0,0 +1,18 @@
1
+ import { defineConfig } from 'lvyjs';
2
+ import { fileURLToPath } from 'url';
3
+ import { dirname, join } from 'path';
4
+ const __dirname = dirname(fileURLToPath(import.meta.url));
5
+ const includes = (value: string) => process.argv.includes(value);
6
+ const alemonjs = () => import('alemonjs').then(res => res.start('src/index.ts'));
7
+ const jsxp = () => import('jsxp').then(res => res.createServer());
8
+ export default defineConfig({
9
+ plugins: [
10
+ () => {
11
+ if (includes('--view')) return jsxp;
12
+ return alemonjs;
13
+ }
14
+ ],
15
+ alias: {
16
+ entries: [{ find: '@src', replacement: join(__dirname, 'src') }]
17
+ }
18
+ });
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "alemonjs-app",
3
+ "version": "1.0.0",
4
+ "description": "template app",
5
+ "main": "lib/index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "dev": "npx lvy dev",
9
+ "build": "npx lvy build",
10
+ "review": "npx alemonc start",
11
+ "start": "npx pm2 startOrRestart pm2.config.cjs",
12
+ "stop": "npx pm2 stop pm2.config.cjs",
13
+ "delete": "npx pm2 delete pm2.config.cjs"
14
+ },
15
+ "exports": {
16
+ ".": "./lib/index.js",
17
+ "./package": "./package.json"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^22",
21
+ "@alemonjs/db": "^0.0.13",
22
+ "alemonjs": "2.1.14",
23
+ "jsxp": "1.2.4",
24
+ "tailwindcss": "3",
25
+ "cssnano": "^7",
26
+ "lvyjs": "^0.2.25",
27
+ "pm2": "^5"
28
+ },
29
+ "publishConfig": {
30
+ "registry": "https://registry.npmjs.org",
31
+ "access": "public"
32
+ }
33
+ }
@@ -0,0 +1,14 @@
1
+ const fs = require('fs');
2
+ const yaml = require('yaml');
3
+
4
+ // Read and parse the YAML configuration file
5
+ const data = fs.readFileSync('./alemon.config.yaml', 'utf8');
6
+ const config = yaml.parse(data);
7
+
8
+ // Extracting PM2 configuration
9
+ const pm2 = config?.pm2 ?? {};
10
+
11
+ /**
12
+ * @type {{ apps: import("pm2").StartOptions[] }}
13
+ */
14
+ module.exports = pm2;
@@ -0,0 +1,10 @@
1
+ export default {
2
+ plugins: {
3
+ // tailwindcss
4
+ tailwindcss: {},
5
+ // 压缩css
6
+ cssnano: {
7
+ preset: 'default'
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,8 @@
1
+ @import url('@src/assets/root.css');
2
+ @tailwind base;
3
+ @tailwind components;
4
+ @tailwind utilities;
5
+
6
+ body {
7
+ @apply m-0 p-0 flex flex-col;
8
+ }
@@ -0,0 +1,15 @@
1
+ :root {
2
+ --bg-color: rgb(60 58 58 / 79%);
3
+ }
4
+
5
+ #root[data-theme='blue'] {
6
+ --bg-color: rgba(215, 218, 225, 0.73);
7
+ }
8
+
9
+ #root[data-theme='purple'] {
10
+ --bg-color: rgb(164 178 205 / 92%);
11
+ }
12
+
13
+ #root[data-theme='red'] {
14
+ --bg-color: rgba(238, 140, 140, 0.79);
15
+ }
@@ -0,0 +1,2 @@
1
+ /// <reference types="lvyjs/env" />
2
+ /// <reference types="alemonjs/env" />
@@ -0,0 +1,13 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import css_output from '@src/assets/main.css';
3
+ import { LinkStyleSheet } from 'jsxp';
4
+ export default function Html({ children }: PropsWithChildren) {
5
+ return (
6
+ <html>
7
+ <head>
8
+ <LinkStyleSheet src={css_output} />
9
+ </head>
10
+ <body>{children}</body>
11
+ </html>
12
+ );
13
+ }
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { BackgroundImage } from 'jsxp';
3
+ import img_logo from '@src/assets/alemonjs.png';
4
+ import Html from './Html';
5
+ type Props = {
6
+ data: string;
7
+ theme?: string;
8
+ };
9
+ /**
10
+ * @param param0
11
+ * @returns
12
+ */
13
+ export default function App({ data, theme }: Props) {
14
+ return (
15
+ <Html>
16
+ <section id='root' data-theme={theme} className='flex flex-col'>
17
+ <BackgroundImage className='min-h-[31rem] w-full h-full flex items-end justify-center' url={img_logo} size={'100% auto'}>
18
+ <div className='text-blue-400 text-5xl'>{data}</div>
19
+ </BackgroundImage>
20
+ </section>
21
+ </Html>
22
+ );
23
+ }
@@ -0,0 +1,31 @@
1
+ import { defineChildren, defineResponse, logger, lazy } from 'alemonjs';
2
+
3
+ // 设置路由规则
4
+ const response = defineResponse([
5
+ {
6
+ handler: lazy(() => import('./response/mw')),
7
+ children: [
8
+ {
9
+ regular: /hello/,
10
+ handler: lazy(() => import('./response/hello/res')),
11
+ },
12
+ {
13
+ regular: /help/,
14
+ handler: lazy(() => import('./response/help/res')),
15
+ }
16
+ ]
17
+ }
18
+ ]);
19
+
20
+ export default defineChildren({
21
+ // 注册内容
22
+ register() {
23
+ return {
24
+ response
25
+ }
26
+ },
27
+ // 当注册完成时
28
+ onCreated() {
29
+ logger.info('本地测试启动');
30
+ }
31
+ });
@@ -0,0 +1,8 @@
1
+ import { Text, useMessage } from 'alemonjs';
2
+ export const selects = onSelects(['message.create']);
3
+ export default onResponse(selects, event => {
4
+ // 创建
5
+ const [message] = useMessage(event);
6
+ // 发送消息
7
+ message.send(format(Text('hello Word')));
8
+ });
@@ -0,0 +1,20 @@
1
+ import { renderComponentToBuffer } from 'jsxp';
2
+ import { Text, Image, useMessage } from 'alemonjs';
3
+
4
+ import Help from '@src/image/component/help';
5
+
6
+ export const selects = onSelects(['message.create']);
7
+
8
+ export default onResponse(selects, async event => {
9
+ const [message] = useMessage(event);
10
+ // pic
11
+ const img = await renderComponentToBuffer('/help', Help, {
12
+ data: 'AlemonJS 跨平台开发框架'
13
+ });
14
+ // send
15
+ if (typeof img != 'boolean') {
16
+ message.send(format(Image(img)));
17
+ } else {
18
+ message.send(format(Text('图片加载失败')));
19
+ }
20
+ });
@@ -0,0 +1,6 @@
1
+ export const selects = onSelects(['message.create']);
2
+
3
+ export default onResponse(selects, (event) => {
4
+ logger.warn("RES中间件", event)
5
+ return true;
6
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @type {import('tailwindcss').Config}
3
+ */
4
+ export default {
5
+ content: ['./src/**/*.{jsx,tsx}']
6
+ };
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "paths": {
4
+ "@src/*": ["./src/*"]
5
+ }
6
+ },
7
+ "include": ["src/**/*", "jsxp.config.tsx"],
8
+ "extends": "lvyjs/tsconfig.json"
9
+ }