Skip to content

Commit

Permalink
fix(CTA): #1569, manually set tauri script for compatability with old…
Browse files Browse the repository at this point in the history
…er npm (#1572)
  • Loading branch information
amrbashir committed Apr 22, 2021
1 parent 938fb62 commit f708ff8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-cta-set-script.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-tauri-app": patch
---

Manually set `tauri` script instead of using `npm set-script` for compatabilty with older npm versions
6 changes: 3 additions & 3 deletions tooling/create-tauri-app/bin/create-tauri-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
install,
checkPackageManager,
shell,
addTauriScript,
} = require("../dist/");

/**
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions tooling/create-tauri-app/src/helpers/add-tauri-script.ts
Original file line number Diff line number Diff line change
@@ -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));
}
16 changes: 11 additions & 5 deletions tooling/create-tauri-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

0 comments on commit f708ff8

Please sign in to comment.