Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function getChangedPackages (commitIsh = 'HEAD^1', allPackages) {
allPackages = allPackages || getPackages() // eslint-disable-line no-param-reassign
const result = runCommandSync('git', ['diff', commitIsh, '--name-only'], [], { stdio: 'pipe' }).stdout
const changedFiles = result.split('\n')
return allPackages
.filter((pkg) => {
const relativePath = path.relative('.', pkg.location) + path.sep
return changedFiles
.findIndex(changedFile => changedFile.startsWith(relativePath)) >= 0
})
}
const {
NPM_TOKEN,
NPM_EMAIL,
NPM_USERNAME
} = process.env
// Only write an npmrc file if these are defined, otherwise assume the system is properly configured
if (NPM_TOKEN) {
fs.writeFileSync(
path.resolve(process.cwd(), '.npmrc'),
`//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n${config.npm_scope}\nemail=${NPM_EMAIL}\nname=${NPM_USERNAME}`
)
}
try {
runCommandSync('npm', ['whoami'])
} catch (e) {
error(`Could not determine if NPM auth was successful: ${e}`)
}
}
exports.createNPMRCFile = createNPMRCFile
exports.commit = function () {
try {
runGitCommand(['commit', '--dry-run'])
} catch(err) {
error(err.stdout)
process.exit(1)
}
try {
runCommandSync('yarn', ['husky:pre-commit'])
} catch(err) {
error(err.stdout)
process.exit(1)
}
return runCommandSync('git-cz')
}
const openSandbox = ({ branch, remote, sourcePath }) => {
const repository = runCommandSync('git', ['config', '--get', `remote.${remote}.url`], [], { stdio: 'pipe' }).stdout
if (!repository) {
error('Could not find a git url corresponding to this project. In order to open with Codesandbox, your project should be hosted in a public GitHub repository.')
process.exit(1)
}
let parsedUrl = {}
try {
parsedUrl = parseGitUrl(repository)
} catch {
error(`Could not retrieve the information necessary to open in Codesandbox from the following git repository url: ${repository}.`)
process.exit(1)
}
const url = `${sandboxHost()}${sandboxUrl({
git: {
exports.publishGithubPages = function publishGithubPages (config = {
gh_pages_dir: '.',
gh_pages_branch: 'gh-pages'
}) {
if (!fs.existsSync(`${config.gh_pages_dir}`)) {
error(`GH pages directory doesn't exist! Do you need to build the documentation?`)
process.exit(1)
}
info(`📖 Deploying '${config.gh_pages_dir}' to Github pages...`)
info(`📖 Repository: ${GIT_REMOTE_URL}...`)
info(`📖 Branch: ${config.gh_pages_branch}...`)
runCommandSync('touch', [`${config.gh_pages_dir}/.nojekyll`])
if (config.gh_pages_cname) {
fs.writeFileSync(`${config.gh_pages_dir}/CNAME`, config.gh_pages_cname)
}
return new Promise((resolve, reject) => {
ghpages.publish(config.gh_pages_dir, {
branch: config.gh_pages_branch,
repo: GIT_REMOTE_URL,
user: {
name: GIT_USERNAME,
email: GIT_EMAIL
},
silent: true,
dotfiles: true
}, (err) => {
module.exports = ({ branch, remote, path: sourcePath, scope }) => {
if (!scope) {
openSandbox({ branch, remote, sourcePath })
} else {
const result = runCommandSync('lerna', ['list', '--json'], [], { stdio: 'pipe' }).stdout
const pkg = JSON.parse(result).find(({ name }) => name === scope)
if (!pkg) {
error(`No project found with the name ${scope}`)
process.exit(1)
}
const { location } = pkg
const appPath = path.relative(sourcePath, location)
openSandbox({
branch,
remote,
sourcePath: appPath
})
const executeAddMissingPackages = async ({ missingPackages, sourcePath }) => {
if (!missingPackages || missingPackages.length === 0) return
const reply = await confirm(
`After updating your imports, the following Instructure UI packages are being used in your project but are not listed in your dependencies:
${missingPackages.map(pkg => ` * ${pkg}`).join('\n')}
Would you like this script to add them to your project now? [y/n]
`
)
if (['Y', 'y', 'Yes', 'yes'].includes(reply.trim())) {
try {
runCommandSync('yarn', [
'add',
...missingPackages.map(pkg => `${pkg}@latest`),
'--cwd',
sourcePath
])
} catch (err) {
error(err)
}
}
}
async function installReact () {
const pkgInfo = JSON.parse(
runCommandSync('yarn', ['info', 'react', '--json'], [], { stdio: 'pipe' }).stdout
).data
const latest = pkgInfo['dist-tags'].latest
let version = `${argv[argv.indexOf('--install-react') + 1]}`.trim()
version = semver.coerce(version) || latest
info(`Version: ${version}`)
let originalResolutions, pkg
if ([15, 16].includes(semver.major(version))) {
pkg = getPackage()
originalResolutions = {...pkg.get('resolutions')}
pkg.set('resolutions', {
module.exports = function getPackages () {
const result = runCommandSync('lerna', ['list', '--json'], [], { stdio: 'pipe' }).stdout
const packageData = JSON.parse(result)
return packageData.map(({ location }) => getPackage({ cwd: location }))
}
const runGitCommand = exports.runGitCommand = function runGitCommand (args = []) {
const { stdout } = runCommandSync('git', args, [], { stdio: 'pipe' })
return stdout && stdout.trim()
}