UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

172 lines 8.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AllWikiDocuments = void 0; exports.makeAllWikis = makeAllWikis; const doc_context_1 = require("../documentation/wiki-mk/doc-context"); const shell_1 = require("../r-bridge/shell"); const tree_sitter_executor_1 = require("../r-bridge/lang-4.x/tree-sitter/tree-sitter-executor"); const fs_1 = __importDefault(require("fs")); const log_1 = require("../../test/functionality/_helper/log"); const command_line_usage_1 = __importDefault(require("command-line-usage")); const command_line_args_1 = __importDefault(require("command-line-args")); const version_1 = require("../util/version"); const wiki_faq_1 = require("../documentation/wiki-faq"); const ansi_1 = require("../util/text/ansi"); const documentation_1 = require("../documentation"); const wiki_cfg_1 = require("../documentation/wiki-cfg"); const wiki_onboarding_1 = require("../documentation/wiki-onboarding"); const wiki_analyzer_1 = require("../documentation/wiki-analyzer"); const issue_linting_rule_1 = require("../documentation/issue-linting-rule"); const doc_readme_1 = require("../documentation/doc-readme"); const wiki_linter_1 = require("../documentation/wiki-linter"); const os_1 = __importDefault(require("os")); const wiki_setup_1 = require("../documentation/wiki-setup"); const wiki_overview_1 = require("../documentation/wiki-overview"); const wiki_absint_1 = require("../documentation/wiki-absint"); exports.AllWikiDocuments = [ new wiki_faq_1.WikiFaq(), new documentation_1.WikiSearch(), new wiki_cfg_1.WikiCfg(), new documentation_1.WikiQuery(), new wiki_onboarding_1.WikiOnboarding(), new wiki_analyzer_1.WikiAnalyzer(), new documentation_1.WikiEngine(), new documentation_1.WikiNormalizedAst(), new documentation_1.WikiCore(), new wiki_setup_1.WikiSetup(), new wiki_overview_1.WikiOverview(), new documentation_1.WikiInterface(), new documentation_1.WikiDataflowGraph(), new documentation_1.WikiLintingAndTesting(), new wiki_linter_1.WikiLinter(), new wiki_absint_1.WikiAbsint(), new issue_linting_rule_1.IssueLintingRule(), new doc_readme_1.DocReadme(), new documentation_1.DocCapabilities() ]; function sortByLeastRecentChanged(wikis) { return wikis.slice().sort((a, b) => { const aStat = fs_1.default.existsSync(a.getProducer()) ? fs_1.default.statSync(a.getProducer()) : undefined; const bStat = fs_1.default.existsSync(b.getProducer()) ? fs_1.default.statSync(b.getProducer()) : undefined; const aMTime = aStat ? aStat.mtime.getTime() : 0; const bMTime = bStat ? bStat.mtime.getTime() : 0; return bMTime - aMTime; }); } /** * Updates and optionally re-creates all flowR wikis. */ async function makeAllWikis(force, filter) { const setupStart = new Date(); console.log('Setting up wiki generation...'); const shell = new shell_1.RShell(); console.log(' * R shell initialized'); await tree_sitter_executor_1.TreeSitterExecutor.initTreeSitter(); const treeSitter = new tree_sitter_executor_1.TreeSitterExecutor(); console.log(' * Tree-sitter parser initialized'); const ctx = (0, doc_context_1.makeDocContextForTypes)(shell); console.log(' * Wiki context prepared'); if (force) { console.log(ansi_1.ansiFormatter.format('Forcing wiki regeneration (existing files will be overwritten)', { style: 1 /* FontStyles.Bold */, color: 3 /* Colors.Yellow */, effect: ansi_1.ColorEffect.Foreground })); } const info = { ctx, shell, treeSitter, force, readFileSync(f) { try { return fs_1.default.readFileSync(f); } catch { return undefined; } }, writeFileSync: fs_1.default.writeFileSync }; console.log(`Setup for wiki generation took ${(Date.now() - setupStart.getTime())}ms`); const changedWikis = new Set(); try { const sortedDocs = sortByLeastRecentChanged(exports.AllWikiDocuments); console.log(`Generating ${sortedDocs.length} wikis/docs, sorted by most recently updated...`); for (const doc of sortedDocs) { const type = doc.getTarget().toLowerCase().includes('wiki') ? 'Wiki' : 'Doc'; if (filter && !filter.some(f => doc.getTarget().includes(f))) { console.log(` * Skipping ${type} (filtered out): ${doc.getTarget()}`); continue; } const now = new Date(); console.log(ansi_1.ansiFormatter.format(` [${doc.getTarget()}] Updating ${type}...`, { style: 1 /* FontStyles.Bold */, color: 6 /* Colors.Cyan */, effect: ansi_1.ColorEffect.Foreground })); const changed = await doc.make(info); const text = changed ? `${type} updated` : `${type} identical, no changes made`; if (changed) { changedWikis.add(doc.getTarget()); } const color = changed ? 2 /* Colors.Green */ : 7 /* Colors.White */; console.log(ansi_1.ansiFormatter.format(` [${doc.getTarget()}] ${text}: ${doc.getTarget()} (took ${Date.now() - now.getTime()}ms)`, { color, effect: ansi_1.ColorEffect.Foreground })); for (const out of doc.getWrittenSubfiles()) { changedWikis.add(out); console.log(` - Also updated: ${out}`); } } } catch (error) { console.error('Error while generating documents:', error); } finally { shell.close(); } console.log('All wikis processed in ' + (new Date().getTime() - setupStart.getTime()) + 'ms'); console.log(` * Changed ${changedWikis.size} wiki/doc files.`); // write a temp file in the os temp dir with the changed wikis const filename = `${os_1.default.tmpdir()}/flowr-wiki-changed-files.txt`; fs_1.default.writeFileSync(`${filename}`, Array.from(changedWikis).join('\n')); console.log(` * List of changed wikis/docs written to ${filename}`); } if (require.main === module) { const wikiOptions = [ { name: 'force', alias: 'F', type: Boolean, description: 'Overwrite existing wiki files, even if nothing changes' }, { name: 'filter', alias: 'f', type: String, multiple: true, description: 'Only generate wikis whose target path contains the given string' }, { name: 'help', alias: 'h', type: Boolean, description: 'Print this usage guide for the wiki generator' }, { name: 'keep-alive', type: Boolean, description: 'Keep-alive wiki generator (only sensible with a reloading script like node --watch)' }, ]; const optionHelp = [ { header: `flowR (version ${(0, version_1.flowrVersion)().toString()})`, content: 'Documentation (wiki, issue, ...) generator for flowR' }, { header: 'Synopsis', content: [ '$ wiki {bold --help}', '$ wiki {bold --force}', '$ wiki {bold --filter} {italic "dataflow"}' ] }, { header: 'Options', optionList: wikiOptions } ]; (0, log_1.setMinLevelOfAllLogs)(6 /* LogLevel.Fatal */); // parse args const options = (0, command_line_args_1.default)(wikiOptions); if (options.help) { console.log((0, command_line_usage_1.default)(optionHelp)); process.exit(0); } void makeAllWikis(options.force, options.filter).catch(err => { console.error('Error while generating wikis:', err); process.exit(1); }).then(() => { if (options['keep-alive']) { console.log('Wiki generator running in keep-alive mode...'); setInterval(() => { // do nothing, just keep alive }, 100); } }); } //# sourceMappingURL=wiki.js.map