@joystick.js/cli-canary 0.0.0-canary.650 → 0.0.0-canary.652

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.
@@ -1,2 +1,2 @@
1
- import s from"fs";import o from"chalk";import c from"child_process";import n from"util";import t from"replace-in-files";import m from"./build_package_json.js";import l from"../../lib/cli_log.js";import u from"../../lib/loader.js";import p from"../../lib/node_path_polyfills.js";import i from"../../lib/get_platform_safe_path.js";const{cp:d,writeFile:y,mkdir:r}=s.promises,f=n.promisify(c.exec),$=(e="")=>y(`./${e}/package.json`,m(e)),j=async(e={},a={})=>{process.loader=new u,process.loader.print("Creating app..."),a?.release&&!["production","canary"].includes(a.release)&&(l("Must pass either production or canary for --release.",{level:"danger",docs:"https://docs.cheatcode.co/joystick/cli/create"}),process.exit(0)),await d(`${p?.__package}/commands/create/template`,`./${e.name}`,{recursive:!0}),await $(e.name),await r(`./${e?.name}/.joystick`,{recursive:!0}),await r(`./${e?.name}/fixtures`,{recursive:!0}),await r(`./${e?.name}/indexes`,{recursive:!0}),await r(`./${e?.name}/lib`,{recursive:!0}),await r(`./${e?.name}/private`,{recursive:!0}),await r(`./${e?.name}/queues`,{recursive:!0}),await r(`./${e?.name}/routes`,{recursive:!0}),await r(`./${e?.name}/uploaders`,{recursive:!0}),await r(`./${e?.name}/tests`,{recursive:!0}),await r(`./${e?.name}/websockets`,{recursive:!0}),a?.release==="canary"&&(await t({files:[i(`${process.cwd()}/${e?.name}/**/*.js`)],from:/(@joystick.js\/node)(?!-)/g,to:"@joystick.js/node-canary",optionsForFiles:{ignore:["**/node_modules/**"]}}),await t({files:[i(`${process.cwd()}/${e?.name}/**/*.js`)],from:/(@joystick.js\/ui)(?!-)/g,to:"@joystick.js/ui-canary",optionsForFiles:{ignore:["**/node_modules/**"]}})),setTimeout(async()=>{process.loader.print("Installing dependencies..."),await f(`cd ./${e?.name} && npm install --save @joystick.js/ui${a?.release==="canary"?"-canary":""}@latest @joystick.js/node${a?.release==="canary"?"-canary":""}@latest @joystick.js/test${a?.release==="canary"?"-canary":""}@latest`),console.log(`${o.green("Project created! To get started, run:")}
2
- cd ${e?.name} && joystick${a?.release==="canary"?"-canary":""} start`)},1e3)};var q=j;export{q as default};
1
+ import c from"fs";import i from"chalk";import s from"child_process";import o from"util";import n from"./build_package_json.js";import l from"../../lib/cli_log.js";import m from"../../lib/loader.js";import u from"../../lib/node_path_polyfills.js";import t from"../../lib/replace_in_files.js";const{cp:p,writeFile:d,mkdir:a}=c.promises,y=o.promisify(s.exec),$=(e="")=>d(`./${e}/package.json`,n(e)),j=async(e={},r={})=>{process.loader=new m,process.loader.print("Creating app..."),r?.release&&!["production","canary"].includes(r.release)&&(l("Must pass either production or canary for --release.",{level:"danger",docs:"https://docs.cheatcode.co/joystick/cli/create"}),process.exit(0)),await p(`${u?.__package}/commands/create/template`,`./${e.name}`,{recursive:!0}),await $(e.name),await a(`./${e?.name}/.joystick`,{recursive:!0}),await a(`./${e?.name}/fixtures`,{recursive:!0}),await a(`./${e?.name}/indexes`,{recursive:!0}),await a(`./${e?.name}/lib`,{recursive:!0}),await a(`./${e?.name}/private`,{recursive:!0}),await a(`./${e?.name}/queues`,{recursive:!0}),await a(`./${e?.name}/routes`,{recursive:!0}),await a(`./${e?.name}/uploaders`,{recursive:!0}),await a(`./${e?.name}/tests`,{recursive:!0}),await a(`./${e?.name}/websockets`,{recursive:!0}),r?.release==="canary"&&(await t(`${process.cwd()}/${e?.name}`,{match:[/\.js$/],exclude:[/node_modules/],replace_regex:/(@joystick.js\/node)(?!-)/g,replace_with:"@joystick.js/node-canary"}),await t(`${process.cwd()}/${e?.name}`,{match:[/\.js$/],exclude:[/node_modules/],replace_regex:/(@joystick.js\/ui)(?!-)/g,replace_with:"@joystick.js/ui-canary"})),setTimeout(async()=>{process.loader.print("Installing dependencies..."),await y(`cd ./${e?.name} && npm install --save @joystick.js/ui${r?.release==="canary"?"-canary":""}@latest @joystick.js/node${r?.release==="canary"?"-canary":""}@latest @joystick.js/test${r?.release==="canary"?"-canary":""}@latest`),console.log(`${i.green("Project created! To get started, run:")}
2
+ cd ${e?.name} && joystick${r?.release==="canary"?"-canary":""} start`)},1e3)};var q=j;export{q as default};
@@ -0,0 +1 @@
1
+ import f from"fs";const{readdir:u,readFile:s,writeFile:d}=f.promises,h=(a="",t={})=>u(a,{recursive:!0}).then(async n=>{let r=n;if(t?.exclude?.length)for(let e=0;e<t?.exclude?.length;e+=1){const l=t?.exclude[e];r=r?.filter(c=>!c.match(new RegExp(l)))}r=r.filter(e=>t?.match?.length?t?.match?.some(l=>e.match(new RegExp(l))):!0);for(let e=0;e<r?.length;e+=1){const l=r[e],c=`${a}/${l}`,i=(await s(c,"utf-8"))?.replace(new RegExp(t.replace_regex),t.replace_with);await d(c,i)}}).catch(n=>{console.warn(n)});var g=h;export{g as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@joystick.js/cli-canary",
3
3
  "type": "module",
4
- "version": "0.0.0-canary.650",
4
+ "version": "0.0.0-canary.652",
5
5
  "description": "The CLI for Joystick.",
6
6
  "main": "dist/index.js",
7
7
  "bin": {
@@ -30,7 +30,6 @@
30
30
  "node-fetch": "^3.3.2",
31
31
  "pg": "^8.11.3",
32
32
  "query-string": "^8.1.0",
33
- "replace-in-files": "^3.0.0",
34
33
  "ws": "^8.15.1"
35
34
  }
36
35
  }
@@ -2,12 +2,11 @@ import fs from 'fs';
2
2
  import chalk from 'chalk';
3
3
  import child_process from 'child_process';
4
4
  import util from 'util';
5
- import replace_in_files from 'replace-in-files';
6
5
  import build_package_json from "./build_package_json.js";
7
6
  import cli_log from '../../lib/cli_log.js';
8
7
  import Loader from "../../lib/loader.js";
9
8
  import node_path_polyfills from '../../lib/node_path_polyfills.js';
10
- import get_platform_safe_path from '../../lib/get_platform_safe_path.js';
9
+ import replace_in_files from '../../lib/replace_in_files.js';
11
10
 
12
11
  const { cp: copy_directory, writeFile, mkdir } = fs.promises;
13
12
  const exec = util.promisify(child_process.exec);
@@ -43,26 +42,18 @@ const create = async (args = {}, options = {}) => {
43
42
  await mkdir(`./${args?.name}/websockets`, { recursive: true });
44
43
 
45
44
  if (options?.release === 'canary') {
46
- await replace_in_files({
47
- files: [get_platform_safe_path(`${process.cwd()}/${args?.name}/**/*.js`)],
48
- from: /(@joystick.js\/node)(?!-)/g,
49
- to: '@joystick.js/node-canary',
50
- optionsForFiles: {
51
- "ignore": [
52
- "**/node_modules/**"
53
- ]
54
- }
45
+ await replace_in_files(`${process.cwd()}/${args?.name}`, {
46
+ match: [/\.js$/],
47
+ exclude: [/node_modules/],
48
+ replace_regex: /(@joystick.js\/node)(?!-)/g,
49
+ replace_with: '@joystick.js/node-canary',
55
50
  });
56
-
57
- await replace_in_files({
58
- files: [get_platform_safe_path(`${process.cwd()}/${args?.name}/**/*.js`)],
59
- from: /(@joystick.js\/ui)(?!-)/g,
60
- to: '@joystick.js/ui-canary',
61
- optionsForFiles: {
62
- "ignore": [
63
- "**/node_modules/**"
64
- ]
65
- }
51
+
52
+ await replace_in_files(`${process.cwd()}/${args?.name}`, {
53
+ match: [/\.js$/],
54
+ exclude: [/node_modules/],
55
+ replace_regex: /(@joystick.js\/ui)(?!-)/g,
56
+ replace_with: '@joystick.js/ui-canary',
66
57
  });
67
58
  }
68
59
 
@@ -0,0 +1,40 @@
1
+ import fs from 'fs';
2
+
3
+ const { readdir, readFile, writeFile } = fs.promises;
4
+
5
+ const replace_in_files = (root_path = '', options = {}) => {
6
+ return readdir(root_path, { recursive: true }).then(async (files) => {
7
+ let filtered_files = files;
8
+
9
+ if (options?.exclude?.length) {
10
+ for (let i = 0; i < options?.exclude?.length; i += 1) {
11
+ const exclude_regex = options?.exclude[i];
12
+ filtered_files = filtered_files?.filter((file) => {
13
+ return !file.match(new RegExp(exclude_regex));
14
+ });
15
+ }
16
+ }
17
+
18
+ filtered_files = filtered_files.filter((file) => {
19
+ return options?.match?.length ? options?.match?.some((match_regex) => {
20
+ return file.match(new RegExp(match_regex));
21
+ }) : true;
22
+ });
23
+
24
+ for (let i = 0; i < filtered_files?.length; i += 1) {
25
+ const file = filtered_files[i];
26
+ const file_path = `${root_path}/${file}`;
27
+ const file_contents = await readFile(file_path, 'utf-8');
28
+ const updated_file_contents = file_contents?.replace(
29
+ new RegExp(options.replace_regex),
30
+ options.replace_with
31
+ );
32
+
33
+ await writeFile(file_path, updated_file_contents);
34
+ }
35
+ }).catch((error) => {
36
+ console.warn(error);
37
+ });
38
+ };
39
+
40
+ export default replace_in_files;