UNPKG

2 kBJavaScriptView Raw
1
2var fs = require("fs")
3, child = require("child_process")
4, path = require("path")
5, cli = require("./index.js")
6, package = {
7 "name": "",
8 "version": "0.0.0",
9 "license": "MIT",
10 "author": "",
11 "description": "LiteJS application",
12 "main": "app/index.js",
13 "readmeFilename": "README.md",
14 "files": [
15 "app",
16 "ui"
17 ],
18 "scripts": {
19 "build": "litejs build",
20 "start": "node app",
21 "test": "node --allow-natives-syntax test/index.js",
22 "test-trace": "node --allow-natives-syntax --trace_opt --trace_deopt test/index.js"
23 },
24 "litejs": {
25 "build": [
26 "-i ui/dev.html -o ui/index.html"
27 ]
28 },
29 "repository": "git://github.com/{project}/{name}.git",
30 "bugs": {
31 "url": "https://github.com/{project}/{name}/issues"
32 }
33}
34
35module.exports = function(opts) {
36 var dir = path.join(process.cwd(), opts.file || "")
37
38 cli.mkdirp(dir)
39 process.chdir(dir)
40
41 try {
42 require(path.join(dir, "package.json"))
43 } catch(e) {
44 console.log("Create package.json")
45 makePackage(dir)
46 cli.cp(path.resolve(__dirname, "../template/README.md"), "README.md")
47 }
48
49 try {
50 fs.statSync(".gitignore")
51 } catch(e) {
52 console.log("Create .gitignore")
53 cli.cp(path.resolve(__dirname, "../../.gitignore"), ".gitignore")
54 }
55
56 child.spawnSync("npm", ["install", "--save-prod", "litejs"], {stdio: "inherit"})
57 //child.spawnSync("npm", ["link", "litejs"], {stdio: "inherit"})
58 child.spawnSync("./node_modules/.bin/litejs", ["init-app", "app"], {stdio: "inherit"})
59 child.spawnSync("./node_modules/.bin/litejs", ["init-ui", "ui"], {stdio: "inherit"})
60 child.spawnSync("git", ["init"], {stdio: "inherit"})
61 child.spawnSync("npm", ["run", "build"], {stdio: "inherit"})
62}
63
64function makePackage(dir) {
65 var tree = dir.split(path.sep)
66 , scope = {
67 name: tree.pop(),
68 project: tree.pop()
69 }
70 package.author = process.env.USER
71 package.name = scope.name
72 package.repository = package.repository.format(scope)
73 package.bugs.url = package.bugs.url.format(scope)
74 cli.writeFile("package.json", JSON.stringify(package, null, " "))
75}
76