forked from citizenfx/fivem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
63 lines (50 loc) · 1.75 KB
/
Gruntfile.js
File metadata and controls
63 lines (50 loc) · 1.75 KB
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
module.exports = function(grunt)
{
var fs = require('fs');
grunt.initConfig({
prompt: {
'component-new': {
options: {
questions: [
{
config: 'component.name',
type: 'input',
message: 'Component name',
validate: function(v) { return v.match(/^[a-z0-9\-:]+$/) ? true : 'Component names must only contain alphanumerics or dashes.'; }
}
]
}
}
}
});
grunt.loadNpmTasks('grunt-prompt');
grunt.registerTask('component-new', 'Creates a new component.', function()
{
var name = grunt.config.get('component.name');
var rawName = name;
name = name.replace(/:/g, '-');
if (!fs.existsSync('components/'))
{
fs.mkdirSync('components/');
}
fs.mkdirSync('components/' + name);
fs.appendFileSync('components/config.lua', grunt.template.process("component '<%= name %>'\r\n", { data: { name: name } }))
fs.writeFileSync('components/' + name + '/component.lua', '');
fs.writeFileSync('components/' + name + '/component.json', JSON.stringify({
'name': rawName,
'version': '0.1.0',
'dependencies': [
'fx[2]'
],
'provides': []
}, null, '\t'));
fs.writeFileSync('components/' + name + '/component.rc', "fxComponent 115 component.json\r\n")
fs.mkdirSync('components/' + name + '/include');
fs.mkdirSync('components/' + name + '/src');
fs.mkdirSync('components/' + name + '/tests');
fs.writeFileSync('components/' + name + '/include/Local.h', "#pragma once\r\n");
fs.writeFileSync('components/' + name + '/src/Component.cpp', fs.readFileSync('components/template/Component.cpp'));
grunt.log.ok('Component created.');
});
grunt.registerTask('component:new', ['prompt:component-new', 'component-new']);
};