Skip to content

Commit

Permalink
♻️ extract config
Browse files Browse the repository at this point in the history
  • Loading branch information
ras0q committed Feb 22, 2024
1 parent 9449efe commit a041920
Showing 1 changed file with 70 additions and 60 deletions.
130 changes: 70 additions & 60 deletions windows/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,71 @@ const flags: {

const home = Deno.env.get("USERPROFILE")!;
const rootDir = dirname(dirname(fromFileUrl(import.meta.url)));

const commonConfig = `${rootDir}/common/config`;
const windowsConfig = `${rootDir}/windows/config`;
const config = {
// deno-fmt-ignore
symlinks: {
[`${home}/.config/aquaproj-aqua`]: `${commonConfig}/aquaproj-aqua`,
[`${home}/.config/starship.toml`]: `${commonConfig}/starship.toml`,
[`${home}/.gitconfig`]: `${windowsConfig}/.gitconfig`,
[`${home}/.gittemplate.txt`]: `${commonConfig}/.gittemplate.txt`,
[`${home}/.wezterm.lua`]: `${commonConfig}/.wezterm.lua`,
[`${home}/.wslconfig`]: `${windowsConfig}/.wslconfig`,
[`${home}/AppData/Local/nvim`]: `${commonConfig}/nvim`,
[`${home}/AppData/Roaming/Code/User/settings.json`]: `${windowsConfig}/vscode/settings.json`,
[`${home}/Microsoft.PowerShell_profile.ps1`]: `${windowsConfig}/Microsoft.PowerShell_profile.ps1`,
[`${home}/Microsoft.VSCode_profile.ps1`]: `${windowsConfig}/Microsoft.PowerShell_profile.ps1`,
},
fonts: {
links: [
// 源ノ角ゴシック
"https://github.com/adobe-fonts/source-han-sans/raw/release/Variable/OTF/Subset/SourceHanSansJP-VF.otf",
// 源ノ角ゴシック Code
"https://github.com/adobe-fonts/source-han-code-jp/raw/release/OTF/SourceHanCodeJP-Regular.otf",
// Source Code Pro (Nerd Font)
"https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/SourceCodePro/SauceCodeProNerdFontMono-Regular.ttf",
],
dist: "./dist/fonts",
},
winget: {
link:
"https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle",
tmppath: "./winget.msixbundle",
packages: [
// Common GUI
"wez.wezterm",
"Microsoft.Edge",
"Microsoft.VisualStudioCode",
"AgileBits.1Password",
"Discord.Discord",
"Figma.Figma",
"Google.GoogleDrive",
"Obsidian.Obsidian",
"LINE.LINE",
"SlackTechnologies.Slack",
"Spotify.Spotify",
"OliverSchwendener.ueli",
"Betterbird.Betterbird",
// Common CLI
"aquaproj.aqua",
"Git.Git",
// Only for Windows
"Flow-Launcher.Flow-Launcher",
"jstarks.npiperelay",
"SomePythonThings.WingetUIStore",
"Microsoft.PowerShell",
"gerardog.gsudo",
"voidtools.Everything",
],
},
};

$.logStep("Creating symlinks");
await $.logGroup(async () => {
// deno-fmt-ignore
const symlinks = {
".config/aquaproj-aqua": `${commonConfig}/aquaproj-aqua`,
".config/starship.toml": `${commonConfig}/starship.toml`,
".gitconfig": `${windowsConfig}/.gitconfig`,
".gittemplate.txt": `${commonConfig}/.gittemplate.txt`,
".wezterm.lua": `${commonConfig}/.wezterm.lua`,
".wslconfig": `${windowsConfig}/.wslconfig`,
"AppData/Local/nvim": `${commonConfig}/nvim`,
"AppData/Roaming/Code/User/settings.json": `${windowsConfig}/vscode/settings.json`,
"Microsoft.PowerShell_profile.ps1": `${windowsConfig}/Microsoft.PowerShell_profile.ps1`,
"Microsoft.VSCode_profile.ps1": `${windowsConfig}/Microsoft.PowerShell_profile.ps1`,
}
await Promise.all(
Object.entries(symlinks).map(async ([_link, _target]) => {
const link = resolve(home, _link);
Object.entries(config.symlinks).map(async ([_link, _target]) => {
const link = resolve(_link);
const target = resolve(_target);
await exists(link) && await Deno.remove(link);
await Deno.symlink(target, link);
Expand All @@ -45,17 +88,10 @@ await $.logGroup(async () => {

$.logStep("Downloading fonts");
await $.logGroup(async () => {
const fonts = [
// 源ノ角ゴシック
"https://github.com/adobe-fonts/source-han-sans/raw/release/Variable/OTF/Subset/SourceHanSansJP-VF.otf",
// 源ノ角ゴシック Code
"https://github.com/adobe-fonts/source-han-code-jp/raw/release/OTF/SourceHanCodeJP-Regular.otf",
// Source Code Pro (Nerd Font)
"https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/SourceCodePro/SauceCodeProNerdFontMono-Regular.ttf",
];
const fontBaseDir = resolve(rootDir, "windows/dist/fonts");
const { dist, links } = config.fonts;
const fontBaseDir = resolve(dist);
await $`mkdir -p ${fontBaseDir}`;
await Promise.all(fonts.map(async (font) => {
await Promise.all(links.map(async (font) => {
const fontPath = resolve(fontBaseDir, font.split("/").slice(-1)[0]);
const data = await $.request(font).showProgress();
await Deno.writeFile(fontPath, new Uint8Array(await data.arrayBuffer()));
Expand All @@ -65,57 +101,29 @@ await $.logGroup(async () => {

$.logStep("Setting up winget and packages");
await $.logGroup(async () => {
const { link, tmppath, packages } = config.winget;
if (
flags["upgrade-winget"] ||
!((await $`pwsh -c Get-Command winget`.stdout("null")).code === 0)
) {
$.logStep("Installing winget");
const wingetLink =
"https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle";
const wingetPath = "./winget.msixbundle";
const data = await $.request(wingetLink).showProgress();
await Deno.writeFile(wingetPath, new Uint8Array(await data.arrayBuffer()));
await $`pwsh -c Add-AppxPackage -Path ${wingetPath}`;
await $`rm ${wingetPath}`;
const data = await $.request(link).showProgress();
await Deno.writeFile(tmppath, new Uint8Array(await data.arrayBuffer()));
await $`pwsh -c Add-AppxPackage -Path ${tmppath}`;
await $`rm ${tmppath}`;
$.logStep("Installed winget");
} else {
$.logStep("Skipped winget installation");
}

$.logStep("Installing winget packages");
const wingetPackages = [
// Common GUI
"wez.wezterm",
"Microsoft.Edge",
"Microsoft.VisualStudioCode",
"AgileBits.1Password",
"Discord.Discord",
"Figma.Figma",
"Google.GoogleDrive",
"Obsidian.Obsidian",
"LINE.LINE",
"SlackTechnologies.Slack",
"Spotify.Spotify",
"OliverSchwendener.ueli",
"Betterbird.Betterbird",
// Common CLI
"aquaproj.aqua",
"Git.Git",
// Only for Windows
"Flow-Launcher.Flow-Launcher",
"jstarks.npiperelay",
"SomePythonThings.WingetUIStore",
"Microsoft.PowerShell",
"gerardog.gsudo",
"voidtools.Everything",
];
const command = [
"winget",
"install",
"--accept-source-agreements",
"--accept-package-agreements",
"--silent",
...wingetPackages,
...packages,
].join(" ");
// TODO: why this command throws an error?
// error: Uncaught (in promise) Error: Exited with code: 1
Expand All @@ -132,3 +140,5 @@ await $.logGroup(async () => {
await $.commandExists("aqua") || $.logError("aqua is not installed");
await $`aqua install --all`;
});

$.log("Set up complete🎉🎉🎉");

0 comments on commit a041920

Please sign in to comment.