Skip to content

Commit

Permalink
Add script to symlink to local early-access repo
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesMGreene committed Nov 11, 2020
1 parent 287ee20 commit fc91756
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
/node_modules/
npm-debug.log
coverage/
/assets/images/early-access/
/content/early-access/
/data/early-access/
/assets/images/early-access
/content/early-access
/data/early-access

# blc: broken link checker
blc_output.log
Expand Down
78 changes: 78 additions & 0 deletions script/early-access/symlink-from-local-repo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env node

// [start-readme]
//
// This script is run on a writer's machine while developing Early Access content locally.
// You must pass the script the location of your local copy of
// the `github/docs-early-access` git repo as the first argument.
//
// [end-readme]

const { execSync } = require('child_process')
const rimraf = require('rimraf').sync
const fs = require('fs')
const path = require('path')

// Early Access details
const earlyAccessDirName = 'early-access'

if (!process.argv[2]) {
throw new Error('Must provide the location of your local `docs-early-access` repo directory')
}

const earlyAccessLocalRepoDir = path.resolve(process.cwd(), process.argv[2])

let dirStats
try {
dirStats = fs.statSync(earlyAccessLocalRepoDir)
} catch (err) {
dirStats = null
}

if (!dirStats) {
throw new Error('The local `docs-early-access` repo directory does not exist:', earlyAccessLocalRepoDir)
}
if (dirStats && !dirStats.isDirectory()) {
throw new Error('A non-directory entry exists at the local `docs-early-access` repo directory location:', earlyAccessLocalRepoDir)
}

const destinationDirNames = ['content', 'data', 'assets/images']
const destinationDirsMap = destinationDirNames
.reduce(
(map, dirName) => {
map[dirName] = path.join(process.cwd(), dirName, earlyAccessDirName)
return map
},
{}
)

// Remove all existing early access directories from this repo
destinationDirNames.forEach(key => rimraf(destinationDirsMap[key]))

// Move the latest early access source directories into this repo
destinationDirNames.forEach((dirName) => {
const sourceDir = path.join(earlyAccessLocalRepoDir, dirName)
const destDir = destinationDirsMap[dirName]

// If the source directory doesn't exist, skip it
if (!fs.existsSync(sourceDir)) {
console.warn(`Early access directory '${dirName}' does not exist. Skipping...`)
return
}

// Create a symbolic link to the directory
fs.symlinkSync(sourceDir, destDir, 'junction')

// Confirm the newly moved directory exist
if (!fs.existsSync(destDir)) {
throw new Error(`Failed to symlink early access directory '${dirName}'!`)
}
if (!fs.lstatSync(destDir).isSymbolicLink()) {
throw new Error(`The early access directory '${dirName}' entry is not a symbolic link!`)
}
if (!fs.statSync(destDir).isDirectory()) {
throw new Error(`The early access directory '${dirName}' entry's symbolic link does not refer to a directory!`)
}

console.log(`Successfully symlinked early access directory '${dirName}' into this repo`)
})

0 comments on commit fc91756

Please sign in to comment.