Skip to content

Commit 3d13d7a

Browse files
committed
chore: Refactor prompts.js and index.js
Refactor the prompts.js and index.js files in the template/plugins/compile-js directory. The changes include fixing indentation and formatting issues, as well as updating variable names and adding comments for clarity.
1 parent 1b6e7e7 commit 3d13d7a

File tree

4 files changed

+73
-75
lines changed

4 files changed

+73
-75
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
2-
type: 'confirm',
3-
color: 'blue',
4-
message: '📘 Using typescript ?',
5-
initial: true,
2+
type: 'confirm',
3+
color: 'blue',
4+
message: '📘 Using typescript ?',
5+
initial: true,
66
};

template/plugins/index.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ const plugins = [typescriptPlugin, printSuccessPlugin];
2020
* @return {Promise<*>}
2121
*/
2222
async function applyPlugin(name, plugin, response) {
23-
if (!plugin.promptsOptions) {
24-
await plugin.apply(null, response);
25-
return { [name]: null, ...response };
26-
}
27-
const { value } = await prompts({ ...plugin.promptsOptions, name: 'value' });
28-
await plugin.apply(value, response);
29-
return { [name]: value, ...response };
23+
if (!plugin.promptsOptions) {
24+
await plugin.apply(null, response);
25+
return { [name]: null, ...response };
26+
}
27+
const { value } = await prompts({ ...plugin.promptsOptions, name: 'value' });
28+
await plugin.apply(value, response);
29+
return { [name]: value, ...response };
3030
}
3131

3232
module.exports = {
33-
/**
34-
* Apply all plugin in the order of plugin
35-
* @return {Promise<{apply: function(*=): Promise<void>, name: string, promptsOptions: {onRender(*): void, initial: boolean, name: string, type: string, message: string}|{type?: string, name?: string, message?: string, msg?: *, initial?: boolean, onRender?: function(*): void}}|{name?: string, promptsOptions?: {onRender(*): void, initial: boolean, name: string, type: string, message: string}|{type?: string, name?: string, message?: string, msg?: *, initial?: boolean, onRender?: function(*): void}, apply?: function(*=): Promise<void>}|{apply: function(*, *): Promise<Promise.Promise|Promise<unknown>>, name: string, promptsOptions: null}|{name?: string, promptsOptions?: null, apply?: function(*, *): Promise<Promise.Promise|Promise<unknown>>}>}
36-
*/
37-
async applyPlugins() {
38-
return plugins.reduce(
39-
(acc, { name, ...plugin }) =>
40-
acc.then(response => applyPlugin(name, plugin, response)),
41-
Promise.resolve({})
42-
);
43-
},
33+
/**
34+
* Apply all plugin in the order of plugin
35+
* @return {Promise<{apply: function(*=): Promise<void>, name: string, promptsOptions: {onRender(*): void, initial: boolean, name: string, type: string, message: string}|{type?: string, name?: string, message?: string, msg?: *, initial?: boolean, onRender?: function(*): void}}|{name?: string, promptsOptions?: {onRender(*): void, initial: boolean, name: string, type: string, message: string}|{type?: string, name?: string, message?: string, msg?: *, initial?: boolean, onRender?: function(*): void}, apply?: function(*=): Promise<void>}|{apply: function(*, *): Promise<Promise.Promise|Promise<unknown>>, name: string, promptsOptions: null}|{name?: string, promptsOptions?: null, apply?: function(*, *): Promise<Promise.Promise|Promise<unknown>>}>}
36+
*/
37+
async applyPlugins() {
38+
return plugins.reduce(
39+
(acc, { name, ...plugin }) =>
40+
acc.then((response) => applyPlugin(name, plugin, response)),
41+
Promise.resolve({}),
42+
);
43+
},
4444
};
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
// eslint-disable-next-line @typescript-eslint/no-var-requires
21
const promptsOptions = require('./_prompts');
3-
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/unbound-method
42
const { apply } = require('./plugin');
53

64
module.exports = {
7-
name: 'printSuccess',
8-
promptsOptions,
9-
apply,
5+
name: 'printSuccess',
6+
promptsOptions,
7+
apply,
108
};
Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
const { green, blue, yellow, red } = require('kleur');
22

33
module.exports = {
4-
async apply(value, previousValues) {
5-
return new Promise(resolve => {
6-
console.log('\n');
7-
console.log(
8-
'TheCodingMachine React-Native Boilerplate initialized with success ! 🚀\n'
9-
);
10-
console.log(
11-
`${green(
12-
' .-` `:: \n' +
13-
' `///////////// `/shhhy+- ://. /sy/ /ss/ :NMN: \n' +
14-
' `sssssyhhhyhhy:` `yMMMMNNMMMd. osss: `hMMMh- .-` `+ss: +MMm/. \n' +
15-
' :MMM+----. `mMMm+:-`.oo/` osssyo` `dMMMMh- ohhh- `oyy+- sMMd/. \n' +
16-
' :MMM+` oMMN/- osssyhs`.mMMMMMh- -hds` .syy+- `hMMh:` \n' +
17-
' :MMM+` hMMd: oss-ohhhMMMhdMMh- `. +NNm/. .dMMy:` \n' +
18-
' :MMM+` oMMN/ oss-`shdMMd:dMMh- :-` sMMd/. -NMMo- \n' +
19-
' :MMM+` `mMMm/` `/+:. oss- `sdMd:.hMMh- hMys- `hMMh:` -hdy-` \n' +
20-
' :MMM+` `yMMMMdssss+ oss. `oh/- hMMh- -hyo: dMMs:` -ss+` \n' +
21-
' .oys:` .+yhyo/- -::` `` -syo- ..` +mo- `// \n' +
22-
' `` ``` `` `. '
23-
)}`
24-
);
25-
if (previousValues.typescript) {
26-
console.log(blue(' THE TYPESCRIPT VERSION 📘'));
27-
} else {
28-
console.log(yellow(' THE JAVASCRIPT VERSION 📒'));
29-
}
30-
console.log('\n');
4+
async apply(value, previousValues) {
5+
return new Promise((resolve) => {
6+
console.log('\n');
7+
console.log(
8+
'TheCodingMachine React-Native Boilerplate initialized with success ! 🚀\n',
9+
);
10+
console.log(
11+
`${green(
12+
' .-` `:: \n' +
13+
' `///////////// `/shhhy+- ://. /sy/ /ss/ :NMN: \n' +
14+
' `sssssyhhhyhhy:` `yMMMMNNMMMd. osss: `hMMMh- .-` `+ss: +MMm/. \n' +
15+
' :MMM+----. `mMMm+:-`.oo/` osssyo` `dMMMMh- ohhh- `oyy+- sMMd/. \n' +
16+
' :MMM+` oMMN/- osssyhs`.mMMMMMh- -hds` .syy+- `hMMh:` \n' +
17+
' :MMM+` hMMd: oss-ohhhMMMhdMMh- `. +NNm/. .dMMy:` \n' +
18+
' :MMM+` oMMN/ oss-`shdMMd:dMMh- :-` sMMd/. -NMMo- \n' +
19+
' :MMM+` `mMMm/` `/+:. oss- `sdMd:.hMMh- hMys- `hMMh:` -hdy-` \n' +
20+
' :MMM+` `yMMMMdssss+ oss. `oh/- hMMh- -hyo: dMMs:` -ss+` \n' +
21+
' .oys:` .+yhyo/- -::` `` -syo- ..` +mo- `// \n' +
22+
' `` ``` `` `. ',
23+
)}`,
24+
);
25+
if (previousValues.typescript) {
26+
console.log(blue(' THE TYPESCRIPT VERSION 📘'));
27+
} else {
28+
console.log(yellow(' THE JAVASCRIPT VERSION 📒'));
29+
}
30+
console.log('\n');
3131

32-
console.log(
33-
'- 📚 If you need to read more about this boilerplate : https://thecodingmachine.github.io/react-native-boilerplate/'
34-
);
35-
console.log(
36-
'- 🤕 If you have some troubles : https://github.com/thecodingmachine/react-native-boilerplate/issues'
37-
);
38-
console.log(
39-
'- ⭐ If you love this boilerplate, give us a star, you will be a ray of sunshine in our lives :) https://github.com/thecodingmachine/react-native-boilerplate'
40-
);
32+
console.log(
33+
'- 📚 If you need to read more about this boilerplate : https://thecodingmachine.github.io/react-native-boilerplate/',
34+
);
35+
console.log(
36+
'- 🤕 If you have some troubles : https://github.com/thecodingmachine/react-native-boilerplate/issues',
37+
);
38+
console.log(
39+
'- ⭐ If you love this boilerplate, give us a star, you will be a ray of sunshine in our lives :) https://github.com/thecodingmachine/react-native-boilerplate',
40+
);
4141

42-
if (!previousValues.typescript) {
43-
console.log('\n');
44-
console.log(
45-
red(
46-
'🚨 You choose the javascript version, don\'t forget to run "yarn lint --fix" after the installation 🚨'
47-
)
48-
);
49-
console.log('\n');
50-
}
42+
if (!previousValues.typescript) {
43+
console.log('\n');
44+
console.log(
45+
red(
46+
'🚨 You choose the javascript version, don\'t forget to run "yarn lint:fix" after the installation 🚨',
47+
),
48+
);
49+
console.log('\n');
50+
}
5151

52-
resolve();
53-
});
54-
},
52+
resolve();
53+
});
54+
},
5555
};

0 commit comments

Comments
 (0)