Skip to content

Commit

Permalink
chore: Refactor prompts.js and index.js
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JeremyDolle committed Oct 8, 2024
1 parent 1b6e7e7 commit 3d13d7a
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 75 deletions.
8 changes: 4 additions & 4 deletions template/plugins/compile-js/_prompts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
type: 'confirm',
color: 'blue',
message: '📘 Using typescript ?',
initial: true,
type: 'confirm',
color: 'blue',
message: '📘 Using typescript ?',
initial: true,
};
36 changes: 18 additions & 18 deletions template/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ const plugins = [typescriptPlugin, printSuccessPlugin];
* @return {Promise<*>}
*/
async function applyPlugin(name, plugin, response) {
if (!plugin.promptsOptions) {
await plugin.apply(null, response);
return { [name]: null, ...response };
}
const { value } = await prompts({ ...plugin.promptsOptions, name: 'value' });
await plugin.apply(value, response);
return { [name]: value, ...response };
if (!plugin.promptsOptions) {
await plugin.apply(null, response);
return { [name]: null, ...response };
}
const { value } = await prompts({ ...plugin.promptsOptions, name: 'value' });
await plugin.apply(value, response);
return { [name]: value, ...response };
}

module.exports = {
/**
* Apply all plugin in the order of plugin
* @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>>}>}
*/
async applyPlugins() {
return plugins.reduce(
(acc, { name, ...plugin }) =>
acc.then(response => applyPlugin(name, plugin, response)),
Promise.resolve({})
);
},
/**
* Apply all plugin in the order of plugin
* @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>>}>}
*/
async applyPlugins() {
return plugins.reduce(
(acc, { name, ...plugin }) =>
acc.then((response) => applyPlugin(name, plugin, response)),
Promise.resolve({}),
);
},
};
8 changes: 3 additions & 5 deletions template/plugins/printSuccess/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const promptsOptions = require('./_prompts');
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/unbound-method
const { apply } = require('./plugin');

module.exports = {
name: 'printSuccess',
promptsOptions,
apply,
name: 'printSuccess',
promptsOptions,
apply,
};
96 changes: 48 additions & 48 deletions template/plugins/printSuccess/plugin.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
const { green, blue, yellow, red } = require('kleur');

module.exports = {
async apply(value, previousValues) {
return new Promise(resolve => {
console.log('\n');
console.log(
'TheCodingMachine React-Native Boilerplate initialized with success ! 🚀\n'
);
console.log(
`${green(
' .-` `:: \n' +
' `///////////// `/shhhy+- ://. /sy/ /ss/ :NMN: \n' +
' `sssssyhhhyhhy:` `yMMMMNNMMMd. osss: `hMMMh- .-` `+ss: +MMm/. \n' +
' :MMM+----. `mMMm+:-`.oo/` osssyo` `dMMMMh- ohhh- `oyy+- sMMd/. \n' +
' :MMM+` oMMN/- osssyhs`.mMMMMMh- -hds` .syy+- `hMMh:` \n' +
' :MMM+` hMMd: oss-ohhhMMMhdMMh- `. +NNm/. .dMMy:` \n' +
' :MMM+` oMMN/ oss-`shdMMd:dMMh- :-` sMMd/. -NMMo- \n' +
' :MMM+` `mMMm/` `/+:. oss- `sdMd:.hMMh- hMys- `hMMh:` -hdy-` \n' +
' :MMM+` `yMMMMdssss+ oss. `oh/- hMMh- -hyo: dMMs:` -ss+` \n' +
' .oys:` .+yhyo/- -::` `` -syo- ..` +mo- `// \n' +
' `` ``` `` `. '
)}`
);
if (previousValues.typescript) {
console.log(blue(' THE TYPESCRIPT VERSION 📘'));
} else {
console.log(yellow(' THE JAVASCRIPT VERSION 📒'));
}
console.log('\n');
async apply(value, previousValues) {
return new Promise((resolve) => {
console.log('\n');
console.log(
'TheCodingMachine React-Native Boilerplate initialized with success ! 🚀\n',
);
console.log(
`${green(
' .-` `:: \n' +
' `///////////// `/shhhy+- ://. /sy/ /ss/ :NMN: \n' +
' `sssssyhhhyhhy:` `yMMMMNNMMMd. osss: `hMMMh- .-` `+ss: +MMm/. \n' +
' :MMM+----. `mMMm+:-`.oo/` osssyo` `dMMMMh- ohhh- `oyy+- sMMd/. \n' +
' :MMM+` oMMN/- osssyhs`.mMMMMMh- -hds` .syy+- `hMMh:` \n' +
' :MMM+` hMMd: oss-ohhhMMMhdMMh- `. +NNm/. .dMMy:` \n' +
' :MMM+` oMMN/ oss-`shdMMd:dMMh- :-` sMMd/. -NMMo- \n' +
' :MMM+` `mMMm/` `/+:. oss- `sdMd:.hMMh- hMys- `hMMh:` -hdy-` \n' +
' :MMM+` `yMMMMdssss+ oss. `oh/- hMMh- -hyo: dMMs:` -ss+` \n' +
' .oys:` .+yhyo/- -::` `` -syo- ..` +mo- `// \n' +
' `` ``` `` `. ',
)}`,
);
if (previousValues.typescript) {
console.log(blue(' THE TYPESCRIPT VERSION 📘'));
} else {
console.log(yellow(' THE JAVASCRIPT VERSION 📒'));
}
console.log('\n');

console.log(
'- 📚 If you need to read more about this boilerplate : https://thecodingmachine.github.io/react-native-boilerplate/'
);
console.log(
'- 🤕 If you have some troubles : https://github.com/thecodingmachine/react-native-boilerplate/issues'
);
console.log(
'- ⭐ 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'
);
console.log(
'- 📚 If you need to read more about this boilerplate : https://thecodingmachine.github.io/react-native-boilerplate/',
);
console.log(
'- 🤕 If you have some troubles : https://github.com/thecodingmachine/react-native-boilerplate/issues',
);
console.log(
'- ⭐ 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',
);

if (!previousValues.typescript) {
console.log('\n');
console.log(
red(
'🚨 You choose the javascript version, don\'t forget to run "yarn lint --fix" after the installation 🚨'
)
);
console.log('\n');
}
if (!previousValues.typescript) {
console.log('\n');
console.log(
red(
'🚨 You choose the javascript version, don\'t forget to run "yarn lint:fix" after the installation 🚨',
),
);
console.log('\n');
}

resolve();
});
},
resolve();
});
},
};

0 comments on commit 3d13d7a

Please sign in to comment.