Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev_sync update to a Node Script #1297

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4e41461
Add watcher and rsync to dependancies
RailonA Aug 14, 2023
92b22a6
Need to double check if I even need the watcher dependancy, rsync sea…
RailonA Aug 14, 2023
7e6fa41
Need to double check if I even need the watcher dependancy, rsync sea…
RailonA Aug 14, 2023
a3b7f6f
Needed watcher to keep command running in the terminal, if not termin…
RailonA Aug 14, 2023
c321c60
Removed ^ from package.json
RailonA Aug 14, 2023
e554f05
Fix README.md
RailonA Aug 14, 2023
be3c29e
Cleaned dev_sync.js
RailonA Aug 14, 2023
3ffaba9
Cleaned dev_sync.js
RailonA Aug 14, 2023
d2bd188
Cleaned dev_sync.js
RailonA Aug 14, 2023
33a50cc
Cleaned dev_sync.js
RailonA Aug 14, 2023
a9e5b33
Watcher works, closses correctly when you press control + C
RailonA Aug 14, 2023
26dedad
Merge branch 'main' of https://github.com/rooseveltframework/roosevel…
RailonA Aug 21, 2023
05f808d
Script will copy and past any changes you have made to roosevelt befo…
RailonA Aug 21, 2023
5bd145e
Cleaned unwanted lines
RailonA Aug 21, 2023
ef2a2a5
Clean README.md
RailonA Aug 21, 2023
a0b2067
Still cleaning code.
RailonA Aug 21, 2023
7f49088
Add instructions to README.md for Windows
RailonA Aug 21, 2023
0630970
Add instructions to README.md for Windows
RailonA Aug 21, 2023
7f7119e
Fix linters.
RailonA Aug 21, 2023
092edea
Was able to have the script dev_sync.js run every 5 seconds after you…
RailonA Aug 22, 2023
d3ead21
Moved rsync and watcher into devDependencies
RailonA Aug 22, 2023
3a4b2d4
Watching all files in directory except the ones listed in gitignore
RailonA Aug 23, 2023
e1b2de2
Cleaning code a bit
RailonA Aug 23, 2023
4ebfd66
Fixed checking for what directy should be watched.
RailonA Aug 23, 2023
9894026
Watcher now focuses on the specific file that has been modified and w…
RailonA Aug 23, 2023
645a13f
Clean unwanted lines
RailonA Aug 23, 2023
3d36967
Prompt will keep looping unless user enters close or exit, watcher an…
RailonA Aug 24, 2023
f8bc171
Prompt is working as intended, watcher and rsync are working
RailonA Aug 24, 2023
1135c2a
Fixed .toLowerCase() to input when user wants to close dev_sync.js
RailonA Aug 24, 2023
cee9853
Removed unwanted lines
RailonA Aug 24, 2023
fdc17d8
Fixed control C error when closing
RailonA Aug 24, 2023
25f3388
To make code shorter I created a fsClose function
RailonA Aug 24, 2023
3d43309
Remove unwanted line
RailonA Aug 24, 2023
00a74b5
Remove unwanted line
RailonA Aug 24, 2023
a4d7022
Add watcher, node-rsync, node-glob and prompts to devDependencies
RailonA Aug 24, 2023
6bfa3f9
dev_sync.js fully working as intended.
RailonA Aug 24, 2023
859e5f9
Add some instructions to the README.md
RailonA Aug 24, 2023
414ebc0
Merge branch 'main' into dev_sync_Update
RailonA Nov 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1348,8 +1348,13 @@ Here's how to set up a dev env to hack on Roosevelt:
- Create or find a Roosevelt app you want to test against.
- To make a Roosevelt app, run `npx mkroosevelt`
- Your changes to Roosevelt need to be copied to your app's `node_modules/roosevelt` directory.
- If you do not want to sync these directories automatically, then run the `dev_sync.sh` script. To do that:
- If you do not want to sync these directories automatically, then run the `dev_sync.js` script. To do that:
- Install [fswatch](https://github.com/emcrisostomo/fswatch) and [rsync](https://en.wikipedia.org/wiki/Rsync) and ensure they are in your PATH.
- Set a `DEST_DIR` environment variable: `export DEST_DIR=/path/to/your/roosevelt/app`
- Run the script: `sh dev_sync.sh`
- Or in one command: `export DEST_DIR=/path/to/your/roosevelt/app && sh dev_sync.sh`
- Run the script: `node dev_sync.js`
RailonA marked this conversation as resolved.
Show resolved Hide resolved
- Or in one command: `export DEST_DIR=/path/to/your/roosevelt/app && node dev_sync.js`
- To end the script press: `control^ + C`
-For Windows
- Set a `DEST_DIR` environment variable: `$env:DEST_DIR="/path/to/your/roosevelt/app"`
- Run the script: `node dev_sync.js`
- To end the script press: `control^ + C`
72 changes: 72 additions & 0 deletions dev_sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const Logger = require('roosevelt-logger')
this.logger = new Logger()
const Rsync = require('rsync')
let DEST_DIR = process.env.DEST_DIR
const rsvtConfig = `${DEST_DIR}/rooseveltConfig.json`
DEST_DIR = `${DEST_DIR}/node_modules/`
const SRC_DIR = __dirname
const fs = require('fs')

try {
if (DEST_DIR === '' || DEST_DIR === undefined) {
this.logger.error('ERROR: DEST_DIR is an empty variable')
} else if (DEST_DIR === SRC_DIR) {
this.logger.error('ERROR: DEST_DIR is pointing to the same path as SRC_DIR ')
} else {
if (fs.existsSync(rsvtConfig) || fs.existsSync(`${DEST_DIR}/roosevelt/`)) {
this.logger.info('')
this.logger.info('💭')
this.logger.info('💭', 'We are in a Roosevelt app ...')
fsWatch()
} else {
this.logger.info('')
this.logger.warn('Make sure the above directories are correct or this could delete unwanted files!')
this.logger.info('💭', 'We are not in a Roosevelt app ...')
this.logger.info('')
}
}
} catch (err) { console.log(err) }

async function fsWatch () {
const Logger = require('roosevelt-logger')
this.logger = new Logger()
const watch = await import('watcher')
const Watcher = watch.default
const watcher = new Watcher(SRC_DIR)

const rsync = new Rsync()
.flags('avz')
.delete()
.exclude('.DS_Store')
.source(SRC_DIR)
.destination(DEST_DIR)

watcher.on('error', error => {
this.logger.err(error)
})
watcher.on('ready', () => {
this.logger.info('💭', 'Roosevelt fswatch rsync tool running...')
this.logger.info('')
this.logger.info('💭', `Now watching: ${SRC_DIR}`)
this.logger.info('💭', `Will copy to: ${DEST_DIR}`)
this.logger.info('')
})

setInterval(function () {
rsync.execute(function (error, code, cmd) {
if (error) {
this.logger.error(`ERROR: ${error.message}`)
}
})
}, 5000)
RailonA marked this conversation as resolved.
Show resolved Hide resolved

process.on('SIGINT', function () {
console.log('')
console.log('')
console.log('💭')
console.log('💭 Closing fswatch')
console.log('💭')
watcher.close()
process.exit()
})
}
16 changes: 0 additions & 16 deletions dev_sync.sh

This file was deleted.

32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
"page-express-mapper": "2.0.2",
"reload": "3.2.1",
"roosevelt-logger": "0.2.3",
"rsync": "0.6.1",
RailonA marked this conversation as resolved.
Show resolved Hide resolved
"selfsigned": "2.1.1",
"serve-favicon": "2.5.0",
"source-configs": "0.3.6",
"toobusy-js": "0.5.1",
"watcher": "2.3.0",
"webpack": "5.88.2"
},
"devDependencies": {
Expand Down