Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
szmxx committed Sep 27, 2023
1 parent 022c965 commit 336764f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 43 deletions.
6 changes: 0 additions & 6 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
* @Author: cola
* @Date: 2023-09-08 00:40:20
* @LastEditors: cola
* @Description:
*/
import { defineBuildConfig } from "unbuild";

export default defineBuildConfig({
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"bin": {
"ucli": "./bin/index.mjs"
"uncli": "./bin/index.mjs"
},
"files": [
"bin",
Expand Down Expand Up @@ -76,4 +76,4 @@
"@types/inquirer": "^9.0.3",
"@types/node": "^20.5.9"
}
}
}
2 changes: 1 addition & 1 deletion src/api/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @LastEditors: cola
* @Description:
*/
const baseURL = "https://api.github.com";
const baseURL = "https://github.aitimi.cn";
import fetch from "node-fetch-native";
export async function createRepo(data: Record<string, unknown>, auth: string) {
return fetch(`${baseURL}/user/repos`, {
Expand Down
7 changes: 1 addition & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/*
* @Author: cola
* @Date: 2023-09-08 01:33:14
* @LastEditors: cola
* @Description:
*/

import { consola } from "consola";
import figlet from "figlet";
import { defineCommand, runMain } from "citty";
Expand Down
15 changes: 3 additions & 12 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
/*
* @Author: cola
* @Date: 2023-09-08 13:10:03
* @LastEditors: cola
* @Description:
*/
export const TemplateMap = {
vite: {
provider: "github",
username: "szmxx",
name: "template-vite",
defaultDir: "vite-app",
tar: "https://codeload.github.com/szmxx/template-vite/tar.gz/refs/heads/",
features: [
{
name: "主题",
Expand All @@ -25,10 +18,9 @@ export const TemplateMap = {
components: ["empty", "element-plus", "vant"],
},
nuxt3: {
provider: "github",
name: "template-nuxt3",
defaultDir: "nuxt3-app",
username: "szmxx",
tar: "https://codeload.github.com/szmxx/template-nuxt3/tar.gz/refs/heads/",
features: [
{
name: "主题",
Expand All @@ -44,10 +36,9 @@ export const TemplateMap = {
components: ["empty", "element-plus", "vant"],
},
node: {
provider: "github",
name: "template-node",
defaultDir: "node-app",
username: "szmxx",
tar: "https://codeload.github.com/szmxx/template-node/tar.gz/refs/heads/",
features: [],
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/inquirer/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function create() {
resolve(result);
break;
case "license":
resolve(result);
if (result["template"] === "node") resolve(result);
break;
}
});
Expand Down
37 changes: 22 additions & 15 deletions src/utils/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,27 @@ function getRepoBranchName(conf: Record<string, unknown>) {
return refName;
}

async function makeProviders(conf: Record<string, unknown>) {
const refName = getRepoBranchName(conf);
const auth = await $`git config --global ucli.auth`;
return (input: string) => {
const { name, tar } = TemplateMap?.[input as TemplateType];
consola.log(tar + refName);
return {
name: name,
headers: { authorization: auth?.stdout?.toString() },
tar: tar + refName,
};
};
}

export async function download(
repoName: string,
conf: Record<string, unknown>
) {
try {
const templateName = conf?.template as string;
const refName = getRepoBranchName(conf);
const {
username = "szmxx",
provider = "github",
name,
defaultDir = "",
} = TemplateMap?.[templateName as TemplateType];
const { defaultDir = "" } = TemplateMap?.[templateName as TemplateType];

const dirName = repoName || defaultDir;

Expand All @@ -65,14 +73,13 @@ export async function download(
}
}
spinner.start();
const auth = await $`git config --global ucli.auth`;
const { dir } = await downloadTemplate(
`${provider}:${username}/${name}#${refName}`,
{
auth: auth?.stdout?.toString(),
dir: dirName,
}
);
const themes = await makeProviders(conf);
const { dir } = await downloadTemplate(`themes:${templateName}`, {
dir: dirName,
providers: {
themes,
},
});
spinner.succeed(chalk.green("下载完成"));
return dir;
} catch (error) {
Expand Down

0 comments on commit 336764f

Please sign in to comment.