-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplopfile.js
94 lines (92 loc) · 2.85 KB
/
plopfile.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
const slug = require('slug');
const YAML = require('yamljs');
const chalk = require('chalk');
const Site = require('./internals/models/site');
const Config = require('./internals/models/config');
const config = new Config(__dirname);
module.exports = (plop) => {
plop.setGenerator('Create Site', {
description: 'Creates site with config.yml file',
prompts: [
{
type: 'input',
name: 'name',
message: 'What is the site name',
},
{
type: 'input',
name: 'description',
message: 'Enter the site description',
},
{
type: 'list',
message: 'Select a schema',
name: 'schema',
choices: ['pod-full', 'simple'],
},
{
type: 'list',
message: 'Select search',
name: 'search',
choices: ['simpleSearch', 'elasticLunr', 'elasticSearch'],
},
{
type: 'editor',
message: 'Enter fields to include in the search index (as yml array of collections)',
name: 'fields',
},
{
type: 'list',
message: 'Select storage',
name: 'storage',
choices: ['FileStorage', 'Mongo'],
},
{
type: 'input',
message: 'Enter Front Page Icon Collection',
name: 'front-page-icon-collection',
default: 'theme',
},
{
type: 'editor',
message: 'Enter Front Page Icons (as yml array of ids)',
name: 'front-page-icons',
},
],
actions: (data) => {
const identifier = slug(data.name.toLowerCase());
const search = {
type: data.search,
fields: YAML.parse(data.fields),
};
const settings = {
name: data.name,
identifier,
schema: data.schema,
search,
description: data.description,
'front-page-icon-collection': data['front-page-icon-collection'],
'front-page-icons': YAML.parse(data['front-page-icons']),
};
const site = new Site(identifier, config);
site.create(settings, (err) => {
if (err === 'Site already exists') {
console.log(chalk.red('[PLOP] ') + 'Site "' + settings.name + '" already exists'); // eslint-disable-line
process.exit(1);
} else if (err === 'Schema not found') {
console.log(chalk.red('[PLOP] ') + 'Schema "' + settings.schema + '" not found'); // eslint-disable-line
process.exit(1);
} else if (err === 'Error creating config file') {
console.log(chalk.red('[PLOP] ') + err); // eslint-disable-line
process.exit(1);
} else if (err) {
console.log(chalk.red('[PLOP] ') + err); // eslint-disable-line
process.exit(1);
} else {
console.log(chalk.blue('[PLOP] ') + "Site creation successful."); // eslint-disable-line
}
});
return [];
},
});
};