Skip to content

Commit

Permalink
feat(docs): add copy demo
Browse files Browse the repository at this point in the history
  • Loading branch information
dogodo-cc committed Apr 16, 2024
1 parent 7fc1077 commit 8704d96
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 1 deletion.
52 changes: 52 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions packages-demos/others/copy/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pkg from 'fs-extra';
const { ensureDirSync, copySync, readdirSync, lstatSync, chmodSync, existsSync } = pkg;
import { join } from 'node:path';
import { spawn } from 'child_process';

export function copy(source, target) {
/**
* asar 里不能复制文件夹,需要用 mkdir 创建
*/
function step(src, dist) {
if (!existsSync(src)) {
return;
}
const fileStat = lstatSync(src);

if (fileStat.isDirectory()) {
ensureDirSync(dist);
if (!fileStat.isSymbolicLink()) chmodSync(dist, 511);
const list = readdirSync(src);
for (const name of list) {
step(join(src, name), join(dist, name));
}
} else {
copySync(src, dist);
if (!fileStat.isSymbolicLink()) chmodSync(dist, 511);
}
}

step(source, target);
}

// 创建一个软连接的文件夹 & 复制包含软连接的文件
const child = spawn('ln', ['-s', '/Users/alan/cocos/fe-team/packages-demos/cocos-plugin-vue2', '/Users/alan/cocos/fe-team/packages-demos/others/copy/test']);
child.addListener('close', (code, signal) => {
if (code === 0) {
copy('/Users/alan/cocos/fe-team/packages-demos/others/copy/test', '/Users/alan/cocos/fe-team/packages-demos/others/copy/test-copy');
} else {
console.log(code, signal);
}
});
1 change: 1 addition & 0 deletions packages-demos/others/copy/test-copy/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
123
1 change: 1 addition & 0 deletions packages-demos/others/copy/test-copy/cocos-plugin-vue2
1 change: 1 addition & 0 deletions packages-demos/others/copy/test/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
123
44 changes: 44 additions & 0 deletions packages-demos/others/nodemailer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import nodemailer from 'nodemailer';

// 创建一个 transporter 实例,配置 SMTP 服务提供商的凭据
const transporter = nodemailer.createTransport({
host: 'smtp.qq.com', // 替换为实际 SMTP 服务器主机名
port: 587, // 或其他适用端口,如 465(SSL)、25(非加密)
secure: false, // 使用 SSL/TLS 连接,如果是非标准端口,通常应设为 true
auth: {
user: '741484865@qq.com', // 替换为您的邮箱用户名或邮箱地址
pass: 'lfqvfktuspembbbc', // 替换为您的邮箱密码或应用生成的授权码
},
// 其他可选配置,如 TLS 特定选项、代理设置等
});

// 定义邮件内容
const mailOptions = {
from: '"袁炜海" <741484865@qq.com>', // 发件人姓名和地址
to: 'yuanweihai25@163.com', // 收件人地址,可以是单个或数组 ['user1@example.com', 'user2@example.com']
subject: '邮件主题', // 邮件主题
text: 'This is a plain-text email body.', // 纯文本邮件正文
// html: '<p>This is an <strong>HTML</strong> email body.</p>', // HTML 格式的邮件正文(可选)

// 附件(可选)
// attachments: [
// {
// filename: 'example.txt',
// path: './path/to/example.txt',
// },
// {
// filename: 'image.png',
// path: './path/to/image.png',
// cid: 'unique-image-id', // Content-Id for inline embedding
// },
// ],
};

// 发送邮件
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.error('Failed to send email:', error);
} else {
console.log('Email sent successfully. Response:', info);
}
});
16 changes: 16 additions & 0 deletions packages-demos/others/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "others",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"fs-extra": "^11.2.0",
"nodemailer": "^6.9.13"
}
}
2 changes: 1 addition & 1 deletion projects/document/docs/docs/symbolic-link/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/Users/alan/.CocosCreator/extensions/your-plugin
```

这样不方便维护,你需要不断的复制同步代码。通过软链,你可以把 `your-plugin` 放置在你平时的开发文件夹。然后通过配置软链接让两个环境下的 extensions 文件夹都有 `your-plugin` 的引用。
这样不方便维护,你需要不断的复制同步代码。通过软链,你可以把 `your-plugin` 放置在你平时的开发文件夹。然后通过配置软链接让两个环境下的 extensions 文件夹都有 `your-plugin` 的引用。 **需要使用绝对路径**

```bash
ln -s /Users/alan/cocos/auto-register /Users/alan/.CocosCreator_Develop/extensions/auto-register
Expand Down

0 comments on commit 8704d96

Please sign in to comment.