Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

docarchive

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docarchive - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

204

index.js

@@ -1,14 +0,28 @@

const readPkg = require('read-pkg')
const execa = require('execa')
const curry = require('lodash.curry')
const readPkg = require('read-pkg')
const tmp = require('tmp')
const cpy = require('cpy')
const del = require('del')
const path = require('path')
const pify = require('pify')
const pMap = require('p-map')
const pFilter = require('p-filter')
const fs = pify(require('fs'))
const mkdirp = pify(require('mkdirp'))
// const Observable = require('zen-observable')
const catchAndThrow = curry(function _catchAndThrow (ob, res) {
debugger
ob.error(res.stderr || res)
})
function readConf (ctx, ob) {
ob.next('Reading package')
const package = readPkg.sync()
const pkg = readPkg.sync()
ob.next('Checking configuration')
ctx.version = package.version
ctx.version = pkg.version
ctx.state = {}
const conf = package.docarchive
const conf = pkg.docarchive
// TODO check properties

@@ -22,4 +36,4 @@ Object.assign(ctx, conf)

ob.next(`Fetching heads at ${ctx.remote}`)
const a = execa('git', ['ls-remote', '--heads', ctx.remote])
execa('git', ['ls-remote', '--heads', ctx.remote])
execa('git', ['ls-remote', '--heads', ctx.remote])
.then(res => {

@@ -32,10 +46,186 @@ ob.next(`Checking if branch '${ctx.branch}' exists`)

})
.catch(catchAndThrow(ob))
}
function fetchRemote (ctx, ob) {
if (ctx.localRepo) {
ob.next(`Using ${ctx.localRepo} to fetch the remote`)
const name = ctx.localRepo
ctx.localRepo = {
name,
removeCallback () {
throw new Error('TODO')
}
}
ob.next(`Checking if ${ctx.localRepo.name} is clean`)
const projectDir = process.cwd()
process.chdir(ctx.localRepo.name)
// TODO create branch if it doesn't exist
execa('git', ['checkout', ctx.branch])
.then(() => execa('git', ['pull']))
.then(() => {
process.chdir(projectDir)
ob.complete()
})
.catch(res => {
process.chdir(projectDir)
catchAndThrow(ob, res)
})
} else {
ob.next('Creating tmp directory to fetch the remote')
ctx.localRepo = tmp.dirSync({ unsafeCleanup: true })
ctx.localRepo.clean = true
ob.next(`Cloning ${ctx.remote} to ${ctx.localRepo.name}`)
const args = ctx.state.branchExists
? ['clone', '-b', ctx.branch, ctx.remote, '--single-branch', '--depth', 1, ctx.localRepo.name]
: ['clone', ctx.remote, '--depth', 1, ctx.localRepo.name]
execa('git', args)
.then(() => ob.complete())
.catch(catchAndThrow(ob))
}
}
function createBranch (ctx, ob) {
const projectDir = process.cwd()
process.chdir(ctx.localRepo.name)
ob.next(`Creating an orphan branch ${ctx.branch}`)
execa('git', ['checkout', '--orphan', ctx.branch])
.then(() => {
return execa('git', ['reset', '--hard'])
})
.then(res => {
process.chdir(projectDir)
ob.complete()
})
.catch(res => {
throw new Error(res.stderr)
process.chdir(projectDir)
catchAndThrow(ob, res)
})
}
function copyRelease (ctx, ob) {
ctx.releaseDir = path.resolve(ctx.localRepo.name, ctx.version)
ob.next(`Creating ${ctx.releaseDir}`)
mkdirp(ctx.releaseDir)
.then(() => {
ob.next(`Copying ${ctx.distDir} to ${ctx.releaseDir}`)
return cpy(`${path.join(ctx.distDir, '*')}`, ctx.releaseDir)
})
.then(() => ob.complete())
.catch(catchAndThrow(ob))
}
function removeOldSymlinks (ctx, ob) {
// retrieve all symbolic links and delete them
fs.readdir(ctx.localRepo.name)
.then((files) => files.map((file) => path.resolve(ctx.localRepo.name, file)))
.then((files) => {
return pFilter(files, (file) => {
ob.next(`Checking ${file}`)
return fs.lstat(file).then(stats => stats.isSymbolicLink())
})
.then((files) => pMap(
files,
file => {
ob.next(`Deleting ${file}`)
return del(file, { force: true })
}
))
})
.then(() => ob.complete())
.catch(catchAndThrow(ob))
}
function generateVersionsJson (ctx, ob) {
const projectDir = process.cwd()
const versionMatcher = /[0-9](:?\.[0-9]){2}/
process.chdir(ctx.localRepo.name)
ob.next(`Creating ${ctx.currentReleaseDirname}`)
fs.readdir('.')
.then((files) => {
ob.next('Check', files)
return pFilter(files, (file) => (
fs.lstat(file).then(stats => stats.isDirectory())
))
})
.then((dirs) => dirs.filter((dir) => versionMatcher.test(dir)))
.then((versions) => fs.writeFile('versions.json', JSON.stringify(versions)))
.then(() => {
process.chdir(projectDir)
ob.complete()
})
.catch(err => {
process.chdir(projectDir)
catchAndThrow(ob, err)
})
}
function createSymlinks (ctx, ob) {
const projectDir = process.cwd()
process.chdir(ctx.localRepo.name)
ob.next(`Creating ${ctx.currentReleaseDirname}`)
fs.symlink(ctx.version, ctx.currentReleaseDirname)
.catch(err => {
process.chdir(projectDir)
catchAndThrow(ob, err)
})
fs.readdir(ctx.releaseDir)
.then((files) => pMap(
files,
(file) => {
ob.next(`Linking ${file}`)
return fs.symlink(path.join(ctx.version, file), file)
}
)).then(() => {
process.chdir(projectDir)
ob.complete()
})
.catch(err => {
process.chdir(projectDir)
catchAndThrow(ob, err)
})
}
function publish (ctx, ob) {
const projectDir = process.cwd()
process.chdir(ctx.localRepo.name)
ob.next('Adding all files')
execa('git', ['add', '.'])
.then(() => {
ob.next('Committing')
return execa('git', ['commit', '-m', ctx.version])
})
.then(() => {
ob.next('Pushing')
return execa('git', ['push', 'origin', ctx.branch])
})
.then(() => {
process.chdir(projectDir)
ob.complete()
})
.catch(err => {
process.chdir(projectDir)
catchAndThrow(ob, err)
})
}
function cleanup (ctx, ob) {
if (ctx.localRepo.clean) {
ob.next(`Cleaning ${ctx.localRepo.name}`)
ctx.localRepo.removeCallback()
}
ob.complete()
}
module.exports = {
readConf: curry(readConf),
checkRemoteBranch: curry(checkRemoteBranch)
checkRemoteBranch: curry(checkRemoteBranch),
fetchRemote: curry(fetchRemote),
createBranch: curry(createBranch),
copyRelease: curry(copyRelease),
removeOldSymlinks: curry(removeOldSymlinks),
createSymlinks: curry(createSymlinks),
generateVersionsJson: curry(generateVersionsJson),
publish: curry(publish),
cleanup: curry(cleanup)
}

21

package.json
{
"name": "docarchive",
"version": "0.0.1",
"version": "0.1.0",
"description": "Manage different documentation versions and host them on Github",

@@ -8,17 +8,14 @@ "main": "index.js",

"license": "MIT",
"scripts": {
"test": "ava"
},
"devDependencies": {
"ava": "^0.17.0",
"observable-to-promise": "^0.4.0",
"proxyquire": "^1.7.10",
"sinon": "^1.17.6",
"zen-observable": "^0.4.0"
},
"dependencies": {
"cpy": "^5.0.0",
"del": "^2.2.2",
"execa": "^0.5.0",
"lodash.curry": "^4.1.1",
"read-pkg": "^2.0.0"
"mkdirp": "^0.5.1",
"p-filter": "^1.0.0",
"p-map": "^1.1.0",
"pify": "^2.3.0",
"read-pkg": "^2.0.0",
"tmp": "^0.0.31"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc