forked from rossning92/movy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovy.js
75 lines (66 loc) · 1.69 KB
/
movy.js
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
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const process = require('process');
const liveServer = require('live-server');
function createExampleFile(baseUrl, file) {
// Automatically create a boilerplate file if not exists.
if (!fs.existsSync(file)) {
fs.writeFileSync(
file,
`import * as mo from "movy";
mo.addText("Hello, Movy!", {
scale: 0.8,
color: "yellow",
}).grow();
`
);
}
// Create jsconfig.json for vscode IntelliSense.
const jsconfig = path.resolve(path.dirname(file), 'jsconfig.json');
if (!fs.existsSync(jsconfig)) {
fs.writeFileSync(
jsconfig,
JSON.stringify(
{
compilerOptions: {
module: 'commonjs',
target: 'es2016',
jsx: 'preserve',
baseUrl,
},
exclude: ['node_modules', '**/node_modules/*'],
},
null,
2
)
);
}
}
const projectRoot = path.resolve(__dirname, '..');
const argv = require('minimist')(process.argv.slice(2));
const file = argv._.length > 0 ? path.resolve(argv._[0]) : undefined;
if (file) createExampleFile(path.resolve(projectRoot, 'dist'), file);
const port = argv.port ? parseInt(argv.port, 10) : undefined;
let open = argv.open !== undefined ? argv.open : true;
if (open) {
if (file) {
open = `/?file=${path.basename(file)}`;
}
}
let mount;
if (file) {
mount = [['/', path.dirname(path.resolve(file))]];
if (argv.content) {
mount.push(['/', path.resolve(argv.content)]);
}
}
const params = {
port,
host: '0.0.0.0',
root: path.resolve(__dirname, '..', 'dist'),
open,
mount,
ignore: argv.hot === false ? '**' : undefined,
};
liveServer.start(params);