UNPKG

2.09 kBPlain TextView Raw
1import nodePlop from './index';
2
3const plop = nodePlop('./file', {
4 destBasePath: './',
5 force: false,
6});
7
8const generators = plop.getGeneratorList();
9
10const names = generators.map((v) => v.name);
11
12const generator = plop.getGenerator(names[0]);
13
14plop.getWelcomeMessage();
15
16// $ExpectError
17plop.test();
18
19generator.runPrompts(['test']).then((answers) => {
20 const onComment = (): void => {
21 console.log('Start');
22 };
23 const onSuccess = (): void => {
24 console.log('This worked!');
25 };
26 const onFailure = (): void => {
27 console.log('Failed');
28 };
29 return generator.runActions(answers, { onSuccess, onFailure, onComment }).then(() => {
30 console.log('Done');
31 });
32});
33
34plop.setGenerator('test', {
35 description: "test generator",
36 prompts: [{
37 type: 'input',
38 name: 'name',
39 message() {
40 return 'test name';
41 },
42 validate(value) {
43 if ((/.+/).test(value)) { return true; }
44 return 'test name is required';
45 }
46 }],
47 actions: [{
48 type: 'add',
49 path: 'tests/{{dashCase name}}.ava.js',
50 templateFile: 'plop-templates/ava-test.js'
51 }]
52});
53
54plop.setGenerator('test-dynamic-prompts-only', {
55 description: "test dynamic prompts only",
56 prompts: async (inquirer) => ({
57 name: "something-dynamic"
58 }),
59 actions: [{
60 type: 'add',
61 path: 'tests/{{dashCase name}}.ava.js',
62 templateFile: 'plop-templates/ava-test.js'
63 }]
64});
65
66
67plop.setGenerator('test-dynamic-actions-only', {
68 description: "test dynamic actions only",
69 prompts: [{
70 type: 'input',
71 name: 'name',
72 message() {
73 return 'test name';
74 },
75 validate(value) {
76 if ((/.+/).test(value)) { return true; }
77 return 'test name is required';
78 }
79 }],
80 actions(data) {
81 return [{
82 type: 'add',
83 path: 'tests/{{dashCase name}}.ava.js',
84 templateFile: 'plop-templates/ava-test.js',
85 }];
86 }
87});
88
89plop.setGenerator("test-dynamic-prompts-and-actions", {
90 description: "Uses dynamic prompts and actions",
91 async prompts(inquirer) {
92 return {
93 name: "something-dynamic"
94 }
95 },
96 actions(data) {
97 return [{
98 type: 'add',
99 path: 'tests/{{dashCase name}}.ava.js',
100 templateFile: 'plop-templates/ava-test.js',
101 }];
102 }
103})
\No newline at end of file