Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Commit f2c2105

Browse files
committed
first commit
0 parents  commit f2c2105

48 files changed

Lines changed: 2384 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto eol=lf
2+
*.txt eol=lf

.github/workflows/main.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
on:
2+
- push
3+
- pull_request
4+
5+
jobs:
6+
cache-and-install:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
13+
- name: Install Node.js
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: latest
17+
cache: npm
18+
19+
- name: Install dependencies
20+
run: npm i
21+
22+
- name: Build
23+
run: npm run build

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/create.js
2+
/node_modules/
3+
/clipcc-extension-*

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"ms-vscode.vscode-typescript-next"
4+
]
5+
}

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"files.eol": "\n"
3+
}

LICENSE.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright © 2025 bddjr & Clip Team
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```
2+
npm create makeccx@latest
3+
```
4+
5+
More info:
6+
https://github.com/makeccx/makeccx

create.ts

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import inquirer from "inquirer"
2+
import fs from "node:fs"
3+
import path from "node:path"
4+
import { fileURLToPath } from "node:url"
5+
6+
7+
const idIgnorePrefix = [
8+
'com',
9+
'net',
10+
'java',
11+
'org',
12+
'top',
13+
'cn',
14+
'io',
15+
'co',
16+
'cc',
17+
'site',
18+
'git',
19+
'github',
20+
'gitee',
21+
'gitea',
22+
'gitlab',
23+
]
24+
25+
26+
let useJS = false
27+
let id = ''
28+
let extensionDir = ''
29+
let author = ''
30+
let extensionName = ''
31+
32+
function leftPath(left: string) {
33+
return fileURLToPath(import.meta.resolve('./template/' + left))
34+
}
35+
36+
function rightPath(right: string) {
37+
return path.join(extensionDir, right)
38+
}
39+
40+
function cp(left: string, right?: string) {
41+
fs.cpSync(
42+
leftPath(left),
43+
rightPath(right || left),
44+
{ recursive: true }
45+
)
46+
}
47+
48+
function checkInputID(id: string): true | string {
49+
// 1. `your.extension.id` must be an valid id,
50+
// which only contains a-z, 0-9 and `_`, and is split by `.`.
51+
// To avoid id conflict, a recommended id is `name.extension`,
52+
// containing both your extension name and your own name
53+
// (or your team/organization's name) with lower letters
54+
// (numbers and `_` shouldn't be used if not necessary),
55+
// like `alexcui.random`, `clipteam.community`, etc.
56+
// https://www.npmjs.com/package/clipcc-extension-cli
57+
let re = /^([a-z0-9_]+\.)+[a-z0-9_]+$/
58+
if (!re.test(id))
59+
return 'ID must match ' + re
60+
61+
// 如果我 id 以 com 开头该怎么办
62+
// —— Simon Shiki
63+
if (idIgnorePrefix.includes(id.split('.', 2)[0]))
64+
return 'ID prefix must not in ' + JSON.stringify(idIgnorePrefix)
65+
66+
return true
67+
}
68+
69+
try {
70+
{
71+
const answerLang = await inquirer.prompt([{
72+
type: 'list',
73+
name: 'lang',
74+
message: 'Choose your development language:',
75+
choices: ['TypeScript', 'JavaScript']
76+
}
77+
])
78+
useJS = answerLang.lang == 'JavaScript'
79+
} {
80+
const answerID = await inquirer.prompt([{
81+
type: 'input',
82+
name: 'id',
83+
message: 'Extension ID:',
84+
validate: (id) => checkInputID(id)
85+
}])
86+
id = answerID.id;
87+
[author, extensionName] = id.split('.', 2)
88+
extensionDir = 'clipcc-extension-' + extensionName
89+
} {
90+
const answerDir = await inquirer.prompt([{
91+
type: 'input',
92+
name: 'dir',
93+
message: 'Directory Name:',
94+
default: extensionDir,
95+
validate: (v) => (!fs.existsSync(v) || 'Directory exists!')
96+
}])
97+
if (answerDir.dir) {
98+
extensionDir = answerDir.dir
99+
}
100+
} {
101+
const answerAuthor = await inquirer.prompt([{
102+
type: 'input',
103+
name: 'author',
104+
message: 'Author:',
105+
default: author
106+
}])
107+
if (answerAuthor.author) {
108+
author = answerAuthor.author
109+
}
110+
} {
111+
const answerExtensionName = await inquirer.prompt([{
112+
type: 'input',
113+
name: 'extensionName',
114+
message: 'Extension Name:',
115+
default: extensionName
116+
}])
117+
if (answerExtensionName.extensionName) {
118+
extensionName = answerExtensionName.extensionName
119+
}
120+
}
121+
} catch (e) {
122+
if (e == 'ExitPromptError: User force closed the prompt with SIGINT') {
123+
console.error('^C')
124+
process.exit(1)
125+
}
126+
throw e
127+
}
128+
129+
130+
if (extensionDir == '') {
131+
console.error('Reject.')
132+
process.exit(1)
133+
}
134+
135+
fs.mkdirSync(extensionDir)
136+
137+
cp('.github')
138+
cp('.vscode')
139+
cp('.gitattributes')
140+
cp('.gitignore')
141+
cp('src-public/assets', 'src/assets')
142+
143+
if (useJS) {
144+
cp('src-js', 'src')
145+
cp('makeccx.config.js')
146+
cp('package-js.json', 'package.json')
147+
} else {
148+
cp('src-ts', 'src')
149+
cp('makeccx.config.js', 'makeccx.config.ts')
150+
cp('package-ts.json', 'package.json')
151+
cp('tsconfig.json')
152+
cp('tsconfig.makeccx.json')
153+
cp('tsconfig.src.json')
154+
}
155+
156+
{
157+
const lp = leftPath('src-public/info.json')
158+
const info = JSON.parse(fs.readFileSync(lp).toString())
159+
info.id = id
160+
info.author = author
161+
162+
const rp = rightPath('src/info.json')
163+
fs.writeFileSync(rp, JSON.stringify(info, null, " "))
164+
}
165+
166+
fs.mkdirSync(rightPath(`src/locales`))
167+
168+
for (const name of fs.readdirSync(leftPath(`src-public/locales`))) {
169+
const lp = leftPath(`src-public/locales/${name}`)
170+
const json = JSON.parse(fs.readFileSync(lp).toString())
171+
json.name = extensionName
172+
173+
const rp = rightPath(`src/locales/${name}`)
174+
fs.writeFileSync(rp, JSON.stringify(json, null, " "))
175+
}
176+
177+
178+
console.log(`
179+
cd ${extensionDir}
180+
npm i
181+
npm run build
182+
`)

0 commit comments

Comments
 (0)