@speleotica/frcsdata 5.0.1 → 5.1.0

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 +1 @@
1
- {"version":3,"file":"parseNamesFile.d.ts","sourceRoot":"","sources":["../../src/cli/parseNamesFile.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM;kBACE,MAAM;GAQrD"}
1
+ {"version":3,"file":"parseNamesFile.d.ts","sourceRoot":"","sources":["../../src/cli/parseNamesFile.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM;kBACE,MAAM;GAMrD"}
@@ -7,12 +7,10 @@ exports.parseNamesFile = parseNamesFile;
7
7
  function parseNamesFile(content) {
8
8
  const names = new Map();
9
9
  for (const line of content.split(/\r\n?|\n/gm)) {
10
- const match = /^\s*(.+)\s*(?:=>\s*(.+)\s*)?$/.exec(line);
11
- if (match) {
12
- names.set(match[1].trim(), {
13
- replacement: match[2]?.trim()
14
- });
15
- }
10
+ const [name, replacement] = line.split('=>').map(s => s.trim());
11
+ if (name) names.set(name, {
12
+ replacement
13
+ });
16
14
  }
17
15
  return names;
18
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"parseNamesFile.js","names":["parseNamesFile","content","names","Map","line","split","match","exec","set","trim","replacement"],"sources":["../../src/cli/parseNamesFile.ts"],"sourcesContent":["export function parseNamesFile(content: string) {\n const names = new Map<string, { replacement?: string }>()\n for (const line of content.split(/\\r\\n?|\\n/gm)) {\n const match = /^\\s*(.+)\\s*(?:=>\\s*(.+)\\s*)?$/.exec(line)\n if (match) {\n names.set(match[1].trim(), { replacement: match[2]?.trim() })\n }\n }\n return names\n}\n"],"mappings":";;;;;;AAAO,SAASA,cAAcA,CAACC,OAAe,EAAE;EAC9C,MAAMC,KAAK,GAAG,IAAIC,GAAG,CAAmC,CAAC;EACzD,KAAK,MAAMC,IAAI,IAAIH,OAAO,CAACI,KAAK,CAAC,YAAY,CAAC,EAAE;IAC9C,MAAMC,KAAK,GAAG,+BAA+B,CAACC,IAAI,CAACH,IAAI,CAAC;IACxD,IAAIE,KAAK,EAAE;MACTJ,KAAK,CAACM,GAAG,CAACF,KAAK,CAAC,CAAC,CAAC,CAACG,IAAI,CAAC,CAAC,EAAE;QAAEC,WAAW,EAAEJ,KAAK,CAAC,CAAC,CAAC,EAAEG,IAAI,CAAC;MAAE,CAAC,CAAC;IAC/D;EACF;EACA,OAAOP,KAAK;AACd","ignoreList":[]}
1
+ {"version":3,"file":"parseNamesFile.js","names":["parseNamesFile","content","names","Map","line","split","name","replacement","map","s","trim","set"],"sources":["../../src/cli/parseNamesFile.ts"],"sourcesContent":["export function parseNamesFile(content: string) {\n const names = new Map<string, { replacement?: string }>()\n for (const line of content.split(/\\r\\n?|\\n/gm)) {\n const [name, replacement] = line.split('=>').map((s) => s.trim())\n if (name) names.set(name, { replacement })\n }\n return names\n}\n"],"mappings":";;;;;;AAAO,SAASA,cAAcA,CAACC,OAAe,EAAE;EAC9C,MAAMC,KAAK,GAAG,IAAIC,GAAG,CAAmC,CAAC;EACzD,KAAK,MAAMC,IAAI,IAAIH,OAAO,CAACI,KAAK,CAAC,YAAY,CAAC,EAAE;IAC9C,MAAM,CAACC,IAAI,EAAEC,WAAW,CAAC,GAAGH,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,CAACG,GAAG,CAAEC,CAAC,IAAKA,CAAC,CAACC,IAAI,CAAC,CAAC,CAAC;IACjE,IAAIJ,IAAI,EAAEJ,KAAK,CAACS,GAAG,CAACL,IAAI,EAAE;MAAEC;IAAY,CAAC,CAAC;EAC5C;EACA,OAAOL,KAAK;AACd","ignoreList":[]}
@@ -1,2 +1,5 @@
1
- export declare function replaceSurveyNames(surveyFile: string, replacementsFile: string): Promise<void>;
1
+ export declare function replaceSurveyNames(surveyFile: string, replacementsFile: string, options?: {
2
+ verbose?: boolean;
3
+ write?: boolean;
4
+ }): Promise<void>;
2
5
  //# sourceMappingURL=replace-names.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"replace-names.d.ts","sourceRoot":"","sources":["../../src/cli/replace-names.ts"],"names":[],"mappings":"AAQA,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,MAAM,EAClB,gBAAgB,EAAE,MAAM,iBA8BzB"}
1
+ {"version":3,"file":"replace-names.d.ts","sourceRoot":"","sources":["../../src/cli/replace-names.ts"],"names":[],"mappings":"AAWA,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,MAAM,EAClB,gBAAgB,EAAE,MAAM,EACxB,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,iBAuEF"}
@@ -11,15 +11,23 @@ var _ZodFrcsSurveyFileToJson = require("../survey/ZodFrcsSurveyFileToJson.js");
11
11
  var _unwrapInvalid = require("../unwrapInvalid.js");
12
12
  var _parseNamesFile = require("./parseNamesFile.js");
13
13
  var _readFile = require("./readFile.js");
14
+ var _promises = require("fs/promises");
15
+ var _chalk = _interopRequireDefault(require("chalk"));
16
+ var _compareNames = require("./compareNames.js");
14
17
  /* eslint-disable no-console */
15
18
 
16
- async function replaceSurveyNames(surveyFile, replacementsFile) {
19
+ async function replaceSurveyNames(surveyFile, replacementsFile, options) {
17
20
  const source = await (0, _readFile.readFile)(surveyFile);
18
21
  const parsed = _ZodFrcsSurveyFileToJson.ZodValidOrInvalidFrcsSurveyFileToJson.parse(await (0, _parseFrcsSurveyFile.default)(surveyFile, [source], {
19
22
  normalizeNames: false,
20
23
  includeLocs: true
21
24
  }));
22
25
  const names = await (0, _parseNamesFile.parseNamesFile)(await (0, _readFile.readFile)(replacementsFile));
26
+ const unreplacedNames = new Set([...names.entries()].flatMap(([name, {
27
+ replacement
28
+ }]) => replacement ? name : []));
29
+ const replacedNames = new Set();
30
+ let replacementCount = 0;
23
31
  const replacements = [];
24
32
  for (const trip of (0, _unwrapInvalid.unwrapInvalid)(parsed).trips) {
25
33
  const {
@@ -30,16 +38,33 @@ async function replaceSurveyNames(surveyFile, replacementsFile) {
30
38
  } = (0, _unwrapInvalid.unwrapInvalid)((0, _unwrapInvalid.unwrapInvalid)(trip).header);
31
39
  if (!team || !teamLocs) continue;
32
40
  for (let i = 0; i < team.length; i++) {
33
- const replacement = names.get(team[i])?.replacement;
34
- if (replacement && teamLocs[i]) {
41
+ const name = team[i];
42
+ const loc = teamLocs[i];
43
+ const replacement = names.get(name)?.replacement;
44
+ if (replacement && loc) {
45
+ unreplacedNames.delete(name);
46
+ replacedNames.add(name);
47
+ replacementCount++;
35
48
  replacements.push({
36
- start: teamLocs[i].start.index,
37
- end: teamLocs[i].end.index,
49
+ start: loc.start.index,
50
+ end: loc.end.index,
38
51
  value: replacement
39
52
  });
40
53
  }
41
54
  }
42
55
  }
43
- process.stdout.write((0, _replaceRanges.replaceRanges)(source, replacements));
56
+ const replaced = (0, _replaceRanges.replaceRanges)(source, replacements);
57
+ if (options?.write) {
58
+ await (0, _promises.writeFile)(surveyFile, replaced, 'utf8');
59
+ } else {
60
+ process.stdout.write(replaced);
61
+ }
62
+ console.error(_chalk.default.yellow(`replaced ${replacedNames.size} name${replacedNames.size === 1 ? '' : 's'} in ${replacementCount} location${replacementCount === 1 ? '' : 's'}`));
63
+ console.error(unreplacedNames.size ? _chalk.default.yellow(`${unreplacedNames.size} name replacement${unreplacedNames.size === 1 ? ' was' : 's were'} unused${options?.verbose ? ':' : ''}`) : _chalk.default.green('all name replacements were used'));
64
+ if (options?.verbose) {
65
+ for (const name of [...unreplacedNames].sort(_compareNames.compareNames)) {
66
+ console.error(_chalk.default.yellow(` ${name} => ${names.get(name)?.replacement}`));
67
+ }
68
+ }
44
69
  }
45
70
  //# sourceMappingURL=replace-names.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"replace-names.js","names":["_parseFrcsSurveyFile","_interopRequireDefault","require","_replaceRanges","_ZodFrcsSurveyFileToJson","_unwrapInvalid","_parseNamesFile","_readFile","replaceSurveyNames","surveyFile","replacementsFile","source","readFile","parsed","ZodValidOrInvalidFrcsSurveyFileToJson","parse","parseFrcsSurveyFile","normalizeNames","includeLocs","names","parseNamesFile","replacements","trip","unwrapInvalid","trips","team","locs","teamLocs","header","i","length","replacement","get","push","start","index","end","value","process","stdout","write","replaceRanges"],"sources":["../../src/cli/replace-names.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport parseFrcsSurveyFile from '../survey/parseFrcsSurveyFile'\nimport { replaceRanges } from '../replaceRanges'\nimport { ZodValidOrInvalidFrcsSurveyFileToJson } from '../survey/ZodFrcsSurveyFileToJson'\nimport { unwrapInvalid } from '../unwrapInvalid'\nimport { parseNamesFile } from './parseNamesFile'\nimport { readFile } from './readFile'\n\nexport async function replaceSurveyNames(\n surveyFile: string,\n replacementsFile: string\n) {\n const source = await readFile(surveyFile)\n const parsed = ZodValidOrInvalidFrcsSurveyFileToJson.parse(\n await parseFrcsSurveyFile(surveyFile, [source], {\n normalizeNames: false,\n includeLocs: true,\n })\n )\n const names = await parseNamesFile(await readFile(replacementsFile))\n\n const replacements: { start: number; end: number; value: string }[] = []\n for (const trip of unwrapInvalid(parsed).trips) {\n const { team, locs: { team: teamLocs } = {} } = unwrapInvalid(\n unwrapInvalid(trip).header\n )\n if (!team || !teamLocs) continue\n for (let i = 0; i < team.length; i++) {\n const replacement = names.get(team[i])?.replacement\n if (replacement && teamLocs[i]) {\n replacements.push({\n start: teamLocs[i].start.index,\n end: teamLocs[i].end.index,\n value: replacement,\n })\n }\n }\n }\n\n process.stdout.write(replaceRanges(source, replacements))\n}\n"],"mappings":";;;;;;;AACA,IAAAA,oBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,wBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AANA;;AA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O,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC,IAAAC,4BAAa,EAAC9B,MAAM,EAAEU,YAAY,CAAC,CAAC;AAC3D","ignoreList":[]}
1
+ {"version":3,"file":"replace-names.js","names":["_parseFrcsSurveyFile","_interopRequireDefault","require","_replaceRanges","_ZodFrcsSurveyFileToJson","_unwrapInvalid","_parseNamesFile","_readFile","_promises","_chalk","_compareNames","replaceSurveyNames","surveyFile","replacementsFile","options","source","readFile","parsed","ZodValidOrInvalidFrcsSurveyFileToJson","parse","parseFrcsSurveyFile","normalizeNames","includeLocs","names","parseNamesFile","unreplacedNames","Set","entries","flatMap","name","replacement","replacedNames","replacementCount","replacements","trip","unwrapInvalid","trips","team","locs","teamLocs","header","i","length","loc","get","delete","add","push","start","index","end","value","replaced","replaceRanges","write","writeFile","process","stdout","console","error","chalk","yellow","size","verbose","green","sort","compareNames"],"sources":["../../src/cli/replace-names.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport parseFrcsSurveyFile from '../survey/parseFrcsSurveyFile'\nimport { replaceRanges } from '../replaceRanges'\nimport { ZodValidOrInvalidFrcsSurveyFileToJson } from '../survey/ZodFrcsSurveyFileToJson'\nimport { unwrapInvalid } from '../unwrapInvalid'\nimport { parseNamesFile } from './parseNamesFile'\nimport { readFile } from './readFile'\nimport { writeFile } from 'fs/promises'\nimport chalk from 'chalk'\nimport { compareNames } from './compareNames'\n\nexport async function replaceSurveyNames(\n surveyFile: string,\n replacementsFile: string,\n options?: {\n verbose?: boolean\n write?: boolean\n }\n) {\n const source = await readFile(surveyFile)\n const parsed = ZodValidOrInvalidFrcsSurveyFileToJson.parse(\n await parseFrcsSurveyFile(surveyFile, [source], {\n normalizeNames: false,\n includeLocs: true,\n })\n )\n const names = await parseNamesFile(await readFile(replacementsFile))\n\n const unreplacedNames = new Set<string>(\n [...names.entries()].flatMap(([name, { replacement }]) =>\n replacement ? name : []\n )\n )\n const replacedNames = new Set<string>()\n let replacementCount = 0\n\n const replacements: { start: number; end: number; value: string }[] = []\n for (const trip of unwrapInvalid(parsed).trips) {\n const { team, locs: { team: teamLocs } = {} } = unwrapInvalid(\n unwrapInvalid(trip).header\n )\n if (!team || !teamLocs) continue\n for (let i = 0; i < team.length; i++) {\n const name = team[i]\n const loc = teamLocs[i]\n const replacement = names.get(name)?.replacement\n if (replacement && loc) {\n unreplacedNames.delete(name)\n replacedNames.add(name)\n replacementCount++\n replacements.push({\n start: loc.start.index,\n end: loc.end.index,\n value: replacement,\n })\n }\n }\n }\n\n const replaced = replaceRanges(source, replacements)\n if (options?.write) {\n await writeFile(surveyFile, replaced, 'utf8')\n } else {\n process.stdout.write(replaced)\n }\n console.error(\n chalk.yellow(\n `replaced ${replacedNames.size} name${\n replacedNames.size === 1 ? '' : 's'\n } in ${replacementCount} location${replacementCount === 1 ? '' : 's'}`\n )\n )\n console.error(\n unreplacedNames.size\n ? chalk.yellow(\n `${unreplacedNames.size} name replacement${\n unreplacedNames.size === 1 ? ' was' : 's were'\n } unused${options?.verbose ? ':' : ''}`\n )\n : chalk.green('all name replacements were used')\n )\n if (options?.verbose) {\n for (const name of [...unreplacedNames].sort(compareNames)) {\n console.error(\n chalk.yellow(` ${name} => ${names.get(name)?.replacement}`)\n )\n }\n }\n}\n"],"mappings":";;;;;;;AACA,IAAAA,oBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,wBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,aAAA,GAAAR,OAAA;AATA;;AAWO,eAAeS,kBAAkBA,CACtCC,UAAkB,EAClBC,gBAAwB,EACxBC,OAGC,EACD;EACA,MAAMC,MAAM,GAAG,MAAM,IAAAC,kBAAQ,EAACJ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,CAACC,0BAAY,CAAC,EAAE;MAC1DR,OAAO,CAACC,KAAK,CACXC,cAAK,CAACC,MAAM,CAAC,KAAKhC,IAAI,OAAON,KAAK,CAACqB,GAAG,CAACf,IAAI,CAAC,EAAEC,WAAW,EAAE,CAC7D,CAAC;IACH;EACF;AACF","ignoreList":[]}
package/cli.js CHANGED
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  var _yargs = _interopRequireDefault(require("yargs/yargs"));
5
5
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
6
6
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
7
- void (0, _yargs.default)(process.argv.slice(2)).command({
7
+ void (0, _yargs.default)(process.argv.slice(2)).scriptName('frcsdata').command({
8
8
  command: 'check <file>',
9
9
  describe: 'check survey file for errors or warnings',
10
10
  builder: yargs => yargs.positional('file', {
@@ -88,15 +88,27 @@ void (0, _yargs.default)(process.argv.slice(2)).command({
88
88
  }).positional('replacementsFile', {
89
89
  type: 'string',
90
90
  demandOption: true
91
+ }).option('verbose', {
92
+ alias: 'v',
93
+ type: 'boolean'
94
+ }).option('write', {
95
+ alias: 'w',
96
+ describe: 'overwrite survey file with replacements',
97
+ type: 'boolean'
91
98
  }),
92
99
  handler: async ({
93
100
  surveyFile,
94
- replacementsFile
101
+ replacementsFile,
102
+ verbose,
103
+ write
95
104
  }) => {
96
105
  const {
97
106
  replaceSurveyNames: replaceNames
98
107
  } = await Promise.resolve().then(() => _interopRequireWildcard(require("./cli/replace-names.js")));
99
- await replaceNames(surveyFile, replacementsFile);
108
+ await replaceNames(surveyFile, replacementsFile, {
109
+ verbose,
110
+ write
111
+ });
100
112
  }
101
113
  }).command({
102
114
  command: 'merge-names-files <namesFiles..>',
package/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","names":["_yargs","_interopRequireDefault","require","_getRequireWildcardCache","e","WeakMap","r","t","_interopRequireWildcard","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","yargs","process","argv","slice","command","describe","builder","positional","type","demandOption","handler","file","checkSurvey","Promise","resolve","then","parseSurvey","summarizeSurvey","option","alias","counts","suggestReplacements","listSurveyNames","listNames","includeCounts","surveyFile","replacementsFile","replaceSurveyNames","replaceNames","array","namesFiles","mergeNamesFiles","summaryFile","checkSurveyCorrespondence","demandCommand"],"sources":["src/cli.ts"],"sourcesContent":["import yargs from 'yargs/yargs'\n\nvoid yargs(process.argv.slice(2))\n .command({\n command: 'check <file>',\n describe: 'check survey file for errors or warnings',\n builder: (yargs) =>\n yargs.positional('file', {\n type: 'string',\n demandOption: true,\n }),\n handler: async ({ file }) => {\n const { checkSurvey } = await import('./cli/check')\n await checkSurvey(file)\n },\n })\n .command({\n command: 'parse <file>',\n describe: 'parse survey file and output JSON parse tree',\n builder: (yargs) =>\n yargs.positional('file', {\n type: 'string',\n demandOption: true,\n }),\n handler: async ({ file }) => {\n const { parseSurvey } = await import('./cli/parse-survey')\n await parseSurvey(file)\n },\n })\n .command({\n command: 'summarize <file>',\n describe: 'parse survey file and output trip summaries',\n builder: (yargs) =>\n yargs.positional('file', {\n type: 'string',\n demandOption: true,\n }),\n handler: async ({ file }) => {\n const { summarizeSurvey } = await import('./cli/summarize')\n await summarizeSurvey(file)\n },\n })\n .command({\n command: 'list-names <file>',\n describe: 'parse survey file and output surveyor name/count table',\n builder: (yargs) =>\n yargs\n .positional('file', {\n type: 'string',\n demandOption: true,\n })\n .option('counts', {\n alias: 'c',\n type: 'boolean',\n describe: 'count the number of occurrences of each name',\n demandOption: false,\n })\n .option('suggest-replacements', {\n alias: 's',\n type: 'boolean',\n describe: 'output suggested replacements',\n demandOption: false,\n }),\n handler: async ({ file, counts, suggestReplacements }) => {\n const { listSurveyNames: listNames } = await import('./cli/list-names')\n await listNames(file, { includeCounts: counts, suggestReplacements })\n },\n })\n .command({\n command: 'replace-names <surveyFile> <replacementsFile>',\n describe: 'replace names survey file',\n builder: (yargs) =>\n yargs\n .positional('surveyFile', {\n type: 'string',\n demandOption: true,\n })\n .positional('replacementsFile', {\n type: 'string',\n demandOption: true,\n }),\n handler: async ({ surveyFile, replacementsFile }) => {\n const { replaceSurveyNames: replaceNames } = await import(\n './cli/replace-names'\n )\n await replaceNames(surveyFile, replacementsFile)\n },\n })\n .command({\n command: 'merge-names-files <namesFiles..>',\n describe: 'merge two or more names files',\n builder: (yargs) =>\n yargs.positional('namesFiles', {\n type: 'string',\n array: true,\n demandOption: true,\n }),\n handler: async ({ namesFiles }) => {\n const { mergeNamesFiles } = await import('./cli/merge-names-files')\n await mergeNamesFiles(...namesFiles)\n },\n })\n .command({\n command: 'check-correspondence <surveyFile> <summaryFile>',\n describe: 'parse survey file and output trip summaries',\n builder: (yargs) =>\n yargs\n .positional('surveyFile', {\n type: 'string',\n demandOption: true,\n })\n .positional('summaryFile', {\n type: 'string',\n demandOption: true,\n }),\n handler: async ({ surveyFile, summaryFile }) => {\n const { checkSurveyCorrespondence } = await import(\n './cli/check-correspondence'\n )\n await checkSurveyCorrespondence(surveyFile, summaryFile)\n },\n })\n .demandCommand().argv\n"],"mappings":";;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA+B,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,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ireWildcardCache","e","WeakMap","r","t","_interopRequireWildcard","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","yargs","process","argv","slice","scriptName","command","describe","builder","positional","type","demandOption","handler","file","checkSurvey","Promise","resolve","then","parseSurvey","summarizeSurvey","option","alias","counts","suggestReplacements","listSurveyNames","listNames","includeCounts","surveyFile","replacementsFile","verbose","write","replaceSurveyNames","replaceNames","array","namesFiles","mergeNamesFiles","summaryFile","checkSurveyCorrespondence","demandCommand"],"sources":["src/cli.ts"],"sourcesContent":["import yargs from 'yargs/yargs'\n\nvoid yargs(process.argv.slice(2))\n .scriptName('frcsdata')\n .command({\n command: 'check <file>',\n describe: 'check survey file for errors or warnings',\n builder: (yargs) =>\n yargs.positional('file', {\n type: 'string',\n demandOption: true,\n }),\n handler: async ({ file }) => {\n const { checkSurvey } = await import('./cli/check')\n await checkSurvey(file)\n },\n })\n .command({\n command: 'parse <file>',\n describe: 'parse survey file and output JSON parse tree',\n builder: (yargs) =>\n yargs.positional('file', {\n type: 'string',\n demandOption: true,\n }),\n handler: async ({ file }) => {\n const { parseSurvey } = await import('./cli/parse-survey')\n await parseSurvey(file)\n },\n })\n .command({\n command: 'summarize <file>',\n describe: 'parse survey file and output trip summaries',\n builder: (yargs) =>\n yargs.positional('file', {\n type: 'string',\n demandOption: true,\n }),\n handler: async ({ file }) => {\n const { summarizeSurvey } = await import('./cli/summarize')\n await summarizeSurvey(file)\n },\n })\n .command({\n command: 'list-names <file>',\n describe: 'parse survey file and output surveyor name/count table',\n builder: (yargs) =>\n yargs\n .positional('file', {\n type: 'string',\n demandOption: true,\n })\n .option('counts', {\n alias: 'c',\n type: 'boolean',\n describe: 'count the number of occurrences of each name',\n demandOption: false,\n })\n .option('suggest-replacements', {\n alias: 's',\n type: 'boolean',\n describe: 'output suggested replacements',\n demandOption: false,\n }),\n handler: async ({ file, counts, suggestReplacements }) => {\n const { listSurveyNames: listNames } = await import('./cli/list-names')\n await listNames(file, { includeCounts: counts, suggestReplacements })\n },\n })\n .command({\n command: 'replace-names <surveyFile> <replacementsFile>',\n describe: 'replace names survey file',\n builder: (yargs) =>\n yargs\n .positional('surveyFile', {\n type: 'string',\n demandOption: true,\n })\n .positional('replacementsFile', {\n type: 'string',\n demandOption: true,\n })\n .option('verbose', {\n alias: 'v',\n type: 'boolean',\n })\n .option('write', {\n alias: 'w',\n describe: 'overwrite survey file with replacements',\n type: 'boolean',\n }),\n handler: async ({ surveyFile, replacementsFile, verbose, write }) => {\n const { replaceSurveyNames: replaceNames } = await import(\n './cli/replace-names'\n )\n await replaceNames(surveyFile, replacementsFile, { verbose, write })\n },\n })\n .command({\n command: 'merge-names-files <namesFiles..>',\n describe: 'merge two or more names files',\n builder: (yargs) =>\n yargs.positional('namesFiles', {\n type: 'string',\n array: true,\n demandOption: true,\n }),\n handler: async ({ namesFiles }) => {\n const { mergeNamesFiles } = await import('./cli/merge-names-files')\n await mergeNamesFiles(...namesFiles)\n },\n })\n .command({\n command: 'check-correspondence <surveyFile> <summaryFile>',\n describe: 'parse survey file and output trip summaries',\n builder: (yargs) =>\n yargs\n .positional('surveyFile', {\n type: 'string',\n demandOption: true,\n })\n .positional('summaryFile', {\n type: 'string',\n demandOption: true,\n }),\n handler: async ({ surveyFile, summaryFile }) => {\n const { checkSurveyCorrespondence } = await import(\n './cli/check-correspondence'\n )\n await checkSurveyCorrespondence(surveyFile, summaryFile)\n },\n })\n .demandCommand().argv\n"],"mappings":";;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA+B,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAI,wBAAAJ,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IA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ACV,UAAU,EAAES,WAAW,CAAC;EAC1D;AACF,CAAC,CAAC,CACDE,aAAa,CAAC,CAAC,CAACnC,IAAI","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speleotica/frcsdata",
3
- "version": "5.0.1",
3
+ "version": "5.1.0",
4
4
  "description": "parser for Chip Hopper's survey data format used in Fisher Ridge Cave System",
5
5
  "sideEffects": false,
6
6
  "bin": {
@@ -1,10 +1,8 @@
1
1
  export function parseNamesFile(content: string) {
2
2
  const names = new Map<string, { replacement?: string }>()
3
3
  for (const line of content.split(/\r\n?|\n/gm)) {
4
- const match = /^\s*(.+)\s*(?:=>\s*(.+)\s*)?$/.exec(line)
5
- if (match) {
6
- names.set(match[1].trim(), { replacement: match[2]?.trim() })
7
- }
4
+ const [name, replacement] = line.split('=>').map((s) => s.trim())
5
+ if (name) names.set(name, { replacement })
8
6
  }
9
7
  return names
10
8
  }
@@ -5,10 +5,17 @@ import { ZodValidOrInvalidFrcsSurveyFileToJson } from '../survey/ZodFrcsSurveyFi
5
5
  import { unwrapInvalid } from '../unwrapInvalid'
6
6
  import { parseNamesFile } from './parseNamesFile'
7
7
  import { readFile } from './readFile'
8
+ import { writeFile } from 'fs/promises'
9
+ import chalk from 'chalk'
10
+ import { compareNames } from './compareNames'
8
11
 
9
12
  export async function replaceSurveyNames(
10
13
  surveyFile: string,
11
- replacementsFile: string
14
+ replacementsFile: string,
15
+ options?: {
16
+ verbose?: boolean
17
+ write?: boolean
18
+ }
12
19
  ) {
13
20
  const source = await readFile(surveyFile)
14
21
  const parsed = ZodValidOrInvalidFrcsSurveyFileToJson.parse(
@@ -19,6 +26,14 @@ export async function replaceSurveyNames(
19
26
  )
20
27
  const names = await parseNamesFile(await readFile(replacementsFile))
21
28
 
29
+ const unreplacedNames = new Set<string>(
30
+ [...names.entries()].flatMap(([name, { replacement }]) =>
31
+ replacement ? name : []
32
+ )
33
+ )
34
+ const replacedNames = new Set<string>()
35
+ let replacementCount = 0
36
+
22
37
  const replacements: { start: number; end: number; value: string }[] = []
23
38
  for (const trip of unwrapInvalid(parsed).trips) {
24
39
  const { team, locs: { team: teamLocs } = {} } = unwrapInvalid(
@@ -26,16 +41,49 @@ export async function replaceSurveyNames(
26
41
  )
27
42
  if (!team || !teamLocs) continue
28
43
  for (let i = 0; i < team.length; i++) {
29
- const replacement = names.get(team[i])?.replacement
30
- if (replacement && teamLocs[i]) {
44
+ const name = team[i]
45
+ const loc = teamLocs[i]
46
+ const replacement = names.get(name)?.replacement
47
+ if (replacement && loc) {
48
+ unreplacedNames.delete(name)
49
+ replacedNames.add(name)
50
+ replacementCount++
31
51
  replacements.push({
32
- start: teamLocs[i].start.index,
33
- end: teamLocs[i].end.index,
52
+ start: loc.start.index,
53
+ end: loc.end.index,
34
54
  value: replacement,
35
55
  })
36
56
  }
37
57
  }
38
58
  }
39
59
 
40
- process.stdout.write(replaceRanges(source, replacements))
60
+ const replaced = replaceRanges(source, replacements)
61
+ if (options?.write) {
62
+ await writeFile(surveyFile, replaced, 'utf8')
63
+ } else {
64
+ process.stdout.write(replaced)
65
+ }
66
+ console.error(
67
+ chalk.yellow(
68
+ `replaced ${replacedNames.size} name${
69
+ replacedNames.size === 1 ? '' : 's'
70
+ } in ${replacementCount} location${replacementCount === 1 ? '' : 's'}`
71
+ )
72
+ )
73
+ console.error(
74
+ unreplacedNames.size
75
+ ? chalk.yellow(
76
+ `${unreplacedNames.size} name replacement${
77
+ unreplacedNames.size === 1 ? ' was' : 's were'
78
+ } unused${options?.verbose ? ':' : ''}`
79
+ )
80
+ : chalk.green('all name replacements were used')
81
+ )
82
+ if (options?.verbose) {
83
+ for (const name of [...unreplacedNames].sort(compareNames)) {
84
+ console.error(
85
+ chalk.yellow(` ${name} => ${names.get(name)?.replacement}`)
86
+ )
87
+ }
88
+ }
41
89
  }
package/src/cli.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import yargs from 'yargs/yargs'
2
2
 
3
3
  void yargs(process.argv.slice(2))
4
+ .scriptName('frcsdata')
4
5
  .command({
5
6
  command: 'check <file>',
6
7
  describe: 'check survey file for errors or warnings',
@@ -78,12 +79,21 @@ void yargs(process.argv.slice(2))
78
79
  .positional('replacementsFile', {
79
80
  type: 'string',
80
81
  demandOption: true,
82
+ })
83
+ .option('verbose', {
84
+ alias: 'v',
85
+ type: 'boolean',
86
+ })
87
+ .option('write', {
88
+ alias: 'w',
89
+ describe: 'overwrite survey file with replacements',
90
+ type: 'boolean',
81
91
  }),
82
- handler: async ({ surveyFile, replacementsFile }) => {
92
+ handler: async ({ surveyFile, replacementsFile, verbose, write }) => {
83
93
  const { replaceSurveyNames: replaceNames } = await import(
84
94
  './cli/replace-names'
85
95
  )
86
- await replaceNames(surveyFile, replacementsFile)
96
+ await replaceNames(surveyFile, replacementsFile, { verbose, write })
87
97
  },
88
98
  })
89
99
  .command({