Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer the right package manager per the environment #1442

Merged
merged 5 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ under the licensing terms detailed in LICENSE:
* Guido Zuidhof <me@guido.io>
* ncave <777696+ncave@users.noreply.github.com>
* Andrew Davis <pulpdrew@gmail.com>
* Maël Nison <nison.mael@gmail.com>

Portions of this software are derived from third-party works licensed under
the following terms:
Expand Down
32 changes: 28 additions & 4 deletions bin/asinit
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ const colors = require("../cli/util/colors");
const version = require("../package.json").version;
const options = require("../cli/util/options");

const commands = {
"npm": {
install: "npm install",
MaxGraey marked this conversation as resolved.
Show resolved Hide resolved
run: "npm run",
test: "npm test"
},
"yarn": {
install: "yarn install",
MaxGraey marked this conversation as resolved.
Show resolved Hide resolved
run: "yarn",
test: "yarn test"
},
"pnpm": {
install: "pnpm install",
run: "pnpm run",
test: "pnpm test"
}
};

let pm = "npm";
if (process.env.npm_config_user_agent.match(/\byarn\//))
MaxGraey marked this conversation as resolved.
Show resolved Hide resolved
pm = "yarn";
else if (process.env.npm_config_user_agent.match(/\bpnpm\//))
MaxGraey marked this conversation as resolved.
Show resolved Hide resolved
pm = "pnpm";

const asinitOptions = {
"help": {
"category": "General",
Expand Down Expand Up @@ -118,14 +142,14 @@ function createProject(answer) {
"",
"Don't forget to install dependencies before you start:",
"",
colors.white(" npm install"),
colors.white(" " + commands[pm].install),
"",
"To edit the entry file, open '" + colors.cyan("assembly/index.ts") + "' in your editor of choice.",
"Create as many additional files as necessary and use them as imports.",
"",
"To build the entry file to WebAssembly when you are ready, run:",
"",
colors.white(" npm run asbuild"),
colors.white(" " + commands[pm].run + " asbuild"),
"",
"Running the command above creates the following binaries incl. their respective",
"text format representations and source maps:",
Expand All @@ -146,7 +170,7 @@ function createProject(answer) {
"",
"To run the tests, do:",
"",
colors.white(" npm test"),
colors.white(" " + commands[pm].test),
"",
"The AssemblyScript documentation covers all the details:",
"",
Expand Down Expand Up @@ -289,7 +313,7 @@ function ensurePackageJson() {
const entryPath = path.relative(projectDir, entryFile).replace(/\\/g, "/");
const buildUntouched = "asc " + entryPath + " --target debug";
const buildOptimized = "asc " + entryPath + " --target release";
const buildAll = "npm run asbuild:untouched && npm run asbuild:optimized";
const buildAll = commands[pm].run + " asbuild:untouched && " + commands[pm].run + " asbuild:optimized";
if (!fs.existsSync(packageFile)) {
fs.writeFileSync(packageFile, JSON.stringify({
"scripts": {
Expand Down