create-strapi-app
Version:
Generate a new Strapi application.
72 lines (69 loc) • 1.54 kB
JavaScript
import execa from 'execa';
async function isInGitRepository(rootDir) {
try {
await execa('git', [
'rev-parse',
'--is-inside-work-tree'
], {
stdio: 'ignore',
cwd: rootDir
});
return true;
} catch (_) {
return false;
}
}
async function isInMercurialRepository(rootDir) {
try {
await execa('hg', [
'-cwd',
'.',
'root'
], {
stdio: 'ignore',
cwd: rootDir
});
return true;
} catch (_) {
return false;
}
}
async function tryGitInit(rootDir) {
try {
await execa('git', [
'--version'
], {
stdio: 'ignore'
});
if (await isInGitRepository(rootDir) || await isInMercurialRepository(rootDir)) {
return false;
}
await execa('git', [
'init'
], {
stdio: 'ignore',
cwd: rootDir
});
await execa('git', [
'add',
'.'
], {
stdio: 'ignore',
cwd: rootDir
});
await execa('git', [
'commit',
'-m',
'Initial commit from Strapi'
], {
stdio: 'ignore',
cwd: rootDir
});
return true;
} catch (e) {
console.error('Error while trying to initialize git:', e);
return false;
}
}
export { tryGitInit };
//# sourceMappingURL=git.mjs.map