@9of9solutions/replikator 1.0.16 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -65
- package/main.js +45 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,93 +1,74 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Replikator
|
|
2
2
|
|
|
3
|
+
Replikator is a command-line tool designed to share and synchronize code between multiple applications in a monorepo. It enables you to maintain shared code in a single source directory and automatically replicate it to multiple target applications, keeping everything in sync.
|
|
3
4
|
|
|
5
|
+
## Features
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
- **Code Sharing**: Maintain shared TypeScript/JavaScript code in one location and replicate it to multiple applications.
|
|
8
|
+
- **Real-time Synchronization**: Automatically sync changes to shared code across all target applications.
|
|
9
|
+
- **File Watching**: Continuously monitor source files and instantly propagate changes to all targets.
|
|
10
|
+
- **Selective Inclusion**: Specify which directories and files should be replicated to each target application.
|
|
11
|
+
- **Read-only Protection**: Replicated files are marked as read-only with clear headers indicating their source.
|
|
12
|
+
- **Monorepo Support**: Works seamlessly with monorepos and includes special support for Turborepo.
|
|
6
13
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
10
|
-
|
|
11
|
-
## Add your files
|
|
14
|
+
## Installation
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
|
16
|
+
To install Replikator, ensure you have Node.js installed, then run:
|
|
15
17
|
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g @9of9solutions/replikator
|
|
16
20
|
```
|
|
17
|
-
cd existing_repo
|
|
18
|
-
git remote add origin https://gitlab.com/9-of-9-solutions/replikator.git
|
|
19
|
-
git branch -M main
|
|
20
|
-
git push -uf origin main
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Integrate with your tools
|
|
24
|
-
|
|
25
|
-
- [ ] [Set up project integrations](https://gitlab.com/9-of-9-solutions/replikator/-/settings/integrations)
|
|
26
|
-
|
|
27
|
-
## Collaborate with your team
|
|
28
|
-
|
|
29
|
-
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
|
30
|
-
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
31
|
-
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
32
|
-
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
33
|
-
- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
|
|
34
|
-
|
|
35
|
-
## Test and Deploy
|
|
36
21
|
|
|
37
|
-
|
|
22
|
+
## Usage
|
|
38
23
|
|
|
39
|
-
|
|
40
|
-
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
|
41
|
-
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
42
|
-
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
43
|
-
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
24
|
+
Replikator provides the following commands:
|
|
44
25
|
|
|
45
|
-
|
|
26
|
+
- **rpk init**: Initialize Replikator configuration for your project.
|
|
27
|
+
- **rpk run**: Start the file watcher and synchronization process.
|
|
28
|
+
- **rpk include**: Specify which directories should be included in the replication.
|
|
29
|
+
- **rpk update**: Update the Replikator tool.
|
|
46
30
|
|
|
47
|
-
|
|
31
|
+
To set up Replikator:
|
|
48
32
|
|
|
49
|
-
|
|
33
|
+
```bash
|
|
34
|
+
# Initialize configuration
|
|
35
|
+
rpk init
|
|
50
36
|
|
|
51
|
-
|
|
37
|
+
# Select files to include
|
|
38
|
+
rpk include
|
|
52
39
|
|
|
53
|
-
|
|
40
|
+
# Start synchronization
|
|
41
|
+
rpk run
|
|
42
|
+
```
|
|
54
43
|
|
|
55
|
-
##
|
|
56
|
-
Choose a self-explaining name for your project.
|
|
44
|
+
## Development
|
|
57
45
|
|
|
58
|
-
|
|
59
|
-
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
46
|
+
For development purposes, you can use the following script in target applications:
|
|
60
47
|
|
|
61
|
-
|
|
62
|
-
|
|
48
|
+
```bash
|
|
49
|
+
npm run dev
|
|
50
|
+
```
|
|
63
51
|
|
|
64
|
-
|
|
65
|
-
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
52
|
+
This will navigate to the parent directory and execute the `rpk run` command.
|
|
66
53
|
|
|
67
|
-
##
|
|
68
|
-
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
54
|
+
## Dependencies
|
|
69
55
|
|
|
70
|
-
|
|
71
|
-
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
56
|
+
Replikator relies on several key dependencies:
|
|
72
57
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
58
|
+
- **commander**: For command-line interfaces.
|
|
59
|
+
- **chokidar**: For file watching and event handling.
|
|
60
|
+
- **fs-extra**: For enhanced file system operations.
|
|
61
|
+
- **inquirer**: For interactive command-line prompts.
|
|
78
62
|
|
|
79
63
|
## Contributing
|
|
80
|
-
State if you are open to contributions and what your requirements are for accepting them.
|
|
81
64
|
|
|
82
|
-
|
|
65
|
+
Contributions are welcome! Please fork the repository and submit a pull request for any improvements or bug fixes.
|
|
66
|
+
|
|
67
|
+
## License
|
|
83
68
|
|
|
84
|
-
|
|
69
|
+
This project is licensed under the ISC License.
|
|
85
70
|
|
|
86
|
-
##
|
|
87
|
-
Show your appreciation to those who have contributed to the project.
|
|
71
|
+
## Author
|
|
88
72
|
|
|
89
|
-
|
|
90
|
-
For open source projects, say how it is licensed.
|
|
73
|
+
Germain LESPINGAL
|
|
91
74
|
|
|
92
|
-
## Project status
|
|
93
|
-
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
package/main.js
CHANGED
|
@@ -77,17 +77,17 @@ async function findApplications(root) {
|
|
|
77
77
|
/**
|
|
78
78
|
* Loads the config if it exists, or creates it via prompt.
|
|
79
79
|
* The stored config contains paths relative to process.cwd().
|
|
80
|
-
* Returns an object { src, targets,
|
|
80
|
+
* Returns an object { src, targets, include } where src/targets are absolute paths.
|
|
81
81
|
*/
|
|
82
82
|
async function loadConfigOrPrompt(prompt) {
|
|
83
83
|
if (await fs.pathExists(PACKAGE_JSON_ROOT_PATH)) {
|
|
84
84
|
if (!prompt) {
|
|
85
85
|
const raw = await fs.readJson(PACKAGE_JSON_ROOT_PATH);
|
|
86
|
-
if (raw.replikator && raw.replikator.src && raw.replikator.targets && raw.replikator.
|
|
86
|
+
if (raw.replikator && raw.replikator.src && raw.replikator.targets && raw.replikator.include) {
|
|
87
87
|
return {
|
|
88
88
|
src: path.resolve(projectRoot, raw.replikator.src),
|
|
89
89
|
targets: raw.replikator.targets.map(rel => path.resolve(projectRoot, rel)),
|
|
90
|
-
|
|
90
|
+
include: raw.replikator.include
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -203,11 +203,11 @@ async function loadConfigOrPrompt(prompt) {
|
|
|
203
203
|
|
|
204
204
|
|
|
205
205
|
const package_json = await fs.readJson(PACKAGE_JSON_ROOT_PATH);
|
|
206
|
-
const config = { ...package_json, replikator: { src: relSrc, targets: relTargets,
|
|
206
|
+
const config = { ...package_json, replikator: { src: relSrc, targets: relTargets, include: {} } };
|
|
207
207
|
await fs.writeJson(PACKAGE_JSON_ROOT_PATH, config, { spaces: 2 });
|
|
208
208
|
console.log(`Configuration saved in ${path.relative(projectRoot, PACKAGE_JSON_ROOT_PATH)}`);
|
|
209
209
|
|
|
210
|
-
return { src: absSrc, targets: absTargets,
|
|
210
|
+
return { src: absSrc, targets: absTargets, include: [] };
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
/**
|
|
@@ -215,23 +215,24 @@ async function loadConfigOrPrompt(prompt) {
|
|
|
215
215
|
* @param {*} prompt - Should init config or no
|
|
216
216
|
*/
|
|
217
217
|
async function run(prompt) {
|
|
218
|
-
const { src, targets,
|
|
218
|
+
const { src, targets, include } = await loadConfigOrPrompt(prompt);
|
|
219
219
|
await Promise.all(
|
|
220
220
|
targets.map(async dest => {
|
|
221
221
|
await fs.remove(dest)
|
|
222
222
|
await fs.ensureDir(dest);
|
|
223
223
|
const relDest = path.relative(projectRoot, dest);
|
|
224
|
-
const patterns =
|
|
224
|
+
const patterns = include?.[relDest] || [];
|
|
225
225
|
|
|
226
226
|
const filterFn = srcFile => {
|
|
227
|
-
const rel = path.relative(src, srcFile)
|
|
228
|
-
|
|
227
|
+
const rel = path.relative(src, srcFile);
|
|
228
|
+
console.log(rel)
|
|
229
|
+
return patterns.filter(p => rel.startsWith(p)).length > 0;
|
|
229
230
|
};
|
|
230
231
|
|
|
231
232
|
console.log(dest)
|
|
232
233
|
await fs.copy(src, dest, { overwrite: true, filter: filterFn });
|
|
233
234
|
|
|
234
|
-
if ((await fs.lstat(src)).isFile()) {
|
|
235
|
+
if ((await fs.lstat(src)).isFile() && !src.endsWith('.svg') && !src.endsWith('.png') && !src.endsWith('.jpg') && !src.endsWith('.jpeg') && !src.endsWith('.gif')) {
|
|
235
236
|
const data = await fs.readFile(src);
|
|
236
237
|
const fd = await fs.open(dest, 'w+');
|
|
237
238
|
const header = Buffer.from(await getReplicatedFileHeader(src));
|
|
@@ -246,9 +247,9 @@ async function run(prompt) {
|
|
|
246
247
|
|
|
247
248
|
const watcher = chokidar.watch(src, { persistent: true });
|
|
248
249
|
watcher
|
|
249
|
-
.on('add', p => syncFile('add', p, src, targets,
|
|
250
|
-
.on('change', p => syncFile('change', p, src, targets,
|
|
251
|
-
.on('unlink', p => syncFile('unlink', p, src, targets,
|
|
250
|
+
.on('add', p => syncFile('add', p, src, targets, include))
|
|
251
|
+
.on('change', p => syncFile('change', p, src, targets, include))
|
|
252
|
+
.on('unlink', p => syncFile('unlink', p, src, targets, include))
|
|
252
253
|
.on('error', e => console.error('Watcher error:', e));
|
|
253
254
|
}
|
|
254
255
|
|
|
@@ -264,7 +265,7 @@ async function showInfo() {
|
|
|
264
265
|
console.log(" init Command used to init replikator configuration.");
|
|
265
266
|
console.log(" run Command used to run replikator.");
|
|
266
267
|
console.log(" update Command used to update replikator.");
|
|
267
|
-
console.log("
|
|
268
|
+
console.log(" include Command used to include files for selected apps.");
|
|
268
269
|
process.exit(0);
|
|
269
270
|
}
|
|
270
271
|
|
|
@@ -283,8 +284,8 @@ async function main() {
|
|
|
283
284
|
case "update":
|
|
284
285
|
await updateRpk();
|
|
285
286
|
break;
|
|
286
|
-
case "
|
|
287
|
-
await
|
|
287
|
+
case "include":
|
|
288
|
+
await includeRpk();
|
|
288
289
|
break;
|
|
289
290
|
default:
|
|
290
291
|
await showInfo();
|
|
@@ -306,7 +307,7 @@ async function updateRpk() {
|
|
|
306
307
|
|
|
307
308
|
if (ua.startsWith('pnpm')) {
|
|
308
309
|
cmd = 'pnpm';
|
|
309
|
-
args = ['add', '-g', '@9of9solutions/replikator@latest'];
|
|
310
|
+
args = ['add', '-g', '@9of9solutions/replikator@latest', '-w'];
|
|
310
311
|
} else if (ua.startsWith('yarn')) {
|
|
311
312
|
cmd = 'yarn';
|
|
312
313
|
args = ['global', 'add', '@9of9solutions/replikator@latest'];
|
|
@@ -331,7 +332,7 @@ const red = txt => `\x1b[31m${txt}\x1b[0m`;
|
|
|
331
332
|
/**
|
|
332
333
|
* Syncs a file that was added/modified/deleted to all targets.
|
|
333
334
|
*/
|
|
334
|
-
async function syncFile(event, filePath, srcDir, targets,
|
|
335
|
+
async function syncFile(event, filePath, srcDir, targets, include) {
|
|
335
336
|
const rel = path.relative(srcDir, filePath);
|
|
336
337
|
await Promise.all(targets.map(async destRoot => {
|
|
337
338
|
const destPath = path.join(destRoot, rel);
|
|
@@ -339,8 +340,8 @@ async function syncFile(event, filePath, srcDir, targets, ignore) {
|
|
|
339
340
|
await fs.remove(destPath);
|
|
340
341
|
} else {
|
|
341
342
|
const relDest = path.relative(projectRoot, destRoot);
|
|
342
|
-
const patterns =
|
|
343
|
-
if (patterns.filter(p => (rel
|
|
343
|
+
const patterns = include?.[relDest] || [];
|
|
344
|
+
if (patterns.filter(p => (rel).startsWith(p)).length > 0) {
|
|
344
345
|
await fs.ensureDir(path.dirname(destPath));
|
|
345
346
|
await fs.copy(filePath, destPath, { overwrite: true });
|
|
346
347
|
if ((await fs.lstat(filePath)).isFile()) {
|
|
@@ -358,9 +359,9 @@ async function syncFile(event, filePath, srcDir, targets, ignore) {
|
|
|
358
359
|
}
|
|
359
360
|
|
|
360
361
|
/**
|
|
361
|
-
* Setup
|
|
362
|
+
* Setup included files or directories for apps
|
|
362
363
|
*/
|
|
363
|
-
async function
|
|
364
|
+
async function includeRpk() {
|
|
364
365
|
const rawPkg = await fs.readJson(PACKAGE_JSON_ROOT_PATH, 'utf8');
|
|
365
366
|
const cfg = rawPkg.replikator;
|
|
366
367
|
if (!cfg || !cfg.src || !Array.isArray(cfg.targets)) {
|
|
@@ -383,7 +384,7 @@ async function excludeRpk() {
|
|
|
383
384
|
const { selectedApps } = await inquirer.prompt([{
|
|
384
385
|
type: 'checkbox',
|
|
385
386
|
name: 'selectedApps',
|
|
386
|
-
message: 'Select applications on which to apply
|
|
387
|
+
message: 'Select applications on which to apply include:',
|
|
387
388
|
choices: choicesApps,
|
|
388
389
|
validate(ans) {
|
|
389
390
|
return ans.length > 0 ? true : 'You must choose at least one application.';
|
|
@@ -392,37 +393,43 @@ async function excludeRpk() {
|
|
|
392
393
|
|
|
393
394
|
async function walk(dir, base = '') {
|
|
394
395
|
const entries = [];
|
|
395
|
-
|
|
396
|
+
const children = await fs.readdir(dir, { withFileTypes: true });
|
|
397
|
+
|
|
398
|
+
const hasFile = children.some(c => c.isFile() && /\.(ts|tsx)$/.test(c.name));
|
|
399
|
+
if (hasFile && base !== '') {
|
|
400
|
+
entries.push(base);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
for (const ent of children) {
|
|
404
|
+
if (ent.isDirectory() && !ent.name.includes('node_modules')) {
|
|
396
405
|
const rel = path.join(base, ent.name);
|
|
397
406
|
const full = path.join(dir, ent.name);
|
|
398
|
-
entries.push(
|
|
399
|
-
|
|
400
|
-
entries.push(...await walk(full, rel));
|
|
401
|
-
}
|
|
407
|
+
entries.push(...await walk(full, rel));
|
|
408
|
+
}
|
|
402
409
|
}
|
|
410
|
+
|
|
403
411
|
return entries;
|
|
404
|
-
|
|
412
|
+
}
|
|
413
|
+
|
|
405
414
|
const allEntries = await walk(absSrc);
|
|
406
415
|
|
|
407
|
-
const {
|
|
416
|
+
const { toinclude } = await inquirer.prompt([{
|
|
408
417
|
type: 'checkbox',
|
|
409
|
-
name: '
|
|
410
|
-
message: 'Select
|
|
418
|
+
name: 'toinclude',
|
|
419
|
+
message: 'Select directories (relative to src) to include:',
|
|
411
420
|
choices: allEntries.map(rel => ({ name: rel, value: rel })),
|
|
412
421
|
validate(ans) {
|
|
413
|
-
return ans.length > 0 ? true : 'You must choose at least one entry to
|
|
422
|
+
return ans.length > 0 ? true : 'You must choose at least one entry to include.';
|
|
414
423
|
}
|
|
415
424
|
}]);
|
|
416
425
|
|
|
417
|
-
rawPkg.replikator.
|
|
426
|
+
rawPkg.replikator.include = rawPkg.replikator.include || {};
|
|
418
427
|
for (const absT of selectedApps) {
|
|
419
428
|
const relT = path.relative(projectRoot, absT);
|
|
420
|
-
rawPkg.replikator.
|
|
429
|
+
rawPkg.replikator.include[relT] = toinclude;
|
|
421
430
|
}
|
|
422
|
-
console.log(PACKAGE_JSON_ROOT_PATH)
|
|
423
|
-
console.log(rawPkg)
|
|
424
431
|
await fs.writeJson(PACKAGE_JSON_ROOT_PATH, rawPkg, { spaces: 2 });
|
|
425
|
-
console.log(green(`
|
|
432
|
+
console.log(green(`Inclusion config updated for ${selectedApps.length} app(s).`));
|
|
426
433
|
}
|
|
427
434
|
|
|
428
435
|
main().catch(err => {
|