-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresourceMakeCommand.js
More file actions
46 lines (34 loc) Β· 1.15 KB
/
resourceMakeCommand.js
File metadata and controls
46 lines (34 loc) Β· 1.15 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
const GeneratorCommand = require('@ostro/console/generatorCommand')
class ResourceMakeCommand extends GeneratorCommand {
$signature = 'make:resource';
$description = 'Create a new resource';
$type = 'Resource';
$options = [
this.createOption('-c, --collection', 'Create a resource collection')
];
async handle() {
if (this.collection()) {
this.$type = 'Resource collection';
}
await super.handle();
}
getStub() {
return this.collection() ?
this.resolveStubPath('/stubs/resource-collection.stub') :
this.resolveStubPath('/stubs/resource.stub');
}
collection() {
return this.option('collection') ||
String.endsWith(this.argument('name'), 'Collection');
}
async resolveStubPath($stub) {
let $customPath = this.$app.basePath(trim($stub, path.sep))
return await this.$file.exists($customPath) ?
$customPath :
__dirname + $stub;
}
getDefaultNamespace($rootNamespace) {
return path.join($rootNamespace, 'app', 'http', 'resources');
}
}
module.exports = ResourceMakeCommand