-
Notifications
You must be signed in to change notification settings - Fork 0
/
boilerPlateGen.js
118 lines (95 loc) · 4 KB
/
boilerPlateGen.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const fs = require("fs");
const nodePath = require('node:path');
const templates = ["test", "script", "gui_script"]
const path = process.argv.pop()
const template = process.argv.pop()
if (!templates.includes(template)) {
console.log(`ERROR No template: ${template}\nPlease use one of these templates:\n${templates.join(",\n")}\n format npm run boilerPlate <template> <path>`)
throw ("no template")
}
const fileName = nodePath.basename(path)
const templatesGenerators = {
test: [{
fileName: (fileName) => `${fileName}_test.ts`,
file: (fileName) => {
return `
export default () => {
describe("${fileName} Tests", () => {
before(() => {
// -- this function will be run before each test
})
after(() => {
// -- this function will be run after each test
})
test("In the end the Party would announce that two and two made five", () => {
assert_equal(2+2,5)
})
})
}
`
}
}],
script: [{
fileName: (fileName) => `${fileName}.script.ts`,
file: (fileName) => {
return `
interface props {
}
export function init(this: props): void {
}
export function final(this: props): void {
// Add finalization code here
// Learn more: https://defold.com/manuals/script/
// Remove this function if not needed
}
export function update(this: props, _dt: number): void {
// Add update code here
// Learn more: https://defold.com/manuals/script/
// Remove this function if not needed
}
export function on_message(this: props, _message_id: hash, _message: any, _sender: url): void {
// Add message-handling code here
// Learn more: https://defold.com/manuals/message-passing/
// Remove this function if not needed
}
export function on_input(this: props, _action_id: hash, _action: hash): void {
// Add input-handling code here. The game object this script is attached to
// must have acquired input focus:
//
// msg.post(".", "acquire_input_focus")
//
// All mapped input bindings will be received. Mouse and touch input will
// be received regardless of where on the screen it happened.
// Learn more: https://defold.com/manuals/input/
// Remove this function if not needed
}
export function on_reload(this: props): void {
// Add reload-handling code here
// Learn more: https://defold.com/manuals/hot-reload/
// Remove this function if not needed
}
`
}
}],
gui_script: [{
fileName: (fileName) => `${fileName}.gui_script.ts`,
file: (fileName) => {
return `
interface props {
}
export function init(this: props): void {
}
export function on_message(this: props, message_id: hash, message: string, sender: url): void {
// Add message-handling code here
// Learn more: https://defold.com/manuals/message-passing/
// Remove this function if not needed
}
`
}
}],
}
const selectedTemplate = templatesGenerators[template]
selectedTemplate.forEach(fileToMake => {
fs.writeFileSync(nodePath.join(path, fileToMake.fileName(fileName)), fileToMake.file(fileName));
});
console.log("thank you for shopping with us")