67 lines
1.3 KiB
JavaScript
Raw Normal View History

'use strict';
const { execSync } = require('child_process');
const execa = require('execa');
const logger = require('./logger');
/**
2021-11-23 16:58:16 +01:00
* @param {Object} options
* @param {string} options.path Path to directory (frontend, backend)
* @param {boolean} options.useYarn Use yarn instead of npm
*/
2021-11-23 16:58:16 +01:00
function runInstall({ path, useYarn }) {
if (useYarn) {
return execa('yarn', ['install'], {
cwd: path,
stdin: 'ignore',
});
}
return execa('npm', ['install'], { cwd: path, stdin: 'ignore' });
}
2021-11-23 16:58:16 +01:00
/**
* @param {Object} options
* @param {string} options.rootPath
* @param {boolean} options.useYarn
*/
function runApp({ rootPath, useYarn }) {
if (useYarn) {
return execa('yarn', ['develop'], {
stdio: 'inherit',
cwd: rootPath,
});
} else {
return execa('npm', ['run', 'develop'], {
stdio: 'inherit',
cwd: rootPath,
});
}
}
async function initGit(rootPath) {
try {
await execa('git', ['init'], {
cwd: rootPath,
});
} catch (err) {
logger.warn(`Could not initialize a git repository`);
}
try {
await execa(`git`, [`add`, `-A`], { cwd: rootPath });
execSync(`git commit -m "Create Strapi starter project"`, {
cwd: rootPath,
});
} catch (err) {
logger.warn(`Could not create initial git commit`);
}
}
module.exports = {
runInstall,
runApp,
initGit,
};