Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
electric-el committed May 25, 2022
2 parents e0973ff + 41971b4 commit e99365e
Show file tree
Hide file tree
Showing 71 changed files with 775 additions and 633 deletions.
46 changes: 27 additions & 19 deletions core/lib/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,42 +72,46 @@ exports.loadingAnimation = `
<div></div><div></div><div></div><div></div>
</div>`;

/* eslint-disable quotes */
exports.scraperHeading = `
<h1 id="scraper__heading">${t('Fepper HTML Scraper')}</h1>`;
<h1 id="scraper__heading">${t("Fepper HTML Scraper")}</h1>`;

exports.forbidden = `
<section id="forbidden" class="error">
<p>${t('ERROR')}! ${t('You can only use %s on the machine that is running this Fepper instance!')}</p>
<p>${t('If you <em>are</em> on this machine, you may need to resync this browser with Fepper.')}</p>
<p>${t('Please go to the command line and quit this Fepper instance. Then run fp (not fp restart).')}</p>
<section id="forbidden" class="error forbidden gatekept">
<p>${t("ERROR")}! ${t("You can only use %s on the machine that is running this Fepper instance!")}</p>
<p>${t("If you <em>are</em> on this machine, you may need to resync this browser with Fepper.")}</p>
<p>${t("Please go to the command line and quit this Fepper instance. Then run fp (not fp restart).")}</p>
</section>`;

exports.landingBody = `
<form id="scraper__targeter" action="/html-scraper" method="post" name="targeter">
<div>
<label for="url">${t('URL:')}</label>
<label for="url">${t("URL:")}</label>
<input name="url" type="text" value="{{{ url }}}">
</div>
<div>
<label for="selector_raw">${t('Selector:')}</label>
<label for="selector_raw">${t("Selector:")}</label>
<input name="selector_raw" type="text" value="{{ selector_raw }}">
<input name="selector" type="hidden" value="{{ selector }}">
<input name="index" type="hidden" value="{{ index }}">
</div>
<textarea name="html2json"></textarea>
<input id="scraper__targeter__submit" name="submit_targeter" type="submit" value="${t('Submit')}">
<input id="scraper__targeter__submit" name="submit_targeter" type="submit" value="${t("Submit")}">
{{{ help_buttons }}}
</form>`;

exports.helpButtons = `<button id="help-hide">${t('Hide')}</button><button id="help-show">${t('Help')}</button>`;
exports.helpButtons = `<button id="help-hide">${t("Hide")}</button><button id="help-show">${t("Help")}</button>`;
/* eslint-enable quotes */

exports.helpText = `
<div id="help-text">{{{ help_text }}} </div>`;

/* eslint-disable quotes */
exports.scraperHelpText = `
<p></p>
<p>${t('Use this tool to scrape and import .mustache templates and .json data files from actual web pages, preferably the actual backend CMS that Fepper is prototyping for. Simply enter the URL of the page you wish to scrape. Then, enter the CSS selector you wish to target (prepended with &quot;#&quot; for IDs and &quot;.&quot; for classes). Classnames and tagnames may be appended with array index notation ([n]). Otherwise, the Scraper will scrape all elements of that class or tag sequentially. Such a loosely targeted scrape will save many of the targeted fields to the .json file, but will only save the first instance of the target to a .mustache template.')}</p>
<p>${t('Upon submit, you should be able to review the scraped output on the subsequent page. If the output looks correct, enter a filename and submit again. The Scraper will save .mustache and .json files by that name in your patterns&apos; scrape directory, also viewable under the Scrape menu of the toolbar.')}</p>\n`;
<p>${t("Use this tool to scrape and import .mustache templates and .json data files from actual web pages, preferably the actual backend CMS that Fepper is prototyping for. Simply enter the URL of the page you wish to scrape. Then, enter the CSS selector you wish to target (prepended with &quot;#&quot; for IDs and &quot;.&quot; for classes). Classnames and tagnames may be appended with array index notation ([n]). Otherwise, the Scraper will scrape all elements of that class or tag sequentially. Such a loosely targeted scrape will save many of the targeted fields to the .json file, but will only save the first instance of the target to a .mustache template.")}</p>
<p>${t("Upon submit, you should be able to review the scraped output on the subsequent page. If the output looks correct, enter a filename and submit again. The Scraper will save .mustache and .json files by that name in your patterns&apos; scrape directory, also viewable under the Scrape menu of the toolbar.")}</p>\n`;
/* eslint-enable quotes */

exports.scraperStage = `
<iframe id="scraper__stage" sandbox="allow-same-origin allow-scripts"></iframe>`;
Expand All @@ -118,31 +122,35 @@ exports.reviewerPrefix = `
exports.reviewerSuffix = `
</div>`;

/* eslint-disable quotes */
exports.importerPrefix = `
<h3>${t('Does this HTML look right?')}</h3>
<h3>${t("Does this HTML look right?")}</h3>
<form id="scraper__importer" action="/html-scraper" method="post" name="importer">
<div>${t('Yes, import into Fepper.')}</div>
<label for="filename">${t('Enter a filename to save this under (extension not necessary):')}</label>
<div>${t("Yes, import into Fepper.")}</div>
<label for="filename">${t("Enter a filename to save this under (extension not necessary):")}</label>
<input name="filename" type="text" value="">
<input name="url" type="hidden" value="{{{ url }}}">
<input name="selector_raw" type="hidden" value="{{ selector_raw }}">
<textarea name="html2json"></textarea>
<textarea name="mustache">`;
/* eslint-enable quotes */

exports.json = `
</textarea>
<textarea name="json">`;

/* eslint-disable quotes */
exports.importerSuffix = `
</textarea>
<input id="scraper__importer__submit" name="submit_importer" type="submit" value="${t('Submit')}">
<input id="scraper__importer__submit" name="submit_importer" type="submit" value="${t("Submit")}">
</form>
<h3>${t('Otherwise, correct the URL and selector and submit again.')}</h3>`;
<h3>${t("Otherwise, correct the URL and selector and submit again.")}</h3>`;

exports.success = `
<p>${t('To open the UI, click here:')} <a href="http://{{ origin }}{{ search }}" target="_blank">http://{{ origin }}</a></p>
<p>${t('To halt Fepper, go to the command prompt where Fepper is running and press ctrl+c.')}</p>
<p>${t('The following documentation is also available in Fepper&apos;s README.md:')}</p>`;
<p>${t("To open the UI, click here:")} <a href="http://{{ origin }}{{ search }}" target="_blank">http://{{ origin }}</a></p>
<p>${t("To halt Fepper, go to the command prompt where Fepper is running and press ctrl+c.")}</p>
<p>${t("The following documentation is also available in Fepper&apos;s README.md:")}</p>`;
/* eslint-enable quotes */

exports.foot = `
</main>
Expand Down
2 changes: 1 addition & 1 deletion core/tasks/frontend-copier.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ module.exports = class {
fs.copySync(file, targetFilePath);
}

let message = 'Copied %s to %s';
let message = t("Copied %s to %s"); // eslint-disable-line quotes
message = message.replace('%s', '\x1b[36m' + file.replace(this.rootDir, '').replace(/^\//, '') + '\x1b[0m');
message = message.replace('%s', '\x1b[36m' + targetFilePath.replace(this.rootDir, '').replace(/^\//, '') +
'\x1b[0m');
Expand Down
34 changes: 18 additions & 16 deletions core/tasks/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@ module.exports = class {
}

main() {
/* eslint-disable quotes */
let out = `
${t('Use:')}
<${t('task')}> [<${t('additional args')}>... [-d | --debug]]
${t("Use:")}
<${t("task")}> [<${t("additional args")}>... [-d | --debug]]
${t('Tasks:')}
fp ${t('Launch Fepper and open it in a browser')}
fp data ${t('Build data.json from underscore-prefixed .json files')}
fp frontend-copy ${t('Copy assets, scripts, and styles to the backend')}
fp once ${t('Output a new build to the public directory')}
fp restart ${t('Restart after shutdown, but without opening the browser')}
fp static ${t('Generate a static site from the 04-pages directory')}
fp syncback ${t('Combine frontend-copy and template tasks')}
fp template ${t('Translate templates in 03-templates for the backend, and output them there')}
fp ui:compile ${t('Compile the user interface from its components')}
fp ui:help ${t('Print UI tasks and their descriptions')}
fp update ${t('Update Fepper distro, Fepper CLI, Fepper NPM, Fepper UI, and Fepper extensions')}
fp version ${t('Print the versions of Fepper CLI, Fepper NPM, and Fepper UI')}
fp extend:help ${t('Print extension tasks and their descriptions')}
${t("Tasks:")}
fp ${t("Launch Fepper and open it in a browser")}
fp data ${t("Build data.json from underscore-prefixed .json files")}
fp frontend-copy ${t("Copy assets, scripts, and styles to the backend")}
fp once ${t("Output a new build to the public directory")}
fp restart ${t("Restart after shutdown, but without opening the browser")}
fp static ${t("Generate a static site from the 04-pages directory")}
fp syncback ${t("Combine frontend-copy and template tasks")}
fp template ${t("Translate templates in 03-templates for the backend, and output them there")}
fp ui:compile ${t("Compile the user interface from its components")}
fp ui:help ${t("Print UI tasks and their descriptions")}
fp update ${t("Update Fepper distro, Fepper CLI, Fepper NPM, Fepper UI, and Fepper extensions")}
fp version ${t("Print the versions of Fepper CLI, Fepper NPM, and Fepper UI")}
fp extend:help ${t("Print extension tasks and their descriptions")}
`;
/* eslint-enable quotes */

this.utils.info(out);
}
Expand Down
9 changes: 6 additions & 3 deletions core/tasks/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,26 @@ module.exports = class {
/* istanbul ignore if */
if (!fs.existsSync(`${this.extendDir}/node_modules`)) {
process.chdir(this.extendDir);
this.utils.log(`${t('Working directory changed to %s')}`, path.resolve(this.extendDir));
// eslint-disable-next-line quotes
this.utils.log(`${t("Working directory changed to %s")}`, path.resolve(this.extendDir));
spawnSync(this.binNpm, ['install'], {stdio: 'inherit'});
}

// Run npm install in public dir if no public/node_modules dir.
/* istanbul ignore if */
if (!fs.existsSync(`${this.publicDir}/node_modules`)) {
process.chdir(this.publicDir);
this.utils.log(`${t('Working directory changed to %s')}`, path.resolve(this.publicDir));
// eslint-disable-next-line quotes
this.utils.log(`${t("Working directory changed to %s")}`, path.resolve(this.publicDir));
spawnSync(this.binNpm, ['install'], {stdio: 'inherit'});
}

// Finish up.
const cwd = process.cwd();

process.chdir(cwd);
this.utils.log(`${t('Working directory changed to %s')}`, cwd);
// eslint-disable-next-line quotes
this.utils.log(`${t("Working directory changed to %s")}`, cwd);
}

copyBase() {
Expand Down
9 changes: 6 additions & 3 deletions core/tasks/json-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ module.exports = class {
dataGlobalJson = JSON5.parse(dataGlobalStr);
}
catch (err) /* istanbul ignore next */ {
this.utils.error(`${t('ERROR')}: ${t('Missing or malformed %s!')}`, dataGlobal);
// eslint-disable-next-line quotes
this.utils.error(`${t("ERROR")}: ${t("Missing or malformed %s!")}`, dataGlobal);
this.utils.error(err);

return;
Expand Down Expand Up @@ -67,7 +68,8 @@ module.exports = class {
dataPartialJson = JSON5.parse(dataPartialStr);
}
catch (err1) /* istanbul ignore next */ {
this.utils.error(`${t('ERROR')}: ${t('Malformed %s')}`, file);
// eslint-disable-next-line quotes
this.utils.error(`${t("ERROR")}: ${t("Malformed %s")}`, file);
this.utils.error(err1);

return;
Expand All @@ -89,7 +91,8 @@ module.exports = class {
dataAppendixJson = JSON5.parse(dataAppendixStr);
}
catch (err) /* istanbul ignore next */ {
this.utils.error(`${t('ERROR')}: ${t('Malformed %s')}`, dataAppendix);
// eslint-disable-next-line quotes
this.utils.error(`${t("ERROR")}: ${t("Malformed %s")}`, dataAppendix);
this.utils.error(err);
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/tasks/templater.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ module.exports = class {
// Write translated templates.
const dest = this.templatesWrite(mustacheFile, srcDirParam, templatesDir, templatesExt, codeTranslated);

let message = t('Template %s translated');
// eslint-disable-next-line quotes
let message = t("Template %s translated");
message = message.replace('%s', '\x1b[36m' + dest.replace(this.rootDir, '').replace(/^\//, '') + '\x1b[0m');

this.utils.log(message);
Expand Down
15 changes: 10 additions & 5 deletions core/tasks/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ module.exports = class {
}

// Update global npm.
this.utils.log(`${t('Running npm --global update on fepper-cli...')}`);
// eslint-disable-next-line quotes
this.utils.log(`${t("Running npm --global update on fepper-cli...")}`);

const fepperCliVersions = parseNpmOutdated('fepper-cli', ['--global']);

Expand All @@ -105,15 +106,17 @@ module.exports = class {
spawnSync(this.binNpm, ['install', '--global', 'fepper-cli'], {stdio: 'inherit'});
}
else {
this.utils.log(`${t('Running this command again as root/Administrator...')}`);
// eslint-disable-next-line quotes
this.utils.log(`${t("Running this command again as root/Administrator...")}`);
spawnSync('sudo', [this.binNpm, 'uninstall', '--global', 'fepper-cli']);
spawnSync('sudo', [this.binNpm, 'install', '--global', 'fepper-cli'], {stdio: 'inherit'});
}
}

// Update core npms.
process.chdir(this.rootDir);
this.utils.log(`${t('Running npm update in %s...')}`, path.resolve(this.rootDir));
// eslint-disable-next-line quotes
this.utils.log(`${t("Running npm update in %s...")}`, path.resolve(this.rootDir));

// Find the latest fepper-npm release and update if updatable.
const fepperVersions = parseNpmOutdated('fepper');
Expand Down Expand Up @@ -161,7 +164,8 @@ module.exports = class {
// Update extension npms.
if (fs.existsSync(this.extendDir)) {
process.chdir(this.extendDir);
this.utils.log(`${t('Running npm update in %s...')}`, path.resolve(this.extendDir));
// eslint-disable-next-line quotes
this.utils.log(`${t("Running npm update in %s...")}`, path.resolve(this.extendDir));

// If the fp-stylus extension is installed, find the latest release and update if updatable.
const extendPackageJson = fs.readJsonSync('./package.json', {throws: false});
Expand All @@ -183,7 +187,8 @@ module.exports = class {

// Update public dir npms.
process.chdir(this.publicDir);
this.utils.log(`${t('Running npm update in %s...')}`, path.resolve(this.publicDir));
// eslint-disable-next-line quotes
this.utils.log(`${t("Running npm update in %s...")}`, path.resolve(this.publicDir));

// Find the latest feplet release and update if updatable.
const fepletVersions = parseNpmOutdated('feplet');
Expand Down
6 changes: 4 additions & 2 deletions core/tcp-ip/error-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ module.exports = class {
);

let outputFpt = this.html.headBoilerplate;
outputFpt = outputFpt.replace('{{ title }}', t('ERROR'));
outputFpt += `\n <pre>${t('Cannot GET %s')}</pre>`;
/* eslint-disable quotes */
outputFpt = outputFpt.replace('{{ title }}', t("ERROR"));
outputFpt += `\n <pre>${t("Cannot GET %s")}</pre>`;
/* eslint-enable quotes */
outputFpt = outputFpt.replace('%s', req.url);
outputFpt += this.html.foot;
const output = Feplet.render(outputFpt, {patternlabFoot});
Expand Down
Loading

0 comments on commit e99365e

Please sign in to comment.