Skip to content

Commit 89232a6

Browse files
committed
npm.cmd
1 parent fa50249 commit 89232a6

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src-tauri/tauri.conf.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@
1919
"scope": [
2020
{
2121
"name": "run-npm",
22+
"cmd": "npm",
23+
"args": true
24+
},
25+
{
26+
"name": "run-npm-cmd",
2227
"cmd": "npm.cmd",
2328
"args": true
2429
}
2530
]
2631
},
2732
"fs": {
2833
"scope": [
29-
"$HOME/.m2/settings.xml",
30-
"$HOME/.npmrc"
34+
"$HOME/.m2/settings.xml"
3135
],
3236
"all": true,
3337
"readFile": true,

src/Npm.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect, useState } from "react";
22
import type { RadioChangeEvent } from "antd";
33
import { Input, Radio, Space, Spin } from "antd";
44
import { Command } from "@tauri-apps/api/shell";
5+
import { platform } from "@tauri-apps/api/os";
56

67
const Npm: React.FC = () => {
78
const [customUrl, setCustomUrl] = useState<string>("");
@@ -50,9 +51,16 @@ const Npm: React.FC = () => {
5051
const [value, setValue] = useState<string>("");
5152
const [url, setUrl] = useState<string>("");
5253

54+
async function getNpmProgram() {
55+
const platformName = await platform();
56+
return /^win/i.test(platformName) ? "run-npm.cmd" : "run-npm";
57+
}
58+
5359
function getUrl(): Promise<string> {
54-
return new Promise<string>((resolve) => {
55-
const command = new Command("run-npm", ["config", "get", "registry"]);
60+
return new Promise<string>(async (resolve) => {
61+
const platformName = await platform();
62+
const program = /^win/i.test(platformName) ? "run-npm-cmd" : "run-npm";
63+
const command = new Command(program, ["config", "get", "registry"]);
5664
let url = "";
5765

5866
command.stdout.on("data", (line) => {
@@ -68,6 +76,12 @@ const Npm: React.FC = () => {
6876
});
6977
}
7078

79+
async function writeUrlToFile(url: string) {
80+
const program = await getNpmProgram();
81+
const command = new Command(program, ["config", "set", "registry", url]);
82+
await command.spawn();
83+
}
84+
7185
const initRadio = () => {
7286
const option = npmOptions.find(
7387
(option) =>
@@ -110,11 +124,6 @@ const Npm: React.FC = () => {
110124
);
111125
}
112126

113-
async function writeUrlToFile(url: string) {
114-
const command = new Command("run-npm", ["config", "set", "registry", url]);
115-
await command.spawn();
116-
}
117-
118127
const onChange = async (e: RadioChangeEvent) => {
119128
let checkedValue = e.target.value;
120129
setValue(checkedValue);

0 commit comments

Comments
 (0)