Skip to content

Commit

Permalink
feat: ✨ better setup script & prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyBeldone committed Nov 17, 2023
1 parent 6cf1dc9 commit b6e6522
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 10 deletions.
61 changes: 52 additions & 9 deletions setup/setup.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable import/no-extraneous-dependencies */
import chalk from 'chalk';
import { exec } from 'child_process';

import prompts from 'prompts';
import replace from 'replace';
Expand Down Expand Up @@ -37,6 +38,13 @@ const onCancel = () => {
const pkgJsonPathPrefix = process.env.MODE === 'test' ? 'setupCopy/' : '';
const setupPath = process.env.MODE === 'test' ? './setupCopy' : './setup';

// lancer la commande 'git init'
const gitInit = async () => {
const { stderr, stdout } = await exec('git init');
console.log('stdout:', stdout);
console.log('stderr:', stderr);
};

// Update package.json
const updatePackage = async () => {
writeMessage(pkgIntroMesage);
Expand Down Expand Up @@ -114,7 +122,6 @@ const updatePackage = async () => {

// Remove setup dependencies
async function cleanDeps() {
const { exec } = await import('child_process');
const { stdout } = await exec('yarn remove chalk prompts replace -D');
console.log('stdout:', stdout);
}
Expand All @@ -126,13 +133,6 @@ const updatePackage = async () => {
if (rmError) throw new Error(rmError);
});
});

// writeMessage(finalMessage);

// // remove all setup scripts from the 'tools' folder
// rimraf(setupPath, (rmError) => {
// if (rmError) throw new Error(rmError);
// });
};

// Initialize prompt
Expand All @@ -157,7 +157,50 @@ const updatePackage = async () => {
rimraf('.git', (error) => {
if (error) throw new Error(error);
writeMessage(gitDeleteMessage);
updatePackage();

// lance la commande 'git init'
gitInit().then(() => {
// ask for git remote url
prompts(
{
initial: '',
message:
'Git remote URL (ex: "git@github.com:JimmyBeldone/gatsby-starter-lemonade.git")',
name: 'value',
type: 'text',
},
{ onCancel },
).then((res) => {
// set git remote url
exec(
`git remote add origin ${res.value}`,
(err) => {
if (err) {
console.error(err);
return;
}

exec('git branch -M main', (errBranch) => {
if (errBranch) {
console.error(errBranch);
return;
}
// push to remote
exec(
'git push -u origin master',
(errPush) => {
if (errPush) {
console.error(errPush);
return;
}
updatePackage();
},
);
});
},
);
});
});
});
}
} else {
Expand Down
13 changes: 12 additions & 1 deletion setup/setupPrompts.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
/* eslint-disable no-underscore-dangle */
import path from 'path';
import { fileURLToPath } from 'url';

// Obtenir le chemin du fichier actuel
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Obtenir le nom du dossier de l'application
const appName = path.basename(path.resolve(__dirname, '..'));

// Define prompts for use with npm 'prompt' module in setup script
export default [
{
initial: 'my-new-project',
initial: appName,
message: 'Project name',
name: 'name',
type: 'text',
Expand Down

0 comments on commit b6e6522

Please sign in to comment.