Skip to content
45 changes: 35 additions & 10 deletions bin/asinit
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,26 @@ const fs = require("fs");
const path = require("path");
const colors = require("../cli/util/colors");
const version = require("../package.json").version;
const options = require("../cli/util/options");

if (process.argv.length != 3 || process.argv[2] == "--help" || process.argv[2] == "-h") printHelp();
const asinitOptions = {
"help": {
"category": "General",
"description": "Prints a help message.",
"type": "b",
"alias": "h"
},
"yes": {
"category": "General",
"description": "Skips asking the user if they want to setup an AssemblyScript project.",
"type": "b",
"alias": "y"
}
};

const cliOptions = options.parse(process.argv, asinitOptions);

if (cliOptions.options.help) printHelp();

function printHelp() {
console.log([
Expand All @@ -19,12 +37,7 @@ function printHelp() {
process.exit(0);
}

const rl = require("readline").createInterface({
input: process.stdin,
output: process.stdout
});

const projectDir = path.resolve(process.argv[2]);
const projectDir = path.resolve(cliOptions.arguments[2]);
const compilerDir = path.join(__dirname, "..");
const compilerVersion = require(path.join(compilerDir, "package.json")).version;
const assemblyDir = path.join(projectDir, "assembly");
Expand Down Expand Up @@ -75,7 +88,7 @@ console.log([
""
].join("\n"));

rl.question(colors.white("Do you want to proceed?") + " [Y/n] ", answer => {
function createProject(answer) {
if (!/^y?$/i.test(answer)) {
process.exit(1);
return;
Expand Down Expand Up @@ -132,8 +145,20 @@ rl.question(colors.white("Do you want to proceed?") + " [Y/n] ", answer => {
"",
"Have a nice day!"
].join("\n"));
rl.close();
});
}

if (cliOptions.options.yes) {
createProject("y");
} else {
const rl = require("readline").createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(colors.white("Do you want to proceed?") + " [Y/n] ", result => {
createProject(result);
rl.close();
});
}

function ensureProjectDirectory() {
console.log("- Making sure that the project directory exists...");
Expand Down
20 changes: 6 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.