|
@@ -12,9 +12,9 @@ const {
|
|
recipeByDescriptiveName,
|
|
recipeByDescriptiveName,
|
|
recipeByShortName,
|
|
recipeByShortName,
|
|
install,
|
|
install,
|
|
|
|
+ checkPackageManager,
|
|
shell,
|
|
shell,
|
|
} = require("../dist/");
|
|
} = require("../dist/");
|
|
-const { dir } = require("console");
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @type {object}
|
|
* @type {object}
|
|
@@ -38,6 +38,7 @@ const createTauriApp = async (cliArgs) => {
|
|
v: "version",
|
|
v: "version",
|
|
f: "force",
|
|
f: "force",
|
|
l: "log",
|
|
l: "log",
|
|
|
|
+ m: "manager",
|
|
d: "directory",
|
|
d: "directory",
|
|
b: "binary",
|
|
b: "binary",
|
|
t: "tauri-path",
|
|
t: "tauri-path",
|
|
@@ -81,6 +82,7 @@ function printUsage() {
|
|
--ci Skip prompts
|
|
--ci Skip prompts
|
|
--force, -f Force init to overwrite [conf|template|all]
|
|
--force, -f Force init to overwrite [conf|template|all]
|
|
--log, -l Logging [boolean]
|
|
--log, -l Logging [boolean]
|
|
|
|
+ --manager, -d Set package manager to use [npm|yarn]
|
|
--directory, -d Set target directory for init
|
|
--directory, -d Set target directory for init
|
|
--binary, -b Optional path to a tauri binary from which to run init
|
|
--binary, -b Optional path to a tauri binary from which to run init
|
|
--app-name, -A Name of your Tauri application
|
|
--app-name, -A Name of your Tauri application
|
|
@@ -142,6 +144,8 @@ async function runInit(argv, config = {}) {
|
|
window: { title },
|
|
window: { title },
|
|
},
|
|
},
|
|
} = config;
|
|
} = config;
|
|
|
|
+ // this little fun snippet pulled from vite determines the package manager the script was run from
|
|
|
|
+ const packageManager = /yarn/.test(process.env.npm_execpath) ? "yarn" : "npm";
|
|
|
|
|
|
let recipe;
|
|
let recipe;
|
|
|
|
|
|
@@ -157,7 +161,7 @@ async function runInit(argv, config = {}) {
|
|
};
|
|
};
|
|
|
|
|
|
if (recipe !== undefined) {
|
|
if (recipe !== undefined) {
|
|
- buildConfig = recipe.configUpdate(buildConfig);
|
|
|
|
|
|
+ buildConfig = recipe.configUpdate({ buildConfig, packageManager });
|
|
}
|
|
}
|
|
|
|
|
|
const directory = argv.d || process.cwd();
|
|
const directory = argv.d || process.cwd();
|
|
@@ -166,14 +170,18 @@ async function runInit(argv, config = {}) {
|
|
appName: appName || argv.A,
|
|
appName: appName || argv.A,
|
|
windowTitle: title || argv.w,
|
|
windowTitle: title || argv.w,
|
|
};
|
|
};
|
|
|
|
+
|
|
// note that our app directory is reliant on the appName and
|
|
// note that our app directory is reliant on the appName and
|
|
// generally there are issues if the path has spaces (see Windows)
|
|
// generally there are issues if the path has spaces (see Windows)
|
|
// future TODO prevent app names with spaces or escape here?
|
|
// future TODO prevent app names with spaces or escape here?
|
|
const appDirectory = join(directory, cfg.appName);
|
|
const appDirectory = join(directory, cfg.appName);
|
|
|
|
|
|
|
|
+ // this throws an error if we can't run the package manager they requested
|
|
|
|
+ await checkPackageManager({ cwd: directory, packageManager });
|
|
|
|
+
|
|
if (recipe.preInit) {
|
|
if (recipe.preInit) {
|
|
console.log("===== running initial command(s) =====");
|
|
console.log("===== running initial command(s) =====");
|
|
- await recipe.preInit({ cwd: directory, cfg });
|
|
|
|
|
|
+ await recipe.preInit({ cwd: directory, cfg, packageManager });
|
|
}
|
|
}
|
|
|
|
|
|
const initArgs = [
|
|
const initArgs = [
|
|
@@ -183,24 +191,24 @@ async function runInit(argv, config = {}) {
|
|
["--dev-path", cfg.devPath],
|
|
["--dev-path", cfg.devPath],
|
|
].reduce((final, argSet) => {
|
|
].reduce((final, argSet) => {
|
|
if (argSet[1]) {
|
|
if (argSet[1]) {
|
|
- return final.concat([argSet[0], `\"${argSet[1]}\"`]);
|
|
|
|
|
|
+ return final.concat(argSet);
|
|
} else {
|
|
} else {
|
|
return final;
|
|
return final;
|
|
}
|
|
}
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
- const installed = await install({
|
|
|
|
|
|
+ console.log("===== installing any additional needed deps =====");
|
|
|
|
+ await install({
|
|
appDir: appDirectory,
|
|
appDir: appDirectory,
|
|
dependencies: recipe.extraNpmDependencies,
|
|
dependencies: recipe.extraNpmDependencies,
|
|
- devDependencies: ["tauri", ...recipe.extraNpmDevDependencies],
|
|
|
|
|
|
+ devDependencies: ["@tauri-apps/cli", ...recipe.extraNpmDevDependencies],
|
|
|
|
+ packageManager,
|
|
});
|
|
});
|
|
|
|
|
|
console.log("===== running tauri init =====");
|
|
console.log("===== running tauri init =====");
|
|
- const binary = !argv.b
|
|
|
|
- ? installed.packageManager
|
|
|
|
- : resolve(appDirectory, argv.b);
|
|
|
|
|
|
+ const binary = !argv.b ? packageManager : resolve(appDirectory, argv.b);
|
|
const runTauriArgs =
|
|
const runTauriArgs =
|
|
- installed.packageManager === "npm" && !argv.b
|
|
|
|
|
|
+ packageManager === "npm" && !argv.b
|
|
? ["run", "tauri", "--", "init"]
|
|
? ["run", "tauri", "--", "init"]
|
|
: ["tauri", "init"];
|
|
: ["tauri", "init"];
|
|
await shell(binary, [...runTauriArgs, ...initArgs], {
|
|
await shell(binary, [...runTauriArgs, ...initArgs], {
|
|
@@ -212,6 +220,7 @@ async function runInit(argv, config = {}) {
|
|
await recipe.postInit({
|
|
await recipe.postInit({
|
|
cwd: appDirectory,
|
|
cwd: appDirectory,
|
|
cfg,
|
|
cfg,
|
|
|
|
+ packageManager,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|