Skip to content

Commit

Permalink
1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
whosydd committed Oct 14, 2021
1 parent a0b4aa5 commit 27ad2ba
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 140 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.3.0 (2021-10-14)

- 重新调整项目目录结构,优化代码
- 在使用`remove`命令时,剔除默认主题选项
- 为了可能会增加的新功能,更改 engines 为 1.61.0

## 1.2.4 (2021-10-14)

- 修复:移除主题时,没有选择会弹出‘移除 undefined 的提示’
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "ayu-mirage-plus",
"displayName": "Ayu Mirage Plus",
"description": "This theme is basic on Ayu Mirage, just for fun! :)",
"version": "1.2.4",
"version": "1.3.0",
"publisher": "GY",
"repository": {
"type": "git",
"url": "https://github.com/whosydd/ayu-mirage-plus"
},
"license": "MIT",
"engines": {
"vscode": "^1.57.0"
"vscode": "^1.61.0"
},
"categories": [
"Themes"
Expand Down Expand Up @@ -170,7 +170,7 @@
"@types/glob": "^7.1.3",
"@types/mocha": "^8.0.4",
"@types/node": "^15.12.5",
"@types/vscode": "^1.46.0",
"@types/vscode": "^1.61.0",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1",
"copy-webpack-plugin": "^9.0.1",
Expand Down
65 changes: 65 additions & 0 deletions src/config/tips.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as vscode from 'vscode'
import { Theme } from './types'

export const tipSetConfig = (config: string) => {
vscode.window
.showWarningMessage(
`Please set "ayu-mirage-plus.${config}Theme" in settings.json first!`,
'Open settings.json'
)
.then(value =>
value === 'Open settings.json'
? vscode.commands.executeCommand('workbench.action.openSettingsJson')
: null
)
}

export const tipConfigFormat = () => {
vscode.window.showInformationMessage('Ayu Mirage Plus 1.2.0 new!', {
modal: true,
detail: `现在配置项需要 name 和 colors 属性,请重新配置选项!
Now you need use "name" and "colors" in the configuration items.
For details, please refer to the extension page.`,
})
}

export const tipAlready = (name: string, config: string) => {
vscode.window
.showInformationMessage(`The "Ayu Mirage Plus ${name}" ${config}`, 'Reload Window')
.then(value =>
value === 'Reload Window'
? vscode.commands.executeCommand('workbench.action.reloadWindow')
: null
)
}

export const tipCreateConfig = (name: string) => {
vscode.window
.showWarningMessage(
`The "Ayu Mirage Plus ${name}" has not been created yet!`,
'Open settings.json'
)
.then(value =>
value === 'Open settings.json'
? vscode.commands.executeCommand('workbench.action.openSettingsJson')
: null
)
}

export const tipRemove = (rmList: Theme[]) => {
vscode.window
.showInformationMessage(
`${rmList?.map(item => item.label).toString()} has been removed!`,
'Reload Window'
)
.then(value =>
value === 'Reload Window'
? vscode.commands.executeCommand('workbench.action.reloadWindow')
: null
)
}

export const tipNothing = () => {
vscode.window.showWarningMessage('Nothing to remove!')
}
15 changes: 15 additions & 0 deletions src/config/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface ConfigParams {
name: string
colors: {
themeColor: string
foreground: string
border: string
highlight: string
}
}

export interface Theme {
label: string
uiTheme: string
path: string
}
78 changes: 31 additions & 47 deletions src/utils/add.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
import * as fs from 'fs'
import * as vscode from 'vscode'
import settings from '../config/settings'
import { tipConfigFormat, tipSetConfig, tipAlready } from '../config/tips'
import { ConfigParams, Theme } from '../config/types'

const { foregroundColors, themeColors, borderColors, highlightColors } = settings

// 配置项格式

export default async () => {
// 获取设置选项
const res:
| [
{
name: string
colors: {
themeColor: string
foreground: string
border: string
highlight: string
}
}
]
| undefined = await vscode.workspace.getConfiguration('ayu-mirage-plus').get('addTheme')
const config: ConfigParams[] | undefined = await vscode.workspace
.getConfiguration('ayu-mirage-plus')
.get('addTheme')

// 判断配置项
if (res && res.length > 0 && res[0].name !== '') {
// 判断配置项格式
if (!res[0].colors) {
vscode.window.showInformationMessage('Ayu Mirage Plus 1.2.0 new!', {
modal: true,
// @ts-ignore
detail: `现在配置项需要 name 和 colors 属性,请重新配置选项!
Now you need use "name" and "colors" in the configuration items.
For details, please refer to the extension page.`,
})
try {
// 配置项不存在抛出错误
if (config === undefined) {
throw new Error('配置项不存在!')
}

// 检测是否存在配置项
if (config[0].name === '') {
tipSetConfig('add')
return
}

const themes = res.reduce<{ label: string; uiTheme: string; path: string }[]>((pre, item) => {
// 配置项格式不正确弹出提示(历史遗留问题)
if (!config[0].colors) {
tipConfigFormat()
return
}

// 处理配置项
const themes = config.reduce<Theme[]>((pre, item) => {
const {
name,
colors: { themeColor, foreground, border, highlight },
Expand All @@ -50,28 +48,22 @@ export default async () => {
if (err) {
throw err
}

const theme = JSON.parse(data)
themeColors.forEach(item => (theme.colors[item] = themeColor))
foregroundColors.forEach(item => (theme.colors[item] = foreground))
borderColors.forEach(item => (theme.colors[item] = border))
highlightColors.forEach(item => (theme.colors[item] = highlight))
theme.name = `Ayu Mirage Plus ${name}`
fs.writeFileSync(`${__dirname}/themes/theme-${name}.json`, JSON.stringify(theme))
vscode.window
.showInformationMessage(
`The "Ayu Mirage Plus ${name}" has been created!`,
'Reload Window'
)
.then(value =>
value === 'Reload Window'
? vscode.commands.executeCommand('workbench.action.reloadWindow')
: null
)

tipAlready(name, 'has been created!')
})
)
} else {
vscode.window.showWarningMessage(`The "Ayu Mirage Plus ${name}" already exists!`)
}

return [
...pre,
{
Expand All @@ -87,6 +79,7 @@ export default async () => {
if (err) {
throw err
}

const packageFile = JSON.parse(data)
themes.forEach(item => {
if (
Expand All @@ -97,16 +90,7 @@ export default async () => {
})
fs.writeFileSync(`${__dirname}/../package.json`, JSON.stringify(packageFile))
})
} else {
vscode.window
.showWarningMessage(
'Please set "ayu-mirage-plus.addTheme" in settings.json first!',
'Open settings.json'
)
.then(value =>
value === 'Open settings.json'
? vscode.commands.executeCommand('workbench.action.openSettingsJson')
: null
)
} catch (error: any) {
vscode.window.showErrorMessage(error.message)
}
}
63 changes: 33 additions & 30 deletions src/utils/remove.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
import * as fs from 'fs'
import * as path from 'path'
import * as vscode from 'vscode'
import { tipNothing, tipRemove } from '../config/tips'
import { Theme } from '../config/types'

export default async () => {
fs.readFile(`${__dirname}/../package.json`, 'utf-8', async (err, data) => {
if (err) {
throw err
}

// 获取package.json中的主题配置
const packageFile = JSON.parse(data)
let themes: { label: string; uiTheme: string; path: string }[] = packageFile.contributes.themes
const rmList = await vscode.window.showQuickPick(themes, {
let themes: Theme[] = packageFile.contributes.themes

// 去除默认主题
const rmThemeList = themes.filter(item => item.label !== 'Ayu Mirage Plus')

if (rmThemeList.length === 0) {
tipNothing()
return
}

// 选择需要删除的主题列表
const rmList = await vscode.window.showQuickPick(rmThemeList, {
canPickMany: true,
})
const rmThemeList = rmList?.filter(item => themes.includes(item))

// 删除主题文件
rmThemeList?.forEach(item => {
const fileName = [
...__dirname.split(path.sep),
...item.path.split('dist/')[1].split(path.sep),
].join('/')
if (fs.existsSync(fileName)) {
fs.rmSync(fileName)
}
})

// 移除package.json中的主题
const res = themes.filter(item => !rmThemeList?.includes(item))
packageFile.contributes.themes = res
fs.writeFileSync(`${__dirname}/../package.json`, JSON.stringify(packageFile))

if (rmThemeList !== undefined) {
vscode.window
.showInformationMessage(
`${rmThemeList?.map(item => item.label).toString()} has been removed!`,
'Reload Window'
)
.then(value =>
value === 'Reload Window'
? vscode.commands.executeCommand('workbench.action.reloadWindow')
: null
)
if (rmList !== undefined) {
// 删除主题文件
rmList.forEach(item => {
const fileName = [
...__dirname.split(path.sep),
...item.path.split('dist/')[1].split(path.sep),
].join('/')
if (fs.existsSync(fileName)) {
fs.rmSync(fileName)
}
})

// 移除package.json中的主题
const res = themes.filter(item => !rmList?.includes(item))
packageFile.contributes.themes = res
fs.writeFileSync(`${__dirname}/../package.json`, JSON.stringify(packageFile))

tipRemove(rmList)
}
})
}
Loading

0 comments on commit 27ad2ba

Please sign in to comment.