@speleotica/frcsdata 5.0.2 → 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.
- package/cli/replace-names.d.ts +1 -0
- package/cli/replace-names.d.ts.map +1 -1
- package/cli/replace-names.js +8 -2
- package/cli/replace-names.js.map +1 -1
- package/cli.js +8 -2
- package/cli.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/replace-names.ts +9 -2
- package/src/cli.ts +7 -2
package/cli/replace-names.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replace-names.d.ts","sourceRoot":"","sources":["../../src/cli/replace-names.ts"],"names":[],"mappings":"
|
|
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"}
|
package/cli/replace-names.js
CHANGED
|
@@ -11,6 +11,7 @@ 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");
|
|
14
15
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
15
16
|
var _compareNames = require("./compareNames.js");
|
|
16
17
|
/* eslint-disable no-console */
|
|
@@ -52,8 +53,13 @@ async function replaceSurveyNames(surveyFile, replacementsFile, options) {
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
-
|
|
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'}`));
|
|
57
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'));
|
|
58
64
|
if (options?.verbose) {
|
|
59
65
|
for (const name of [...unreplacedNames].sort(_compareNames.compareNames)) {
|
package/cli/replace-names.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replace-names.js","names":["_parseFrcsSurveyFile","_interopRequireDefault","require","_replaceRanges","_ZodFrcsSurveyFileToJson","_unwrapInvalid","_parseNamesFile","_readFile","_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","
|
|
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,UAAU,CAAC;EACzC,MAAMK,MAAM,GAAGC,8DAAqC,CAACC,KAAK,CACxD,MAAM,IAAAC,4BAAmB,EAACR,UAAU,EAAE,CAACG,MAAM,CAAC,EAAE;IAC9CM,cAAc,EAAE,KAAK;IACrBC,WAAW,EAAE;EACf,CAAC,CACH,CAAC;EACD,MAAMC,KAAK,GAAG,MAAM,IAAAC,8BAAc,EAAC,MAAM,IAAAR,kBAAQ,EAACH,gBAAgB,CAAC,CAAC;EAEpE,MAAMY,eAAe,GAAG,IAAIC,GAAG,CAC7B,CAAC,GAAGH,KAAK,CAACI,OAAO,CAAC,CAAC,CAAC,CAACC,OAAO,CAAC,CAAC,CAACC,IAAI,EAAE;IAAEC;EAAY,CAAC,CA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AC,mBAAS,EAAC3C,UAAU,EAAEwC,QAAQ,EAAE,MAAM,CAAC;EAC/C,CAAC,MAAM;IACLI,OAAO,CAACC,MAAM,CAACH,KAAK,CAACF,QAAQ,CAAC;EAChC;EACAM,OAAO,CAACC,KAAK,CACXC,cAAK,CAACC,MAAM,CACV,YAAY9B,aAAa,CAAC+B,IAAI,QAC5B/B,aAAa,CAAC+B,IAAI,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,OAC9B9B,gBAAgB,YAAYA,gBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,EACtE,CACF,CAAC;EACD0B,OAAO,CAACC,KAAK,CACXlC,eAAe,CAACqC,IAAI,GAChBF,cAAK,CAACC,MAAM,CACV,GAAGpC,eAAe,CAACqC,IAAI,oBACrBrC,eAAe,CAACqC,IAAI,KAAK,CAAC,GAAG,MAAM,GAAG,QAAQ,UACtChD,OAAO,EAAEiD,OAAO,GAAG,GAAG,GAAG,EAAE,EACvC,CAAC,GACDH,cAAK,CAACI,KAAK,CAAC,iCAAiC,CACnD,CAAC;EACD,IAAIlD,OAAO,EAAEiD,OAAO,EAAE;IACpB,KAAK,MAAMlC,IAAI,IAAI,CAAC,GAAGJ,eAAe,CAAC,CAACwC,IAAI,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
|
@@ -91,17 +91,23 @@ void (0, _yargs.default)(process.argv.slice(2)).scriptName('frcsdata').command({
|
|
|
91
91
|
}).option('verbose', {
|
|
92
92
|
alias: 'v',
|
|
93
93
|
type: 'boolean'
|
|
94
|
+
}).option('write', {
|
|
95
|
+
alias: 'w',
|
|
96
|
+
describe: 'overwrite survey file with replacements',
|
|
97
|
+
type: 'boolean'
|
|
94
98
|
}),
|
|
95
99
|
handler: async ({
|
|
96
100
|
surveyFile,
|
|
97
101
|
replacementsFile,
|
|
98
|
-
verbose
|
|
102
|
+
verbose,
|
|
103
|
+
write
|
|
99
104
|
}) => {
|
|
100
105
|
const {
|
|
101
106
|
replaceSurveyNames: replaceNames
|
|
102
107
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./cli/replace-names.js")));
|
|
103
108
|
await replaceNames(surveyFile, replacementsFile, {
|
|
104
|
-
verbose
|
|
109
|
+
verbose,
|
|
110
|
+
write
|
|
105
111
|
});
|
|
106
112
|
}
|
|
107
113
|
}).command({
|
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","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","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 handler: async ({ surveyFile, replacementsFile, verbose }) => {\n const { replaceSurveyNames: replaceNames } = await import(\n './cli/replace-names'\n )\n await replaceNames(surveyFile, replacementsFile, { verbose })\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,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAM,OAAA,EAAAN,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAI,GAAA,CAAAP,CAAA,UAAAG,CAAA,CAAAK,GAAA,CAAAR,CAAA,OAAAS,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAf,CAAA,oBAAAe,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAe,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAd,CAAA,EAAAe,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAG,CAAA,IAAAT,CAAA,CAAAM,CAAA,IAAAf,CAAA,CAAAe,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAN,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,EAAAS,CAAA,GAAAA,C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ChB,CAAC,CAAC,CACDF,UAAU,CAAC,kBAAkB,EAAE;IAC9BC,IAAI,EAAE,QAAQ;IACdC,YAAY,EAAE;EAChB,CAAC,CAAC,CACDS,MAAM,CAAC,SAAS,EAAE;IACjBC,KAAK,EAAE,GAAG;IACVX,IAAI,EAAE;EACR,CAAC,CAAC;EACNE,OAAO,EAAE,MAAAA,CAAO;IAAEe,UAAU;IAAEC,gBAAgB;IAAEC;
|
|
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","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 })\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AY,EAAE;EAChB,CAAC,CAAC,CACDF,UAAU,CAAC,aAAa,EAAE;IACzBC,IAAI,EAAE,QAAQ;IACdC,YAAY,EAAE;EAChB,CAAC,CAAC;EACNC,OAAO,EAAE,MAAAA,CAAO;IAAEe,UAAU;IAAES;EAAY,CAAC,KAAK;IAC9C,MAAM;MAAEC;IAA0B,CAAC,GAAG,MAAAtB,OAAA,CAAAC,OAAA,GAAAC,IAAA,OAAAhC,uBAAA,CAAAN,OAAA,mCAErC;IACD,MAAM0D,yBAAyB,CAACV,UAAU,EAAES,WAAW,CAAC;EAC1D;AACF,CAAC,CAAC,CACDE,aAAa,CAAC,CAAC,CAACnC,IAAI","ignoreList":[]}
|
package/package.json
CHANGED
package/src/cli/replace-names.ts
CHANGED
|
@@ -5,6 +5,7 @@ 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'
|
|
8
9
|
import chalk from 'chalk'
|
|
9
10
|
import { compareNames } from './compareNames'
|
|
10
11
|
|
|
@@ -13,6 +14,7 @@ export async function replaceSurveyNames(
|
|
|
13
14
|
replacementsFile: string,
|
|
14
15
|
options?: {
|
|
15
16
|
verbose?: boolean
|
|
17
|
+
write?: boolean
|
|
16
18
|
}
|
|
17
19
|
) {
|
|
18
20
|
const source = await readFile(surveyFile)
|
|
@@ -55,10 +57,15 @@ export async function replaceSurveyNames(
|
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
const replaced = replaceRanges(source, replacements)
|
|
61
|
+
if (options?.write) {
|
|
62
|
+
await writeFile(surveyFile, replaced, 'utf8')
|
|
63
|
+
} else {
|
|
64
|
+
process.stdout.write(replaced)
|
|
65
|
+
}
|
|
59
66
|
console.error(
|
|
60
67
|
chalk.yellow(
|
|
61
|
-
`replaced ${replacedNames.size} ${
|
|
68
|
+
`replaced ${replacedNames.size} name${
|
|
62
69
|
replacedNames.size === 1 ? '' : 's'
|
|
63
70
|
} in ${replacementCount} location${replacementCount === 1 ? '' : 's'}`
|
|
64
71
|
)
|
package/src/cli.ts
CHANGED
|
@@ -83,12 +83,17 @@ void yargs(process.argv.slice(2))
|
|
|
83
83
|
.option('verbose', {
|
|
84
84
|
alias: 'v',
|
|
85
85
|
type: 'boolean',
|
|
86
|
+
})
|
|
87
|
+
.option('write', {
|
|
88
|
+
alias: 'w',
|
|
89
|
+
describe: 'overwrite survey file with replacements',
|
|
90
|
+
type: 'boolean',
|
|
86
91
|
}),
|
|
87
|
-
handler: async ({ surveyFile, replacementsFile, verbose }) => {
|
|
92
|
+
handler: async ({ surveyFile, replacementsFile, verbose, write }) => {
|
|
88
93
|
const { replaceSurveyNames: replaceNames } = await import(
|
|
89
94
|
'./cli/replace-names'
|
|
90
95
|
)
|
|
91
|
-
await replaceNames(surveyFile, replacementsFile, { verbose })
|
|
96
|
+
await replaceNames(surveyFile, replacementsFile, { verbose, write })
|
|
92
97
|
},
|
|
93
98
|
})
|
|
94
99
|
.command({
|