fix(CTA): #1569, manually set tauri script for compatability with older npm (#1572)

This commit is contained in:
Amr Bashir 2021-04-22 02:26:49 +02:00 committed by GitHub
parent 938fb624f5
commit f708ff824e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 8 deletions

View File

@ -0,0 +1,5 @@
---
"create-tauri-app": patch
---
Manually set `tauri` script instead of using `npm set-script` for compatabilty with older npm versions

View File

@ -14,6 +14,7 @@ const {
install,
checkPackageManager,
shell,
addTauriScript,
} = require("../dist/");
/**
@ -208,9 +209,8 @@ async function runInit(argv, config = {}) {
});
console.log("===== running tauri init =====");
await shell("npm", ["set-script", "tauri", "tauri"], {
cwd: appDirectory,
});
addTauriScript(appDirectory);
const binary = !argv.b ? packageManager : resolve(appDirectory, argv.b);
const runTauriArgs =
packageManager === "npm" && !argv.b

View File

@ -0,0 +1,26 @@
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { readFileSync, writeFileSync } from "fs";
import { join } from "path";
export async function addTauriScript(appDirectory: string) {
const pkgPath = join(appDirectory, "package.json");
const pkgString = readFileSync(pkgPath, "utf8");
const pkg = JSON.parse(pkgString) as {
scripts: {
tauri: string;
};
};
let outputPkg = {
...pkg,
scripts: {
...pkg.scripts,
tauri: "tauri",
},
};
writeFileSync(pkgPath, JSON.stringify(outputPkg, undefined, 2));
}

View File

@ -10,6 +10,7 @@ import { vite } from "./recipes/vite";
export { shell } from "./shell";
export { install, checkPackageManager } from "./dependency-manager";
export { addTauriScript } from "./helpers/add-tauri-script";
import { PackageManager } from "./dependency-manager";
export interface Recipe {
@ -46,12 +47,17 @@ export interface Recipe {
export const allRecipes: Recipe[] = [vanillajs, reactjs, reactts, vite, vuecli];
export const recipeNames: Array<[string, string]> = allRecipes.map(r => [r.shortName, r.descriptiveName]);
export const recipeNames: Array<[string, string]> = allRecipes.map((r) => [
r.shortName,
r.descriptiveName,
]);
export const recipeByShortName = (name: string) => allRecipes.find(r => r.shortName === name);
export const recipeByShortName = (name: string) =>
allRecipes.find((r) => r.shortName === name);
export const recipeByDescriptiveName = (name: string) => allRecipes.find(r => r.descriptiveName === name);
export const recipeByDescriptiveName = (name: string) =>
allRecipes.find((r) => r.descriptiveName === name);
export const recipeShortNames = allRecipes.map(r => r.shortName);
export const recipeShortNames = allRecipes.map((r) => r.shortName);
export const recipeDescriptiveNames = allRecipes.map(r => r.descriptiveName);
export const recipeDescriptiveNames = allRecipes.map((r) => r.descriptiveName);