Play

Check-in [770b0da167]
Login
Overview
Comment:Add cli command for initializing project.
Timelines: family | ancestors | descendants | both | cli
Files: files | file ages | folders
SHA3-256: 770b0da1672de0e0ee6fef65507b28164ac17327e92d2f8a691ab21b95950119
User & Date: robin.hansen on 2021-04-07 08:01:17
Other Links: branch diff | manifest | tags
Context
2021-04-07
12:58
Add standard library as a dependency when creating a project with the 'init' command. check-in: 34e9e1a068 user: robin.hansen tags: cli
08:01
Add cli command for initializing project. check-in: 770b0da167 user: robin.hansen tags: cli
07:42
Find path to stdlib and pass that on to PackageLoader.elm. check-in: b5bd5c4ee0 user: robin.hansen tags: cli
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified bin/cli.js from [6508b8f3bf] to [0900cd213a].

1
2
3
4
5
6
7


8
9
10
11
12
13

14
15
16



























17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126
#!/usr/bin/env node

const path = require("path");
const fs = require("fs");
const wabtInit = require("wabt");

const stdLibPath = path.resolve(__dirname, "..", "stdlib");


const subCmd = process.argv[2];
const subCmdFlags = process.argv.slice(3);

switch (subCmd) {
    case "compile": compileProject(); break;
    case "run": runProject(); break;

    default: printHelp(); break;
}




























function runProject() {
    if (subCmdFlags.length !== 1) {
        console.error("run command requires exactly one argument: the function to run.");
        return;
    }

    compileProject(subCmdFlags[0]);
}

function compileProject(entryPoint) {
    const cwd = process.cwd();
    const rootJsonMetaPath = path.join(cwd, "play.json");
    if (!fs.existsSync(rootJsonMetaPath)) {
        console.error("No 'play.json' file found in this directory.");
        return;
    }

    const compiler = require(__dirname + "/compiler").Elm.CLI.init({
................................................................................
}

function printHelp() {
    console.log(`
Play compiler. Alpha-2.

Possible options are:

* compile: compile the project.
* run <function_name>: compile the project, and execute the given function.
* help: print this help message.
    `);
}

async function executeWat(wat, entryPointName) {
    const wabt = await wabtInit();
    const wasmModule = wabt.parseWat('tmp', wat).toBinary({}).buffer;







>
>




|

>



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


|







<







 







>

|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env node

const path = require("path");
const fs = require("fs");
const wabtInit = require("wabt");

const stdLibPath = path.resolve(__dirname, "..", "stdlib");
const cwd = process.cwd();

const subCmd = process.argv[2];
const subCmdFlags = process.argv.slice(3);

switch (subCmd) {
    case "init": initProject(); break;
    case "run": runProject(); break;
    case "compile": compileProject(); break;
    default: printHelp(); break;
}

function initProject() {
    if (subCmdFlags.length !== 1) {
        console.error("'init' requires exactly one argument: the package name.");
        return;
    }

    fs.mkdirSync(path.join(cwd, "src"));

    const playJson = {
        name: subCmdFlags[0],
        version: "0.1.0",
        "language-version": "0.2.0",
        "exposed-modules": [
            "main"
        ],
        dependencies: {},
        "package-paths": []
    };

    fs.writeFileSync(path.join(cwd, "play.json"), JSON.stringify(playJson, null, 4));

    fs.writeFileSync(path.join(cwd, "src", "main.play"), `
def: execute
: 0
`.trim());
}

function runProject() {
    if (subCmdFlags.length !== 1) {
        console.error("'run' requires exactly one argument: the function to run.");
        return;
    }

    compileProject(subCmdFlags[0]);
}

function compileProject(entryPoint) {

    const rootJsonMetaPath = path.join(cwd, "play.json");
    if (!fs.existsSync(rootJsonMetaPath)) {
        console.error("No 'play.json' file found in this directory.");
        return;
    }

    const compiler = require(__dirname + "/compiler").Elm.CLI.init({
................................................................................
}

function printHelp() {
    console.log(`
Play compiler. Alpha-2.

Possible options are:
* init <package_name>: initialize a new project in the current directory.
* compile: compile the project.
* run <function_name>: compile the project and execute the given function.
* help: print this help message.
    `);
}

async function executeWat(wat, entryPointName) {
    const wabt = await wabtInit();
    const wasmModule = wabt.parseWat('tmp', wat).toBinary({}).buffer;