Skip to content

Commit

Permalink
feat: Infer package manager from environment upon asinit (#1442)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis authored Aug 20, 2020
1 parent 61df707 commit a6e5da6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
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
35 changes: 31 additions & 4 deletions bin/asinit
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@ const colors = require("../cli/util/colors");
const version = require("../package.json").version;
const options = require("../cli/util/options");

const commands = {
"npm": {
install: "npm install",
run: "npm run",
test: "npm test"
},
"yarn": {
install: "yarn install",
run: "yarn",
test: "yarn test"
},
"pnpm": {
install: "pnpm install",
run: "pnpm run",
test: "pnpm test"
}
};

let pm = "npm";
if (typeof process.env.npm_config_user_agent === "string") {
if (/\byarn\//.test(process.env.npm_config_user_agent)) {
pm = "yarn";
} else if (/\bpnpm\//.test(process.env.npm_config_user_agent)) {
pm = "pnpm";
}
}

const asinitOptions = {
"help": {
"category": "General",
Expand Down Expand Up @@ -118,14 +145,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 +173,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 +316,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

0 comments on commit a6e5da6

Please sign in to comment.