@prosopo/scripts 3.1.138 → 3.1.139

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,46 +1,37 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const node_child_process = require("node:child_process");
4
- const node_process = require("node:process");
5
- const exec = (command, options) => {
6
- let { pipe, printCmd } = options || {};
7
- pipe = pipe === void 0 || pipe;
8
- printCmd = printCmd === void 0 || printCmd;
9
- if (printCmd) {
10
- console.log(`[exec] ${command}`);
11
- }
12
- const prc = node_child_process.spawn(command, {
13
- shell: true
14
- });
15
- if (pipe || pipe === void 0) {
16
- prc.stdout.pipe(process.stdout);
17
- prc.stderr.pipe(process.stderr);
18
- }
19
- node_process.stdin.pipe(prc.stdin);
20
- const stdoutData = [];
21
- const stderrData = [];
22
- prc.stdout.on("data", (data) => {
23
- stdoutData.push(data.toString());
24
- });
25
- prc.stderr.on("data", (data) => {
26
- stderrData.push(data.toString());
27
- });
28
- return new Promise((resolve, reject) => {
29
- prc.on("close", (code) => {
30
- if (pipe || pipe === void 0) {
31
- console.log("");
32
- }
33
- const output = {
34
- stdout: stdoutData.join(""),
35
- stderr: stderrData.join(""),
36
- code
37
- };
38
- if (code === 0) {
39
- resolve(output);
40
- } else {
41
- reject(output);
42
- }
43
- });
44
- });
1
+ let node_child_process = require("node:child_process");
2
+ let node_process = require("node:process");
3
+ //#region src/util/exec.ts
4
+ var exec = (command, options) => {
5
+ let { pipe, printCmd } = options || {};
6
+ pipe = pipe === void 0 || pipe;
7
+ printCmd = printCmd === void 0 || printCmd;
8
+ if (printCmd) console.log(`[exec] ${command}`);
9
+ const prc = (0, node_child_process.spawn)(command, { shell: true });
10
+ if (pipe || pipe === void 0) {
11
+ prc.stdout.pipe(process.stdout);
12
+ prc.stderr.pipe(process.stderr);
13
+ }
14
+ node_process.stdin.pipe(prc.stdin);
15
+ const stdoutData = [];
16
+ const stderrData = [];
17
+ prc.stdout.on("data", (data) => {
18
+ stdoutData.push(data.toString());
19
+ });
20
+ prc.stderr.on("data", (data) => {
21
+ stderrData.push(data.toString());
22
+ });
23
+ return new Promise((resolve, reject) => {
24
+ prc.on("close", (code) => {
25
+ if (pipe || pipe === void 0) console.log("");
26
+ const output = {
27
+ stdout: stdoutData.join(""),
28
+ stderr: stderrData.join(""),
29
+ code
30
+ };
31
+ if (code === 0) resolve(output);
32
+ else reject(output);
33
+ });
34
+ });
45
35
  };
36
+ //#endregion
46
37
  exports.exec = exec;
@@ -1,18 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
1
+ //#region src/util/fluxLogDappDetails.ts
3
2
  function extractReferrersFromLogs(logsText) {
4
- const urls = [
5
- ...logsText.split("\n").reduce((accumulator, line) => {
6
- const matches = line.match(/"(https?:\/\/[^"]+)"/g);
7
- if (matches) {
8
- for (const match of matches) {
9
- const url = match.substring(1, match.length - 1);
10
- accumulator.add(url);
11
- }
12
- }
13
- return accumulator;
14
- }, /* @__PURE__ */ new Set())
15
- ];
16
- return urls.join(" ");
3
+ return [...logsText.split("\n").reduce((accumulator, line) => {
4
+ const matches = line.match(/"(https?:\/\/[^"]+)"/g);
5
+ if (matches) for (const match of matches) {
6
+ const url = match.substring(1, match.length - 1);
7
+ accumulator.add(url);
8
+ }
9
+ return accumulator;
10
+ }, /* @__PURE__ */ new Set())].join(" ");
17
11
  }
12
+ //#endregion
18
13
  exports.extractReferrersFromLogs = extractReferrersFromLogs;
@@ -1,10 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const updateEnv = require("./updateEnv.cjs");
4
- const exec = require("./exec.cjs");
5
- const fluxLogDappDetails = require("./fluxLogDappDetails.cjs");
6
- exports.findEnvFiles = updateEnv.findEnvFiles;
7
- exports.updateDemoHTMLFiles = updateEnv.updateDemoHTMLFiles;
8
- exports.updateEnvFiles = updateEnv.updateEnvFiles;
9
- exports.exec = exec.exec;
10
- exports.extractReferrersFromLogs = fluxLogDappDetails.extractReferrersFromLogs;
1
+ const require_updateEnv = require("./updateEnv.cjs");
2
+ const require_exec = require("./exec.cjs");
3
+ const require_fluxLogDappDetails = require("./fluxLogDappDetails.cjs");
4
+ exports.exec = require_exec.exec;
5
+ exports.extractReferrersFromLogs = require_fluxLogDappDetails.extractReferrersFromLogs;
6
+ exports.findEnvFiles = require_updateEnv.findEnvFiles;
7
+ exports.updateDemoHTMLFiles = require_updateEnv.updateDemoHTMLFiles;
8
+ exports.updateEnvFiles = require_updateEnv.updateEnvFiles;
@@ -1,71 +1,71 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const fs = require("node:fs");
4
- const path = require("node:path");
5
- const dotenv = require("@prosopo/dotenv");
6
- const util = require("@prosopo/util");
7
- const dotenv$1 = require("dotenv");
8
- const fg = require("fast-glob");
9
- const ignore = [
10
- "**/node_modules/**",
11
- "node_modules/**",
12
- "../../**/node_modules/**",
13
- "../node_modules/**",
14
- "../../node_modules/**"
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
+ let node_path = require("node:path");
3
+ node_path = require_runtime.__toESM(node_path, 1);
4
+ let _prosopo_dotenv = require("@prosopo/dotenv");
5
+ let _prosopo_util = require("@prosopo/util");
6
+ let node_fs = require("node:fs");
7
+ node_fs = require_runtime.__toESM(node_fs, 1);
8
+ let dotenv = require("dotenv");
9
+ dotenv = require_runtime.__toESM(dotenv, 1);
10
+ let fast_glob = require("fast-glob");
11
+ fast_glob = require_runtime.__toESM(fast_glob, 1);
12
+ //#region src/util/updateEnv.ts
13
+ var ignore = [
14
+ "**/node_modules/**",
15
+ "node_modules/**",
16
+ "../../**/node_modules/**",
17
+ "../node_modules/**",
18
+ "../../node_modules/**"
15
19
  ];
16
- const __dirname$1 = path.resolve();
20
+ var __dirname$1 = node_path.default.resolve();
17
21
  async function findEnvFiles(logger, cwd) {
18
- const env = dotenv.getEnv();
19
- const fileName = `.env.${env}`;
20
- logger.info(() => ({ msg: "Searching for files" }));
21
- return await fg(`${cwd || "../.."}/**/${fileName}`, {
22
- ignore
23
- });
22
+ const fileName = `.env.${(0, _prosopo_dotenv.getEnv)()}`;
23
+ logger.info(() => ({ msg: "Searching for files" }));
24
+ return await (0, fast_glob.default)(`${cwd || "../.."}/**/${fileName}`, { ignore });
24
25
  }
25
26
  async function updateDemoHTMLFiles(varMatchers, varValue, logger) {
26
- const files = await fg("../../demos/**/*.html", {
27
- ignore
28
- });
29
- logger.info(() => ({ data: { files }, msg: "HTML files found" }));
30
- files.forEach((file) => {
31
- const filePath = path.resolve(process.cwd(), file);
32
- const contents = fs.readFileSync(filePath).toString();
33
- let newContents = contents;
34
- for (const varMatcher of varMatchers) {
35
- const matches = contents.match(varMatcher);
36
- if (matches) {
37
- const matchedVar = util.at(matches, 1);
38
- logger.info(() => ({ data: { matchedVar }, msg: "matchedVar" }));
39
- newContents = contents.replaceAll(matchedVar, varValue);
40
- break;
41
- }
42
- }
43
- if (newContents !== contents) {
44
- fs.writeFileSync(path.resolve(__dirname$1, filePath), newContents);
45
- }
46
- });
27
+ const files = await (0, fast_glob.default)("../../demos/**/*.html", { ignore });
28
+ logger.info(() => ({
29
+ data: { files },
30
+ msg: "HTML files found"
31
+ }));
32
+ files.forEach((file) => {
33
+ const filePath = node_path.default.resolve(process.cwd(), file);
34
+ const contents = node_fs.default.readFileSync(filePath).toString();
35
+ let newContents = contents;
36
+ for (const varMatcher of varMatchers) {
37
+ const matches = contents.match(varMatcher);
38
+ if (matches) {
39
+ const matchedVar = (0, _prosopo_util.at)(matches, 1);
40
+ logger.info(() => ({
41
+ data: { matchedVar },
42
+ msg: "matchedVar"
43
+ }));
44
+ newContents = contents.replaceAll(matchedVar, varValue);
45
+ break;
46
+ }
47
+ }
48
+ if (newContents !== contents) node_fs.default.writeFileSync(node_path.default.resolve(__dirname$1, filePath), newContents);
49
+ });
47
50
  }
48
51
  async function updateEnvFiles(varNames, varValue, logger, cwd) {
49
- const files = await findEnvFiles(logger, cwd);
50
- logger.info(() => ({ data: { files }, msg: "Env files found" }));
51
- files.forEach((file) => {
52
- let write = false;
53
- const filePath = path.resolve(cwd || process.cwd(), file);
54
- const envConfig = dotenv$1.parse(fs.readFileSync(filePath));
55
- for (const varName of varNames) {
56
- if (varName in envConfig) {
57
- envConfig[varName] = varValue;
58
- write = true;
59
- }
60
- }
61
- if (write) {
62
- fs.writeFileSync(
63
- path.resolve(__dirname$1, filePath),
64
- Object.keys(envConfig).map((k) => `${k}=${envConfig[k]}`).join("\n")
65
- );
66
- }
67
- });
52
+ const files = await findEnvFiles(logger, cwd);
53
+ logger.info(() => ({
54
+ data: { files },
55
+ msg: "Env files found"
56
+ }));
57
+ files.forEach((file) => {
58
+ let write = false;
59
+ const filePath = node_path.default.resolve(cwd || process.cwd(), file);
60
+ const envConfig = dotenv.default.parse(node_fs.default.readFileSync(filePath));
61
+ for (const varName of varNames) if (varName in envConfig) {
62
+ envConfig[varName] = varValue;
63
+ write = true;
64
+ }
65
+ if (write) node_fs.default.writeFileSync(node_path.default.resolve(__dirname$1, filePath), Object.keys(envConfig).map((k) => `${k}=${envConfig[k]}`).join("\n"));
66
+ });
68
67
  }
68
+ //#endregion
69
69
  exports.findEnvFiles = findEnvFiles;
70
70
  exports.updateDemoHTMLFiles = updateDemoHTMLFiles;
71
71
  exports.updateEnvFiles = updateEnvFiles;
package/dist/cli/index.js CHANGED
@@ -1,89 +1,78 @@
1
+ import { exec } from "../util/exec.js";
2
+ import "../util/index.js";
3
+ import { setup } from "../setup/setup.js";
4
+ import "../setup/index.js";
5
+ import { getScriptsPkgDir } from "../workspace/dist/projectInfo.js";
6
+ import setVersion from "../scripts/setVersion.js";
1
7
  import path from "node:path";
2
- import { isHex } from "@polkadot/util";
3
- import { loadEnv, getEnv } from "@prosopo/dotenv";
8
+ import { getEnv, loadEnv } from "@prosopo/dotenv";
4
9
  import { LogLevel, getLogger, parseLogLevel } from "@prosopo/logger";
5
- import { encodeProcaptchaOutput, decodeProcaptchaOutput } from "@prosopo/types";
6
- import "../workspace/dist/index.js";
10
+ import { decodeProcaptchaOutput, encodeProcaptchaOutput } from "@prosopo/types";
11
+ import { isHex } from "@polkadot/util";
7
12
  import yargs from "yargs";
8
13
  import { hideBin } from "yargs/helpers";
9
- import setVersion from "../scripts/setVersion.js";
10
- import "../setup/index.js";
11
- import "../util/index.js";
12
- import { getScriptsPkgDir } from "../workspace/dist/projectInfo.js";
13
- import { exec } from "../util/exec.js";
14
- import { setup } from "../setup/setup.js";
15
- const rootDir = path.resolve(".");
16
- loadEnv(rootDir);
14
+ loadEnv(path.resolve("."));
17
15
  async function processArgs(args) {
18
- const parsed = await yargs(hideBin(args)).option("logLevel", {
19
- describe: "set log level",
20
- choices: Object.keys(LogLevel.enum)
21
- }).argv;
22
- const log = getLogger(parseLogLevel(parsed.logLevel), "CLI");
23
- await yargs(hideBin(args)).usage("Usage: $0 [global options] <command> [options]").command(
24
- "create_env_files",
25
- "Copies the env.xyz files to .env.xyz",
26
- (yargs2) => yargs2,
27
- async () => {
28
- const env = getEnv();
29
- const scripts = getScriptsPkgDir();
30
- await exec(`cp -v ${scripts}/env.${env} ${scripts}/.env.${env}`);
31
- },
32
- []
33
- ).command({
34
- command: "setup",
35
- describe: "Setup the development environment by registering a provider, staking, loading a data set and then registering a dapp and staking.",
36
- builder: (yargs2) => yargs2.option("sites", {
37
- type: "boolean",
38
- demandOption: false,
39
- default: true,
40
- desc: "Set up sites"
41
- }).option("provider", {
42
- type: "boolean",
43
- demandOption: false,
44
- default: true,
45
- desc: "Set up the provider"
46
- }),
47
- handler: async (argv) => {
48
- log.info(() => ({ msg: "Running setup scripts" }));
49
- await setup(argv.provider, argv.sites);
50
- }
51
- }).command({
52
- command: "version",
53
- describe: "Set the version of packages",
54
- builder: (yargs2) => yargs2.option("v", { type: "string", demandOption: true }),
55
- handler: async (argv) => {
56
- await setVersion(String(argv.v));
57
- }
58
- }).command({
59
- command: "token <token>",
60
- describe: "Encode or Decode a Procaptcha token to the JSON output format",
61
- builder: (yargs2) => yargs2.positional("token", {
62
- describe: "a Procaptcha token to decode",
63
- type: "string",
64
- demandOption: true
65
- }),
66
- handler: async (argv) => {
67
- if (!isHex(argv.token)) {
68
- log.debug(() => ({ msg: "Encoding token to hex" }));
69
- log.info(() => ({
70
- data: { result: encodeProcaptchaOutput(JSON.parse(argv.token)) }
71
- }));
72
- } else {
73
- log.debug(() => ({ msg: "Decoding token from hex" }));
74
- log.info(() => ({
75
- data: { result: decodeProcaptchaOutput(argv.token) }
76
- }));
77
- }
78
- }
79
- }).argv;
16
+ const log = getLogger(parseLogLevel((await yargs(hideBin(args)).option("logLevel", {
17
+ describe: "set log level",
18
+ choices: Object.keys(LogLevel.enum)
19
+ }).argv).logLevel), "CLI");
20
+ await yargs(hideBin(args)).usage("Usage: $0 [global options] <command> [options]").command("create_env_files", "Copies the env.xyz files to .env.xyz", (yargs) => yargs, async () => {
21
+ const env = getEnv();
22
+ const scripts = getScriptsPkgDir();
23
+ await exec(`cp -v ${scripts}/env.${env} ${scripts}/.env.${env}`);
24
+ }, []).command({
25
+ command: "setup",
26
+ describe: "Setup the development environment by registering a provider, staking, loading a data set and then registering a dapp and staking.",
27
+ builder: (yargs) => yargs.option("sites", {
28
+ type: "boolean",
29
+ demandOption: false,
30
+ default: true,
31
+ desc: "Set up sites"
32
+ }).option("provider", {
33
+ type: "boolean",
34
+ demandOption: false,
35
+ default: true,
36
+ desc: "Set up the provider"
37
+ }),
38
+ handler: async (argv) => {
39
+ log.info(() => ({ msg: "Running setup scripts" }));
40
+ await setup(argv.provider, argv.sites);
41
+ }
42
+ }).command({
43
+ command: "version",
44
+ describe: "Set the version of packages",
45
+ builder: (yargs) => yargs.option("v", {
46
+ type: "string",
47
+ demandOption: true
48
+ }),
49
+ handler: async (argv) => {
50
+ await setVersion(String(argv.v));
51
+ }
52
+ }).command({
53
+ command: "token <token>",
54
+ describe: "Encode or Decode a Procaptcha token to the JSON output format",
55
+ builder: (yargs) => yargs.positional("token", {
56
+ describe: "a Procaptcha token to decode",
57
+ type: "string",
58
+ demandOption: true
59
+ }),
60
+ handler: async (argv) => {
61
+ if (!isHex(argv.token)) {
62
+ log.debug(() => ({ msg: "Encoding token to hex" }));
63
+ log.info(() => ({ data: { result: encodeProcaptchaOutput(JSON.parse(argv.token)) } }));
64
+ } else {
65
+ log.debug(() => ({ msg: "Decoding token from hex" }));
66
+ log.info(() => ({ data: { result: decodeProcaptchaOutput(argv.token) } }));
67
+ }
68
+ }
69
+ }).argv;
80
70
  }
81
71
  processArgs(process.argv).then(() => {
82
- process.exit(0);
72
+ process.exit(0);
83
73
  }).catch((error) => {
84
- console.error(error);
85
- process.exit(1);
74
+ console.error(error);
75
+ process.exit(1);
86
76
  });
87
- export {
88
- processArgs
89
- };
77
+ //#endregion
78
+ export { processArgs };
package/dist/index.js CHANGED
@@ -1,19 +1,10 @@
1
- import "./setup/index.js";
2
- import "./util/index.js";
3
- import { processArgs } from "./cli/index.js";
4
- import { setup, updateEnvFile } from "./setup/setup.js";
5
- import { setupProvider } from "./setup/provider.js";
1
+ import "./_virtual/_rolldown/runtime.js";
6
2
  import { findEnvFiles, updateDemoHTMLFiles, updateEnvFiles } from "./util/updateEnv.js";
7
3
  import { exec } from "./util/exec.js";
8
4
  import { extractReferrersFromLogs } from "./util/fluxLogDappDetails.js";
9
- export {
10
- exec,
11
- extractReferrersFromLogs,
12
- findEnvFiles,
13
- processArgs,
14
- setup,
15
- setupProvider,
16
- updateDemoHTMLFiles,
17
- updateEnvFile,
18
- updateEnvFiles
19
- };
5
+ import "./util/index.js";
6
+ import { setupProvider } from "./setup/provider.js";
7
+ import { setup, updateEnvFile } from "./setup/setup.js";
8
+ import "./setup/index.js";
9
+ import { processArgs } from "./cli/index.js";
10
+ export { exec, extractReferrersFromLogs, findEnvFiles, processArgs, setup, setupProvider, updateDemoHTMLFiles, updateEnvFile, updateEnvFiles };