Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
gavoja committed Jul 11, 2022
1 parent 5446c19 commit a8d5cc2
Show file tree
Hide file tree
Showing 9 changed files with 3,195 additions and 859 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [5.0.0]
# [5.0.0] - TBA

### Changed

- No more callbacks in JavaScript API. Asynchronous generators are used instead.
- No more callbacks in JavaScript API; asynchronous generators are used instead.
- The pipeline has been rewritten. Instead of interval-based approach, packages are now pushed after a delay since the last change.
- The `-i` (interval) argument becomes `-d` (delay).
- The `-d` (debug) argument becomes `-v` (verbose).
- The `-u` argument becomes `-q`.
- The `-u` argument becomes `-q`.
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ Options:
-t <target> URL to AEM instance; multiple can be set.
Default: http://admin:admin@localhost:4502
-w <path_to_watch> Watch over folder.
Default: .
Default: '.'
-p <path_to_push> Push specific file or folder.
-e <exclude_filter> Extended glob filter; multiple can be set.
Default:
**/jcr_root/*
**/@(.git|.svn|.hg|target)
**/@(.git|.svn|.hg|target)/**
-d <delay> Time to wait since the last change before push.
Default: undefined ms
Default: 300 ms
-q <packmgr_path> Package manager path.
Default: /crx/packmgr/service.jsp
-c Check if AEM is up and running before pushing.
Expand All @@ -58,17 +58,14 @@ Examples:
> aemsync -e **/*.orig -e **/test -e -e **/test/**
Just push, don't watch:
> aemsync -p /foo/bar/my-workspace/jcr_content/apps/my-app/components/my-component
Website:
https://github.com/gavoja/aemsync
```

JavaScript API
```JavaScript
import { aemsync, push } from 'aemsync'

// Interactive watch example.
(async () => {
(async function () {
const args = { workingDir }

for await (const result of aemsync(args)) {
Expand All @@ -77,7 +74,7 @@ import { aemsync, push } from 'aemsync'
})()

// Push example.
(async () => {
(async function () {
const args = { payload: [
'./foo/bar/my-workspace/jcr_content/apps/my-app/components/my-component',
'./foo/bar/my-workspace/jcr_content/apps/my-app/components/something-else'
Expand All @@ -97,7 +94,7 @@ const args = {
exclude: ['**/jcr_root/*', '**/@(.git|.svn|.hg|target)', '**/@(.git|.svn|.hg|target)/**'],
packmgrPath: '/crx/packmgr/service.jsp',
targets: ['http://admin:admin@localhost:4501'],
delay: 200,
delay: 300,
checkIfUp: false
}
```
Expand All @@ -111,7 +108,7 @@ Any changes inside `jcr_root` folders are detected and deployed to AEM instance(
* Any paths containing `.svn`, `.git`, `.hg` or `target` are ignored.
* The exclude filter can be overriden. Do note that this will remove the above rules completely and if required, they must be added manually.

Delay is the time to wait to pass since the last change before the package is created. In case of bulk changes (e.g. switching between code branches), creating a new package per file should be avoided and instead, all changes should be pushed in one go. Lowering the value decreases the delay for a single file change but may increase the delay for multiple file changes. If you are unsure, please leave the default.
Delai is the time to wait to pass since the last change before the package is created. In case of bulk changes (e.g. switching between code branches), creating a new package per file should be avoided and instead, all changes should be pushed in one go. Lowering the value decreases the delay for a single file change but may increase the delay for multiple file changes. If you are unsure, please leave the default.

### Caveats

Expand Down
3 changes: 0 additions & 3 deletions bin/aemsync

This file was deleted.

3 changes: 3 additions & 0 deletions bin/aemsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
import { main } from '../index.js'
main()
22 changes: 10 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
import FormData from 'form-data'
import fs from 'fs'
import minimist from 'minimist'
Expand All @@ -8,20 +9,17 @@ import xmlToJson from 'xml-to-json-stream'
import Channel from './src/channel.js'
import * as log from './src/log.js'
import Package from './src/package.js'
import ROOT from './src/root.js'

const VERSION = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')).version

console.log(VERSION)
const VERSION = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version
const DEFAULTS = {
checkIfUp: false,
delay: 200,
workingDir: '.',
exclude: ['**/jcr_root/*', '**/@(.git|.svn|.hg|target)', '**/@(.git|.svn|.hg|target)/**'],
packmgrPath: '/crx/packmgr/service.jsp',
postHandler: post,
targets: ['http://admin:admin@localhost:4502'],
verbose: false,
workingDir: '.'
delay: 300,
checkIfUp: false,
postHandler: post,
verbose: false
}

const HELP = `
Expand Down Expand Up @@ -140,7 +138,7 @@ async function wait (ms) {
}

export async function * push (args) {
const { payload, exclude, targets, packmgrPath, checkIfUp, postHandler, delay, breakStuff } = { ...DEFAULTS, ...args }
const { payload, exclude, targets, packmgrPath, checkIfUp, postHandler, breakStuff } = { ...DEFAULTS, ...args }

// Get archive as many times as necessary.
let archive
Expand All @@ -158,7 +156,7 @@ export async function * push (args) {
archive = pack.save()
if (archive.err) {
log.debug(archive.err)
await wait(delay)
await wait(100)
log.info('Failed to create ZIP, retrying...')
} else {
break
Expand Down Expand Up @@ -249,7 +247,7 @@ function getArgs () {
}
}

async function main () {
export async function main () {
const args = getArgs()

// Show help.
Expand Down
Loading

0 comments on commit a8d5cc2

Please sign in to comment.