diff --git a/.gitignore b/.gitignore index cd5f291d8..f4a27e05f 100644 --- a/.gitignore +++ b/.gitignore @@ -61,4 +61,4 @@ consoleProxy.ts .angular *.tgz testCreate.sh -scully/runtime \ No newline at end of file +scully/runtime diff --git a/apps/scully-docs/src/app/app-routing.module.ts b/apps/scully-docs/src/app/app-routing.module.ts index 2e78656a1..ee8a4705a 100644 --- a/apps/scully-docs/src/app/app-routing.module.ts +++ b/apps/scully-docs/src/app/app-routing.module.ts @@ -20,7 +20,7 @@ const routes: Routes = [ loadChildren: () => import('./pages/extraPages/extra-page.module').then((m) => m.ExtraPageModule), }, { - path: 'consultancy', + path: 'support', loadChildren: () => import('./pages/extraPages/extra-page.module').then((m) => m.ExtraPageModule), }, { diff --git a/apps/scully-docs/src/app/components/footer/component/footer.component.ts b/apps/scully-docs/src/app/components/footer/component/footer.component.ts index ea837e4ed..5e7a99749 100644 --- a/apps/scully-docs/src/app/components/footer/component/footer.component.ts +++ b/apps/scully-docs/src/app/components/footer/component/footer.component.ts @@ -27,6 +27,14 @@ import { Component, ViewEncapsulation } from '@angular/core';
  • Press kit
  • +
    +

    Support

    + +
    `, }) export class FooterComponent {} diff --git a/apps/scully-docs/src/app/components/header/component/nav-header/nav-header.component.css b/apps/scully-docs/src/app/components/header/component/nav-header/nav-header.component.css index c9e4016bf..e010a591c 100644 --- a/apps/scully-docs/src/app/components/header/component/nav-header/nav-header.component.css +++ b/apps/scully-docs/src/app/components/header/component/nav-header/nav-header.component.css @@ -1,3 +1,9 @@ +nav.scullyio-nav-header ul li a.pricing { + color: var(--scully-white); + font-size: 1.2em; + opacity: 1; +} + nav.scullyio-nav-header { position: fixed; display: flex; diff --git a/apps/scully-docs/src/app/components/header/component/nav-header/nav-header.component.ts b/apps/scully-docs/src/app/components/header/component/nav-header/nav-header.component.ts index 98471cc40..2b9dc3639 100644 --- a/apps/scully-docs/src/app/components/header/component/nav-header/nav-header.component.ts +++ b/apps/scully-docs/src/app/components/header/component/nav-header/nav-header.component.ts @@ -6,13 +6,13 @@ import { Component, ViewEncapsulation, Input, HostBinding } from '@angular/core' template: ` `, diff --git a/apps/scully-docs/src/app/pages/docs/page/docs.page.component.ts b/apps/scully-docs/src/app/pages/docs/page/docs.page.component.ts index 6eba3b4cc..b63f1b946 100644 --- a/apps/scully-docs/src/app/pages/docs/page/docs.page.component.ts +++ b/apps/scully-docs/src/app/pages/docs/page/docs.page.component.ts @@ -1,6 +1,6 @@ import { Component, ViewEncapsulation } from '@angular/core'; import { Title } from '@angular/platform-browser'; -import { EMPTY } from 'rxjs'; +import { EMPTY, filter } from 'rxjs'; import { catchError, map, tap } from 'rxjs'; import { NavListService } from '../../../components/nav-list/nav-list.service'; @@ -28,13 +28,14 @@ export class DocsPageComponent { currentPage$ = this.nav.currentDoc$.pipe( tap((cur) => { - const title = cur._route?.title as string; + const title = cur?._route?.title as string; if (title) { this.title.setTitle(title + ' - Scully'); } else { this.title.setTitle('Scully Documentation'); } }), + filter(cur => cur?._route !== undefined), map((cur) => ({ next: cur._next, prev: cur._prev, suggestEditLink: this.githubEditLink(cur?._route?.route) })), /** note, this is for testing only, as in the docs site _no_ code will not be there anyway! */ catchError((e) => { diff --git a/apps/scully-docs/src/app/pages/extraPages/extra-page.module.ts b/apps/scully-docs/src/app/pages/extraPages/extra-page.module.ts index 51552005a..e8872e7f7 100644 --- a/apps/scully-docs/src/app/pages/extraPages/extra-page.module.ts +++ b/apps/scully-docs/src/app/pages/extraPages/extra-page.module.ts @@ -1,9 +1,12 @@ import { CommonModule } from '@angular/common'; -import { Component, NgModule } from '@angular/core'; +import { Component, NgModule, ViewEncapsulation } from '@angular/core'; import { RouterModule } from '@angular/router'; import { ScullyLibModule } from '@scullyio/ng-lib'; +import { FooterModule } from '../../components/footer'; +import { FooterComponent } from '../../components/footer/component/footer.component'; @Component({ + encapsulation: ViewEncapsulation.None, template: `
    @@ -12,7 +15,7 @@ import { ScullyLibModule } from '@scullyio/ng-lib'; + diff --git a/libs/plugins/scully-plugin-playwright/src/index.ts b/libs/plugins/scully-plugin-playwright/src/index.ts index 5a10cae99..a09444794 100644 --- a/libs/plugins/scully-plugin-playwright/src/index.ts +++ b/libs/plugins/scully-plugin-playwright/src/index.ts @@ -22,19 +22,18 @@ const plugin = async () => { process.exit(0); }); log(` ${green('✔')} Playwright installation successfully`); -} +}; registerPlugin('beforeAll', 'installPWDeps', plugin); /** enable as default routeRenderer */ registerPlugin('scullySystem', routeRenderer, playwrightRenderer, undefined, { replaceExistingPlugin: true }); /** also add as its own thing, perhaps we want to combine later, or use it differently */ registerPlugin('enterprise', playwrightRender, playwrightRenderer); -registerPlugin('enterprise', 'getPWLaunchedBrowser', async () => launchedBrowser$) +registerPlugin('enterprise', 'getPWLaunchedBrowser', async () => launchedBrowser$); registerPlugin('beforeAll', 'startLaunching the browser', async () => { - logOk('Playwright is being launched') + logOk('Playwright is being launched'); launchedBrowser(); -}) - +}); export { playwrightRender } from './lib/plugins-scully-plugin-playwright'; export type BrowserLaunchOptions = LaunchOptions & { browser: string }; diff --git a/libs/plugins/scully-plugin-playwright/src/lib/plugins-scully-plugin-playwright-utils.ts b/libs/plugins/scully-plugin-playwright/src/lib/plugins-scully-plugin-playwright-utils.ts index b154df95a..7f4461c06 100644 --- a/libs/plugins/scully-plugin-playwright/src/lib/plugins-scully-plugin-playwright-utils.ts +++ b/libs/plugins/scully-plugin-playwright/src/lib/plugins-scully-plugin-playwright-utils.ts @@ -1,8 +1,22 @@ import { loadConfig, logError, logWarn, white, yellow } from '@scullyio/scully'; import { showBrowser } from '@scullyio/scully/src/lib/utils/cli-options'; -import * as playwright from "playwright"; -import { Browser, LaunchOptions } from "playwright"; -import { BehaviorSubject, catchError, delayWhen, filter, from, merge, Observable, of, shareReplay, switchMap, take, throttleTime, timer } from 'rxjs'; +import * as playwright from 'playwright'; +import { Browser, LaunchOptions } from 'playwright'; +import { + BehaviorSubject, + catchError, + delayWhen, + filter, + from, + merge, + Observable, + of, + shareReplay, + switchMap, + take, + throttleTime, + timer, +} from 'rxjs'; const defaultConfig: LaunchOptions = { headless: true, @@ -11,7 +25,6 @@ const defaultConfig: LaunchOptions = { } as any; const options = { ...defaultConfig }; - const launches = new BehaviorSubject(undefined); export let browser: Browser; @@ -44,11 +57,11 @@ export const reLaunch = (reason?: string): Promise => { }; const launch = async (pluginConfig: any): Promise => { - const browserType = pluginConfig.browser + const browserType = pluginConfig.browser; const playrightBrowser = playwright[browserType]; const browser = await playrightBrowser.launch({ headless: pluginConfig.headless, channel: pluginConfig.channel }); return browser; -} +}; export const launchedBrowser$: Observable = of('').pipe( /** load config only after a subscription is made */ switchMap(() => loadConfig()), @@ -153,4 +166,4 @@ https://playwright.dev/docs/troubleshooting `); process.exit(15); }) as unknown as Promise; -} \ No newline at end of file +} diff --git a/libs/plugins/scully-plugin-playwright/src/lib/plugins-scully-plugin-playwright.ts b/libs/plugins/scully-plugin-playwright/src/lib/plugins-scully-plugin-playwright.ts index a26f12336..4a4621688 100644 --- a/libs/plugins/scully-plugin-playwright/src/lib/plugins-scully-plugin-playwright.ts +++ b/libs/plugins/scully-plugin-playwright/src/lib/plugins-scully-plugin-playwright.ts @@ -21,8 +21,8 @@ export const playwrightRenderer = async (route: HandledRoute): Promise = const path = route.rawRoute ? route.rawRoute : scullyConfig.hostUrl - ? `${scullyConfig.hostUrl}${route.route}` - : `http${ssl ? 's' : ''}://${scullyConfig.hostName}:${scullyConfig.appPort}${route.route}`; + ? `${scullyConfig.hostUrl}${route.route}` + : `http${ssl ? 's' : ''}://${scullyConfig.hostName}:${scullyConfig.appPort}${route.route}`; let pageHtml: string; let browser: Browser; let page: Page; @@ -38,7 +38,7 @@ export const playwrightRenderer = async (route: HandledRoute): Promise = const pageReady = new Promise((r) => (resolve = r)); if (scullyConfig.ignoreResourceTypes && scullyConfig.ignoreResourceTypes.length > 0) { - await page.route('**/*', route => checkIfRequestShouldBeIgnored.bind(route.request)); + await page.route('**/*', (route) => checkIfRequestShouldBeIgnored.bind(route.request)); // eslint-disable-next-line no-inner-declarations function checkIfRequestShouldBeIgnored(request) { @@ -144,7 +144,6 @@ export const playwrightRenderer = async (route: HandledRoute): Promise = } else { // await page.close(); page.close(); - } } catch (err) { const { message } = err; diff --git a/libs/plugins/scully-plugin-puppeteer/src/index.ts b/libs/plugins/scully-plugin-puppeteer/src/index.ts index dcbd03a34..b0345ae51 100644 --- a/libs/plugins/scully-plugin-puppeteer/src/index.ts +++ b/libs/plugins/scully-plugin-puppeteer/src/index.ts @@ -4,11 +4,11 @@ import { puppeteerRender } from './lib/plugins-scully-plugin-puppeteer'; import { launchedBrowser$ } from './lib/launchedBrowser'; /** little hack to be able to share the browser instance */ -registerPlugin('enterprise','getPPTLaunchedBrowser',async () => launchedBrowser$) +registerPlugin('enterprise', 'getPPTLaunchedBrowser', async () => launchedBrowser$); /** instead of always starting, now use the beforeAll plugin */ registerPlugin('beforeAll', 'startLaunching the browser', async () => { - logOk('Puppeteer is being launched') + logOk('Puppeteer is being launched'); launchedBrowser(); -}) +}); /** use ppt as 'default' renderer plugin */ registerPlugin('scullySystem', routeRenderer, puppeteerRender); diff --git a/libs/plugins/scully-plugin-puppeteer/src/lib/launchedBrowser.ts b/libs/plugins/scully-plugin-puppeteer/src/lib/launchedBrowser.ts index 3ebf45548..2d839cb81 100644 --- a/libs/plugins/scully-plugin-puppeteer/src/lib/launchedBrowser.ts +++ b/libs/plugins/scully-plugin-puppeteer/src/lib/launchedBrowser.ts @@ -1,6 +1,21 @@ import { cliOptions, loadConfig, logError, logOk, scullyConfig, waitForIt, yellow } from '@scullyio/scully'; import { Browser, launch } from 'puppeteer'; -import { BehaviorSubject, catchError, delayWhen, filter, from, interval, merge, Observable, of, shareReplay, switchMap, take, throttleTime, timer } from 'rxjs'; +import { + BehaviorSubject, + catchError, + delayWhen, + filter, + from, + interval, + merge, + Observable, + of, + shareReplay, + switchMap, + take, + throttleTime, + timer, +} from 'rxjs'; const { showBrowser, serverTimeout } = cliOptions; const launches = new BehaviorSubject(undefined); diff --git a/libs/plugins/scully-plugin-puppeteer/src/lib/plugins-scully-plugin-puppeteer.spec.ts b/libs/plugins/scully-plugin-puppeteer/src/lib/plugins-scully-plugin-puppeteer.spec.ts index c78445d3b..f2fa693b1 100644 --- a/libs/plugins/scully-plugin-puppeteer/src/lib/plugins-scully-plugin-puppeteer.spec.ts +++ b/libs/plugins/scully-plugin-puppeteer/src/lib/plugins-scully-plugin-puppeteer.spec.ts @@ -2,6 +2,6 @@ import { puppeteerRender } from './plugins-scully-plugin-puppeteer'; describe('pluginsScullyPluginPuppeteer', () => { it('should work', () => { - expect(puppeteerRender).toEqual(puppeteerRender) + expect(puppeteerRender).toEqual(puppeteerRender); }); }); diff --git a/libs/plugins/scully-plugin-puppeteer/src/lib/plugins-scully-plugin-puppeteer.ts b/libs/plugins/scully-plugin-puppeteer/src/lib/plugins-scully-plugin-puppeteer.ts index 7be78c191..801aac89b 100644 --- a/libs/plugins/scully-plugin-puppeteer/src/lib/plugins-scully-plugin-puppeteer.ts +++ b/libs/plugins/scully-plugin-puppeteer/src/lib/plugins-scully-plugin-puppeteer.ts @@ -22,16 +22,14 @@ try { // version = jsonc.parse(readFileSync(join(__dirname, '../../../package.json')).toString()).version || '0.0.0'; } - - export const puppeteerRender = async (route: HandledRoute): Promise => { const timeOutValueInSeconds = 25; const pageLoaded = new Subject(); const path = route.rawRoute ? route.rawRoute : scullyConfig.hostUrl - ? `${scullyConfig.hostUrl}${route.route}` - : `http${ssl ? 's' : ''}://${scullyConfig.hostName}:${scullyConfig.appPort}${route.route}`; + ? `${scullyConfig.hostUrl}${route.route}` + : `http${ssl ? 's' : ''}://${scullyConfig.hostName}:${scullyConfig.appPort}${route.route}`; let pageHtml: string; let browser: Browser; @@ -230,4 +228,3 @@ const windowSet = (page: Page, name: string, value: Serializable) => } }) `); - diff --git a/libs/scully/src/index.ts b/libs/scully/src/index.ts index a8efe2309..3331f01e3 100644 --- a/libs/scully/src/index.ts +++ b/libs/scully/src/index.ts @@ -4,7 +4,7 @@ import { getPluginConfig, setConfig, setPluginConfig, - setPluginPriority + setPluginPriority, } from './lib/pluginManagement/pluginConfig'; import { configValidator, registerPlugin } from './lib/pluginManagement/pluginRepository'; import './lib/pluginManagement/systemPlugins'; @@ -67,4 +67,4 @@ export { setConfig as setMyConfig, prod, setPluginPriority, -}; \ No newline at end of file +}; diff --git a/libs/scully/src/lib/fileHanderPlugins/markdown.ts b/libs/scully/src/lib/fileHanderPlugins/markdown.ts index 35af3d280..491100f0d 100644 --- a/libs/scully/src/lib/fileHanderPlugins/markdown.ts +++ b/libs/scully/src/lib/fileHanderPlugins/markdown.ts @@ -1,25 +1,20 @@ import { registerPlugin } from '../pluginManagement/pluginRepository'; import { getConfig, setConfig } from '../pluginManagement/pluginConfig'; import { marked } from 'marked'; +import { logWarn } from '../utils/log'; // ------------------------------ // Syntax Highlighting const Prism = require('prismjs'); -import 'prismjs/components/prism-bash'; import 'prismjs/components/prism-css'; import 'prismjs/components/prism-javascript'; import 'prismjs/components/prism-json'; -import 'prismjs/components/prism-markup'; -import 'prismjs/components/prism-markdown'; import 'prismjs/components/prism-typescript'; -import 'prismjs/components/prism-jsx'; -import 'prismjs/components/prism-tsx'; -import 'prismjs/components/prism-docker'; const renderer = new marked.Renderer(); // wrap code block the way Prism.js expects it -renderer.code = function (this:any ,code, lang, escaped) { +renderer.code = function (this: any, code, lang, escaped) { code = this.options.highlight(code, lang); if (!lang) { return '
    ' + code + '
    '; @@ -42,7 +37,16 @@ const markdownPlugin = async (raw: string) => { highlight: (code, lang) => { lang = lang || 'typescript'; if (!Prism.languages[lang]) { - console.error(`Language '${lang}' is not available in Prism.js, ignoring syntax highlighting for this code block.`); + logWarn(`Notice: + --------------------------------------------------------------------------------------- + Language '${lang}' is not available in the default Prism.js setup. + if you want support for this you can add it into your ScullyConfig.ts as: + + import 'prismjs/components/prism-${lang}' + + Note that this is a sample the actual syntax might be slightly different + --------------------------------------------------------------------------------------- + `); return code; } return Prism.highlight(code, Prism.languages[lang]); diff --git a/libs/scully/src/lib/renderPlugins/executePlugins.ts b/libs/scully/src/lib/renderPlugins/executePlugins.ts index 69b3b789c..03a9e7537 100644 --- a/libs/scully/src/lib/renderPlugins/executePlugins.ts +++ b/libs/scully/src/lib/renderPlugins/executePlugins.ts @@ -1,7 +1,7 @@ import { findPlugin } from '../pluginManagement/pluginConfig'; import { registerPlugin, scullySystem } from '../pluginManagement/pluginRepository'; import { HandledRoute } from '../routerPlugins/handledRoute.interface'; -import { scullyConfig,routeRenderer } from '../utils/config'; +import { scullyConfig, routeRenderer } from '../utils/config'; import { logError, yellow, logWarn } from '../utils/log'; import { captureException } from '../utils/captureMessage'; import { toJSDOM, fromJSDOM } from './jsdomPlugins'; diff --git a/libs/scully/src/lib/routerPlugins/handledRoute.interface.ts b/libs/scully/src/lib/routerPlugins/handledRoute.interface.ts index 3be0c3ca8..850a396e6 100644 --- a/libs/scully/src/lib/routerPlugins/handledRoute.interface.ts +++ b/libs/scully/src/lib/routerPlugins/handledRoute.interface.ts @@ -7,8 +7,9 @@ export interface RouteConfig { /** * an optional function that will be executed on render. * Receives the route string, and the config of this route. + * When it returns false, the route isn't rendered. */ - preRenderer?: (route: HandledRoute) => Promise; + preRenderer?: (route: HandledRoute) => Promise; /** option to select a different render plugin fir this route. */ renderPlugin?: string | symbol; /** Allow in every other setting possible, depends on plugins */ @@ -17,7 +18,7 @@ export interface RouteConfig { export interface HandledRoute { /** the string as used in the Scully config */ - usedConfigRoute?:string; + usedConfigRoute?: string; /** the _complete_ route */ route: string; /** the raw route, will be used by puppeteer over the route.route, will be used as is. must include the http(s):// part and eventual params*/ @@ -55,6 +56,11 @@ export interface HandledRoute { renderPlugin?: string | symbol; } +//TODO: add more of the common frontmatter properties to the interface +/** + * The data that will be added to the route in scully.routes.json. + * The frontmatter data will be added here too. + */ export interface RouteData { title?: string; author?: string; @@ -68,5 +74,5 @@ export interface ContentTextRoute extends HandledRoute { /** the type of content (MD/HTML this determines what plugin us used for render) */ contentType?: string; /** The actual raw content that will be rendered into scully-content */ - content?: string|((route?:HandledRoute)=>string); + content?: string | ((route?: HandledRoute) => string); } diff --git a/libs/scully/src/lib/utils/cli-options.ts b/libs/scully/src/lib/utils/cli-options.ts index a55040ce8..f19fc09c8 100644 --- a/libs/scully/src/lib/utils/cli-options.ts +++ b/libs/scully/src/lib/utils/cli-options.ts @@ -33,7 +33,7 @@ export const { watch, stats, disableProjectFolderCheck, - killServer + killServer, } = /** return the argv */ // eslint-disable-next-line @typescript-eslint/ban-ts-comment diff --git a/libs/scully/src/lib/utils/compileConfig.ts b/libs/scully/src/lib/utils/compileConfig.ts index 597b495f8..14f462dd3 100644 --- a/libs/scully/src/lib/utils/compileConfig.ts +++ b/libs/scully/src/lib/utils/compileConfig.ts @@ -48,9 +48,9 @@ export const compileConfig = async (): Promise => { which will look for package.json instead of angular.json to find the 'root' of the project. ===================================================================================================== `); - return ({ + return { projectName: project || defaultProjectName, - } as unknown) as ScullyConfig; + } as unknown as ScullyConfig; } /** skip compiling if it exists */ const jsFile = getJsName(path); @@ -105,7 +105,7 @@ async function compileUserPluginsAndConfig() { const configPath = findConfigFile(useFolder, sys.fileExists, 'tsconfig.json'); if (!existsSync(join(useFolder, 'tsconfig.json'))) { // no userstuff to handle - logWarn(`Folder "${yellow(folder)}" doesn't seem to contain custom plugins`) + logWarn(`Folder "${yellow(folder)}" doesn't seem to contain custom plugins`); return; } log(` ${green('✔')} Folder "${yellow(folder)}" used for custom plugins`); @@ -144,14 +144,14 @@ async function compileTSConfig(path) { reportDiagnostics: true, moduleName: 'scully', compilerOptions: { - lib: ["ES2020", "dom"], + lib: ['ES2020', 'dom'], module: ModuleKind.CommonJS, target: ScriptTarget.ES2020, allowJs: true, allowSyntheticDefaultImports: true, skipLibCheck: true, - moduleResolution: ModuleResolutionKind.NodeJs - } + moduleResolution: ModuleResolutionKind.NodeJs, + }, }); if (js.diagnostics.length > 0) { logError( diff --git a/libs/scully/src/lib/utils/handlers/renderPlugin.ts b/libs/scully/src/lib/utils/handlers/renderPlugin.ts index 796aa1ee8..a3dafb0d9 100644 --- a/libs/scully/src/lib/utils/handlers/renderPlugin.ts +++ b/libs/scully/src/lib/utils/handlers/renderPlugin.ts @@ -2,7 +2,6 @@ import { registerPlugin, scullySystem } from '../../pluginManagement'; import { HandledRoute } from '../../routerPlugins/handledRoute.interface'; import { renderParallel } from './renderParallel'; - export const renderPlugin = 'renderPlugin' as const; registerPlugin(scullySystem, renderPlugin, defaultRenderPlugin); async function defaultRenderPlugin(handledRoutes: HandledRoute[]) { diff --git a/libs/scully/src/lib/utils/interfacesandenums.ts b/libs/scully/src/lib/utils/interfacesandenums.ts index b5c6d6c41..958c83792 100644 --- a/libs/scully/src/lib/utils/interfacesandenums.ts +++ b/libs/scully/src/lib/utils/interfacesandenums.ts @@ -46,7 +46,7 @@ export interface ScullyConfig { /** optional proxy config file, uses the same config file as the CLI */ proxyConfig?: string; /** optional launch-options for puppeteer */ - puppeteerLaunchOptions?: PuppeteerNodeLaunchOptions; /** hostname to use for local server, defaults to `localhost` */ + puppeteerLaunchOptions?: PuppeteerNodeLaunchOptions /** hostname to use for local server, defaults to `localhost` */; hostName?: string; /** optional hostURL, if this is provided, we are going to use this server instead of the build-in one. */ hostUrl?: string; diff --git a/libs/scully/src/lib/utils/platform-server/index.ts b/libs/scully/src/lib/utils/platform-server/index.ts index 1f33d7b47..525ca3b75 100644 --- a/libs/scully/src/lib/utils/platform-server/index.ts +++ b/libs/scully/src/lib/utils/platform-server/index.ts @@ -1,4 +1,4 @@ // export * from './ps-runner'; -export { enableSPS } from './startupSpS' -export { Deferred } from './deferred' -export { SPSRouteRenderer } from './serverPlatformRender' +export { enableSPS } from './startupSpS'; +export { Deferred } from './deferred'; +export { SPSRouteRenderer } from './serverPlatformRender'; diff --git a/libs/scully/src/lib/utils/platform-server/serverPlatformRender.ts b/libs/scully/src/lib/utils/platform-server/serverPlatformRender.ts index 8603f4e07..37457977c 100644 --- a/libs/scully/src/lib/utils/platform-server/serverPlatformRender.ts +++ b/libs/scully/src/lib/utils/platform-server/serverPlatformRender.ts @@ -1,10 +1,17 @@ import { existsSync } from 'fs'; import { performance } from 'perf_hooks'; import { - determineConfigFilePath, getJsName, - getPool, handleJobs, Job, logError, logOk, orange, + determineConfigFilePath, + getJsName, + getPool, + handleJobs, + Job, + logError, + logOk, + orange, performanceIds, - printProgress, scullyConfig + printProgress, + scullyConfig, } from '..'; import { registerPlugin } from '../../pluginManagement'; import { HandledRoute } from '../../routerPlugins'; @@ -52,7 +59,6 @@ async function spsPoolInitPlugin(path) { performance.mark('stopplugin-serverPlatformWarmUp'); } - export const SPSRouteRenderer = 'SPSRouteRenderer' as const; export const SPSRenderer = 'SPSRenderer' as const; registerPlugin('scullySystem', SPSRenderer, renderWithSpSPlugin); diff --git a/libs/scully/src/lib/utils/platform-server/startupSpS.ts b/libs/scully/src/lib/utils/platform-server/startupSpS.ts index 079b925e5..1606ee08f 100644 --- a/libs/scully/src/lib/utils/platform-server/startupSpS.ts +++ b/libs/scully/src/lib/utils/platform-server/startupSpS.ts @@ -11,71 +11,69 @@ import { readDotProperty } from '../scullydot'; import { Deferred } from './deferred'; import { initSpSPool, SPSRenderer } from './serverPlatformRender'; -const workerPath = join(__dirname, 'ps-worker.js') +const workerPath = join(__dirname, 'ps-worker.js'); const tsConfig = { - "extends": "../tsconfig.json", - "compilerOptions": { - "outDir": "runtime", - "target": "es2020", - "allowJs": true, - "allowSyntheticDefaultImports": true, - "skipDefaultLibCheck": true, - "skipLibCheck": true, - "lib": ["ES2020", "DOM"], - "types": ["node"], - "moduleResolution": "Node", - "module": "CommonJS" + extends: '../tsconfig.json', + compilerOptions: { + outDir: 'runtime', + target: 'es2020', + allowJs: true, + allowSyntheticDefaultImports: true, + skipDefaultLibCheck: true, + skipLibCheck: true, + lib: ['ES2020', 'DOM'], + types: ['node'], + moduleResolution: 'Node', + module: 'CommonJS', }, - "files": [], - "angularCompilerOptions": { - "enableIvy": true, - "compilationMode": "partial" - } -} - + files: [], + angularCompilerOptions: { + enableIvy: true, + compilationMode: 'partial', + }, +}; const plugin = async () => { /** check if I'm a worker, and import the runner. */ if (process.env.SCULLY_WORKER === 'true') { process.title = 'ScullyWorker'; /** worker will pick up its in a worker and starts itself */ - const worker = await import('./ps-worker') - .catch(e => { - console.log('worker module load error', e) - logError(e) - process.exit(16); - }); + const worker = await import('./ps-worker').catch((e) => { + console.log('worker module load error', e); + logError(e); + process.exit(16); + }); } else { - const { sourceRoot, homeFolder, spsModulePath } = scullyConfig + const { sourceRoot, homeFolder, spsModulePath } = scullyConfig; if (spsModulePath === undefined) { - logError(`For the SPS renderer the option "spsModulePath" needs to be part of your projects scullyConfig. Aborting run`) - process.exit(15) + logError(`For the SPS renderer the option "spsModulePath" needs to be part of your projects scullyConfig. Aborting run`); + process.exit(15); } const fullSps = join(homeFolder, spsModulePath); if (!existsSync(fullSps)) { - logError(`file "${yellow(fullSps)}" doesn't seem to exists, this is mandatory for the SPS renderer`) - process.exit(15) + logError(`file "${yellow(fullSps)}" doesn't seem to exists, this is mandatory for the SPS renderer`); + process.exit(15); } const persistentFolder = readDotProperty('pluginFolder') || './scully'; const scullyPath = join(homeFolder, persistentFolder); const outDir = join(scullyPath, 'runtime'); const tsConfigPath = join(scullyPath, `tsconfig.${scullyConfig.projectName}.json`); - const modulePath = fullSps.replace(homeFolder, '..') + const modulePath = fullSps.replace(homeFolder, '..'); if (!existsSync(tsConfigPath)) { // tsConfig.compilerOptions.outDir = outDir; tsConfig.files.push(modulePath); writeFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2)); log(` ${green('✔')} created ${yellow(tsConfigPath)}`); } - printProgress(true, 'compiling application') + printProgress(true, 'compiling application'); rmSync(outDir, { recursive: true, force: true }); await runScript(`npx ngc -p "${tsConfigPath}"`).catch(() => { logError(`Couldn't compile ${yellow(modulePath)}. Please fix the above errors in the app, and run Scully again.`); process.exit(0); }); log(` ${green('✔')} Angular application compiled successfully`); - printProgress(false, 'starting workers') + printProgress(false, 'starting workers'); await startPSRunner(); // process.exit(0); @@ -115,22 +113,20 @@ async function startPSRunner() { misses: 0, }; await findPlugin(initSpSPool)(workerPath); - const pool = getPool(workerPath) + const pool = getPool(workerPath); - getHandledRoutes().then(routes => { + getHandledRoutes().then((routes) => { // every worker needs a copy od the HanderRoutes[] - const sendRoutes = pool.map(() => new Job('setHandledRoutes', routes)) - return handleJobs(sendRoutes, pool) - }) + const sendRoutes = pool.map(() => new Job('setHandledRoutes', routes)); + return handleJobs(sendRoutes, pool); + }); const cache = new Map>(); setupCacheListener(); async function setupCacheListener() { try { await loadConfig(); - const listenAll$ = merge(...pool.map((w) => w.messages$)) - const listenCache$ = listenAll$.pipe( - filter(({ msg }) => Array.isArray(msg) && msg[0].startsWith('cache')) - ); + const listenAll$ = merge(...pool.map((w) => w.messages$)); + const listenCache$ = listenAll$.pipe(filter(({ msg }) => Array.isArray(msg) && msg[0].startsWith('cache'))); const idChecks$ = listenCache$.pipe( filter(({ msg }) => msg[0] === 'cacheHas'), @@ -142,16 +138,18 @@ async function startPSRunner() { worker.send('cacheResult', false); return; } - cache.get(id).promise.then((cacheItem) => { - cacheStats.hits += 1; - worker.send('cacheResult', cacheItem); - }).catch((e) => { - logError(e); - }); + cache + .get(id) + .promise.then((cacheItem) => { + cacheStats.hits += 1; + worker.send('cacheResult', cacheItem); + }) + .catch((e) => { + logError(e); + }); }) ); - const idSetCacheItems$ = listenCache$.pipe( filter(({ msg }) => msg[0] === 'cacheSet'), tap(({ worker, msg }) => { @@ -171,4 +169,3 @@ async function startPSRunner() { } } } - diff --git a/libs/scully/src/lib/utils/scullydot.ts b/libs/scully/src/lib/utils/scullydot.ts index 413f5adb4..9d14c0cd9 100644 --- a/libs/scully/src/lib/utils/scullydot.ts +++ b/libs/scully/src/lib/utils/scullydot.ts @@ -56,13 +56,13 @@ export const writeDotProps = (dotProps: Partial) => { writeFileSync(file, dump({ ...state.dotProps, ...dotProps })); }; -export const readAllDotProps = (forceRefresh=false): DotProps => { +export const readAllDotProps = (forceRefresh = false): DotProps => { if (forceRefresh || !state.dotProps) { - const file = join(dotFolder, 'settings.yml'); //? - if (!existsSync(file)) { - return undefined; - } - state.dotProps = load(readFileSync(file).toString('utf-8')) as DotProps; + const file = join(dotFolder, 'settings.yml'); //? + if (!existsSync(file)) { + return undefined; + } + state.dotProps = load(readFileSync(file).toString('utf-8')) as DotProps; } /** return deep clone */ return JSON.parse(JSON.stringify(state.dotProps)); @@ -113,11 +113,7 @@ function createIndefier() { */ export const askUser = (question: string): Promise => { return new Promise((resolve, reject) => { - if ( - noPrompt || - process.stdout?.cursorTo === undefined || - process.env.SCULLY_WORKER === 'true' - ) { + if (noPrompt || process.stdout?.cursorTo === undefined || process.env.SCULLY_WORKER === 'true') { /** no input possible in CI/CD a worker or when opted out. */ return resolve(undefined); } diff --git a/libs/scully/src/lib/utils/startup/scullyInit.ts b/libs/scully/src/lib/utils/startup/scullyInit.ts index 8280998f0..513ecdff2 100644 --- a/libs/scully/src/lib/utils/startup/scullyInit.ts +++ b/libs/scully/src/lib/utils/startup/scullyInit.ts @@ -1,6 +1,27 @@ import open from 'open'; import { join } from 'path'; -import { captureException, green, hostName, httpGetJson, installExitHandler, isPortTaken, loadConfig, log, logError, logWarn, moveDistAngular, openNavigator, removeStaticDist, ScullyConfig, scullyDefaults, ssl, startScully, waitForServerToBeAvailable, watch, yellow } from '../'; +import { + captureException, + green, + hostName, + httpGetJson, + installExitHandler, + isPortTaken, + loadConfig, + log, + logError, + logWarn, + moveDistAngular, + openNavigator, + removeStaticDist, + ScullyConfig, + scullyDefaults, + ssl, + startScully, + waitForServerToBeAvailable, + watch, + yellow, +} from '../'; import { findPlugin } from '../../pluginManagement'; import { project } from '../cli-options'; import { routeRenderer } from '../config'; @@ -11,8 +32,7 @@ import { bootServe, isBuildThere, watchMode } from './watchMode'; export const scullyInit = async () => { installExitHandler(); /** make sure not to do something before the config is ready */ - let { err, scullyConfig }: { err: any; scullyConfig: ScullyConfig; } = await getConfig(); - + let { err, scullyConfig }: { err: any; scullyConfig: ScullyConfig } = await getConfig(); if (err) { captureException(err); @@ -24,7 +44,6 @@ export const scullyInit = async () => { scullyConfig.hostName = hostName; } - updateDotProps(scullyConfig); /** @@ -33,7 +52,6 @@ export const scullyInit = async () => { */ await checkIfRenderPluginIsLoaded(scullyConfig); - /** check if the dist folder containes a build */ await isBuildThere(scullyConfig); @@ -58,10 +76,12 @@ You are using "${yellow(scullyConfig.hostUrl)}" as server. // debug only log(` ${green('✔')} scully serve already running`); } - if (!(await waitForServerToBeAvailable().catch((e) => { - console.error(e); - return false - }))) { + if ( + !(await waitForServerToBeAvailable().catch((e) => { + console.error(e); + return false; + })) + ) { logError('Could not connect to server'); process.exit(15); } @@ -77,7 +97,6 @@ You are using "${yellow(scullyConfig.hostUrl)}" as server. /** done, stop the program */ process.exit(0); } - }; async function checkIfRenderPluginIsLoaded(scullyConfig: ScullyConfig) { @@ -85,7 +104,6 @@ async function checkIfRenderPluginIsLoaded(scullyConfig: ScullyConfig) { if (!findPlugin(routeRenderer, undefined, false)) { try { await import(pluginName); - } catch { logError(` Notice: ============================================================ @@ -94,7 +112,7 @@ async function checkIfRenderPluginIsLoaded(scullyConfig: ScullyConfig) { and try again. ============================================================`); process.exit(15); - }; + } logWarn(` Deprication Notice: ====================================================================== From now on, the plugin that is being used to render a route is @@ -140,7 +158,7 @@ export async function startServer() { } await killScullyServer(false); updateDotProps(scullyConfig); - await new Promise(r => setTimeout(() => r(), 2500)); + await new Promise((r) => setTimeout(() => r(), 2500)); } await bootServe(); if (openNavigator) { @@ -158,7 +176,6 @@ export async function prepServe() { await killScullyServer(false); updateDotProps(scullyConfig); process.exit(0); - } export async function killScullyServer(doesExit = true) { @@ -187,7 +204,6 @@ export async function killScullyServer(doesExit = true) { logWarn('Sent kill command to other server'); } - export function updateDotProps(scullyConfig) { const dotProps = readAllDotProps(); const newProps: Partial = { @@ -210,4 +226,4 @@ export function updateDotProps(scullyConfig) { writeDotProperty(prop, value); } }); -}; +} diff --git a/libs/scully/src/lib/utils/waitForIt.ts b/libs/scully/src/lib/utils/waitForIt.ts index cfca50e68..2baaeac0c 100644 --- a/libs/scully/src/lib/utils/waitForIt.ts +++ b/libs/scully/src/lib/utils/waitForIt.ts @@ -1,4 +1,3 @@ - export function waitForIt(milliSeconds: number) { return new Promise((resolve) => setTimeout(() => resolve(), milliSeconds)); } diff --git a/libs/scully/src/scully.ts b/libs/scully/src/scully.ts index 1483a9ce8..b12eef4ec 100644 --- a/libs/scully/src/scully.ts +++ b/libs/scully/src/scully.ts @@ -17,7 +17,7 @@ process.title = 'Scully'; yargs(process.argv.slice(2)) .command(['version'], 'Get the Scully version', () => { - const { version } = JSON.parse(readFileSync(join(__dirname, './package.json')).toString()); + const { version } = JSON.parse(readFileSync(join(__dirname, '../package.json')).toString()); console.log(`Scully version : ${version}`); process.exit(0); }) @@ -28,7 +28,4 @@ yargs(process.argv.slice(2)) .command(['$0'], 'start processing the app', scullyInit) .demandCommand() .help() - .wrap(92) - .argv - - + .wrap(92).argv; diff --git a/scully.pw-sample-blog.config.ts b/scully.pw-sample-blog.config.ts index 4e21854a8..e7df944af 100644 --- a/scully.pw-sample-blog.config.ts +++ b/scully.pw-sample-blog.config.ts @@ -1,4 +1,13 @@ -import { ContentTextRoute, HandledRoute, httpGetJson, logError, registerPlugin, RouteConfig, ScullyConfig, setPluginConfig } from '@scullyio/scully'; +import { + ContentTextRoute, + HandledRoute, + httpGetJson, + logError, + registerPlugin, + RouteConfig, + ScullyConfig, + setPluginConfig, +} from '@scullyio/scully'; import { baseHrefRewrite } from '@scullyio/scully-plugin-base-href-rewrite'; import { docLink } from '@scullyio/scully-plugin-docs-link-update'; import '@scullyio/scully-plugin-extra'; @@ -154,17 +163,18 @@ export const config: Promise = (async () => { })(); registerPlugin('postProcessByDom', 'rawTest', async (dom: JSDOM, r: HandledRoute) => { - const { window: { document } } = dom; + const { + window: { document }, + } = dom; const content = (await httpGetJson(r.config.url, { headers: { contentType: 'text/html', - expectedContentType: 'text/html' - } + expectedContentType: 'text/html', + }, })) as string; document.write(content); return dom; -}) - +}); registerPlugin('router', 'rawTest', async (route, options: RouteConfig) => { return [{ route, type: 'rawTest', rawRoute: options?.url ?? 'https://scully.io/', manualIdleCheck: true }]; diff --git a/scully.sample-blog.config.ts b/scully.sample-blog.config.ts index 68f05890d..f69c82298 100644 --- a/scully.sample-blog.config.ts +++ b/scully.sample-blog.config.ts @@ -1,6 +1,17 @@ /** load the plugins */ // import './demos/plugins/extra-plugin.js'; -import { SPSRouteRenderer, ContentTextRoute, enableSPS, HandledRoute, httpGetJson, logError, registerPlugin, RouteConfig, ScullyConfig, setPluginConfig } from '@scullyio/scully'; +import { + SPSRouteRenderer, + ContentTextRoute, + enableSPS, + HandledRoute, + httpGetJson, + logError, + registerPlugin, + RouteConfig, + ScullyConfig, + setPluginConfig, +} from '@scullyio/scully'; import { baseHrefRewrite } from '@scullyio/scully-plugin-base-href-rewrite'; import { docLink } from '@scullyio/scully-plugin-docs-link-update'; import '@scullyio/scully-plugin-extra'; @@ -12,9 +23,6 @@ import './demos/plugins/errorPlugin'; import './demos/plugins/tocPlugin'; import './demos/plugins/voidPlugin'; - - - // import { theVaultReady } from '@herodevs/scully-plugin-the-vault'; const FlashPrevention = getFlashPreventionPlugin(); @@ -178,17 +186,18 @@ export const config: Promise = (async () => { })(); registerPlugin('postProcessByDom', 'rawTest', async (dom: JSDOM, r: HandledRoute) => { - const { window: { document } } = dom; + const { + window: { document }, + } = dom; const content = (await httpGetJson(r.config.url, { headers: { contentType: 'text/html', - expectedContentType: 'text/html' - } + expectedContentType: 'text/html', + }, })) as string; document.write(content); return dom; -}) - +}); registerPlugin('router', 'rawTest', async (route, options: RouteConfig) => { return [{ route, type: 'rawTest', rawRoute: options?.url ?? 'https://scully.io/', manualIdleCheck: true }]; diff --git a/scully.scully-docs.config.ts b/scully.scully-docs.config.ts index 3499bd1ad..1f7f27c2f 100644 --- a/scully.scully-docs.config.ts +++ b/scully.scully-docs.config.ts @@ -1,11 +1,20 @@ -import { SPSRouteRenderer, prod, scullyConfig, registerPlugin, ScullyConfig, setPluginConfig, log, logError, enableSPS } from '@scullyio/scully'; +import { + SPSRouteRenderer, + prod, + scullyConfig, + registerPlugin, + ScullyConfig, + setPluginConfig, + log, + logError, + enableSPS, +} from '@scullyio/scully'; import { docLink } from '@scullyio/scully-plugin-docs-link-update'; import { GoogleAnalytics } from '@scullyio/scully-plugin-google-analytics'; import { LogRocket } from '@scullyio/scully-plugin-logrocket'; import { Sentry } from '@scullyio/scully-plugin-sentry'; import { copyToClipboard } from '@scullyio/scully-plugin-copy-to-clipboard'; import { removeScripts, RemoveScriptsConfig } from '@scullyio/scully-plugin-remove-scripts'; -import { renderOnce } from './scully/plugins/render-once'; const { marked } = require('marked'); import { readFileSync } from 'fs-extra'; @@ -14,12 +23,18 @@ import { loadRenderer } from './scully/loadRenderer'; // import { criticalCSS } from '@scullyio/scully-plugin-critical-css'; // import { localCacheReady } from '@scullyio/scully-plugin-local-cache'; +import 'prismjs/components/prism-yaml'; +import 'prismjs/components/prism-docker'; +import 'prismjs/components/prism-bash'; +import 'prismjs/components/prism-markdown'; +import { join } from 'path'; +import { cpus } from 'os'; + const { window } = new JSDOM(''); const { document } = window; -global.console.log = (first, ...args) => log(typeof first === 'string' ? first.slice(0, 120) : first, ...args); -global.console.error = (first, ...args) => logError(String(first).slice(0, 60)); - +// global.console.log = (first, ...args) => log(typeof first === 'string' ? first.slice(0, 120) : first, ...args); +// global.console.error = (first, ...args) => logError(String(first).slice(0, 60)); // const jsdom = require('jsdom'); // conFst { JSDOM } = jsdom; @@ -73,6 +88,7 @@ async function createConfig(): Promise { spsModulePath: './apps/scully-docs/src/app/app.sps.module.ts', defaultPostRenderers, // extraRoutes: [], + maxRenderThreads: cpus().length * 2, routes: { '/docs/:slug': { type: 'contentFolder', @@ -85,11 +101,12 @@ async function createConfig(): Promise { type: 'default', postRenderers: ['contentText'], contentType: 'html', - content: () => `` + content: () => + ``, }, '/ngconf': { type: 'default', - postRenderers: ['contentText'], + postRenderers: ['contentText', ...defaultPostRenderers], contentType: 'md', content: () => { return `# Ng-Conf 2021 @@ -107,6 +124,17 @@ async function createConfig(): Promise { `; }, }, + '/support': { + type: 'default', + postRenderers: ['contentText', ...defaultPostRenderers], + contentType: 'md', + content: async () => { + const fm: any = await import('front-matter'); + const contentFile = join(scullyConfig.homeFolder, 'docs_extraPages/support.md'); + const { body } = fm(readFileSync(contentFile).toString('utf-8')); + return body; + }, + }, }, puppeteerLaunchOptions: { defaultViewport: null, @@ -132,8 +160,7 @@ registerPlugin('postProcessByDom', 'docs-toc', async (dom, route) => { document.head.appendChild(meta); try { document.querySelector('scully-content').parentNode.appendChild(tocDiv); - } - catch (e) { } + } catch (e) {} return dom; function createLi([id, desc]) { @@ -153,7 +180,9 @@ function getHeadings(content: string): [string, string][] { ].map((e) => e.trim().toLowerCase()); return content .split('\n') - .filter((line) => line.startsWith('#') && !exceptions.some((exception) => line.toLowerCase().includes(exception.toLowerCase().trim()))) + .filter( + (line) => line.startsWith('#') && !exceptions.some((exception) => line.toLowerCase().includes(exception.toLowerCase().trim())) + ) .map((line) => { const outer = document.createElement('div'); outer.innerHTML = marked(line.trim()); @@ -181,5 +210,5 @@ registerPlugin('postProcessByHtml', 'critters', async (html, route) => { inlineFonts: true, }); - return await critter.process(html) -}) + return await critter.process(html); +}); diff --git a/scully.sps-sample.config.ts b/scully.sps-sample.config.ts index 8331a3acb..b79f108ee 100644 --- a/scully.sps-sample.config.ts +++ b/scully.sps-sample.config.ts @@ -49,13 +49,14 @@ export const config: ScullyConfig = { }, }; - registerPlugin('postProcessByHtml', 'blah', async (html, route) => { return html.replace('

    ', '

    blah '); }); registerPlugin('postProcessByDom', 'addMyToc', async (dom: JSDOM, route: HandledRoute) => { - const { window: { document } } = dom; + const { + window: { document }, + } = dom; const toc = document.createElement('ul'); toc.classList.add('toc'); const h2 = Array.from(document.querySelectorAll('h2')); diff --git a/scully/loadRenderer.ts b/scully/loadRenderer.ts index 56413eed5..337a3c989 100644 --- a/scully/loadRenderer.ts +++ b/scully/loadRenderer.ts @@ -6,21 +6,20 @@ export const loadRenderer = async () => { .env('SCULLY') .choices('rnd', ['ppt', 'pw', 'sps']) .default('rnd', 'sps') - .describe('rnd', 'determine how 404 is handled') - .argv; - logOk('Selected', rnd) + .describe('rnd', 'determine how 404 is handled').argv; + // logOk('Selected', rnd); switch (rnd) { case 'ppt': - await import('@scullyio/scully-plugin-puppeteer') - logOk('Using Puppeteer to render pages') + await import('@scullyio/scully-plugin-puppeteer'); + // logOk('Using Puppeteer to render pages'); break; case 'pw': - await import('@scullyio/scully-plugin-playwright') - logOk('Using Playwright to render pages') + await import('@scullyio/scully-plugin-playwright'); + // logOk('Using Playwright to render pages'); break; case `sps`: - enableSPS() - logOk('Using Scully Platform Server to render pages') + enableSPS(); + // logOk('Using Scully Platform Server to render pages'); break; default: throw new Error(`Unknown renderer ${rnd}`); diff --git a/tests/jest/src/__tests__/docsThere.spec.ts b/tests/jest/src/__tests__/docsThere.spec.ts index 3ead53a76..aaf99ea29 100644 --- a/tests/jest/src/__tests__/docsThere.spec.ts +++ b/tests/jest/src/__tests__/docsThere.spec.ts @@ -146,10 +146,8 @@ function getHeadings(content: string) { 'my blog post', 'heading 1 ### subheading 1 ## heading 2 ### subheading 2', '# first build your app, as Scully still needs the static artifacts', - '# run Scully' - ].map((e) => - e.trim().toLowerCase() - ); + '# run Scully', + ].map((e) => e.trim().toLowerCase()); return content .split('\n') .map((line) => line.trim()) diff --git a/tools/bumpAndTag.ts b/tools/bumpAndTag.ts index 4330d6e4b..69f703674 100644 --- a/tools/bumpAndTag.ts +++ b/tools/bumpAndTag.ts @@ -1,18 +1,17 @@ -import { Octokit } from "@octokit/rest"; +import { Octokit } from '@octokit/rest'; import { writeFileSync } from 'fs'; import { join } from 'path'; import simpleGit, { SimpleGit, SimpleGitOptions } from 'simple-git'; import { dryRun, green, main, newVersion, releaseType, yellow } from './cmdLineOptions.js'; import { folder, getPublishableProjects, readJson } from './utils.js'; -const pat = (process.env.BOT_PAT); -const repo = (process.env.REPO_NAME); +const pat = process.env.BOT_PAT; +const repo = process.env.REPO_NAME; const octokit = new Octokit({ auth: pat, - baseUrl: "https://api.github.com", + baseUrl: 'https://api.github.com', userAgent: 'Scully-Bot', -}) - +}); if (dryRun) { console.log( @@ -33,7 +32,10 @@ for (const pkg of currentVersions) { process.exit(15); } if (!dryRun) { - writeFileSync(join(folder, pkg.root, 'package.json'), JSON.stringify({ ...originalPackage, version: newVersion }, undefined, 2)); + writeFileSync( + join(folder, pkg.root, 'package.json'), + JSON.stringify({ ...originalPackage, version: newVersion }, undefined, 2) + ); writeFileSync(join(folder, pkg.dist, 'package.json'), JSON.stringify({ ...distPackage, version: newVersion }, undefined, 2)); } } @@ -72,8 +74,6 @@ if (!dryRun) { await octokit.request(`POST /repos/${repo}/releases`, { tag_name: `v${newVersion}`, generate_release_notes: true, - draft: true - }) - + draft: true, + }); } - diff --git a/tools/listVersions.ts b/tools/listVersions.ts new file mode 100644 index 000000000..1051be1b2 --- /dev/null +++ b/tools/listVersions.ts @@ -0,0 +1,10 @@ +import { join } from 'node:path'; +import { folder, getPublishableProjects, readJson } from './utils.js'; + +const currentVersions = await getPublishableProjects(); + +for (const pkg of currentVersions) { + const locOrg = join(folder, './', pkg.root, 'package.json'); + const { name, version } = readJson(locOrg); + console.log(`${name}@${version}`); +} diff --git a/tools/publishCurrent.ts b/tools/publishCurrent.ts index 70f07e67d..d8ab5a79c 100644 --- a/tools/publishCurrent.ts +++ b/tools/publishCurrent.ts @@ -8,22 +8,18 @@ const require = createRequire(import.meta.url); const { inc, prerelease, parse } = require('semver'); const minimist = require('minimist'); - - const currentVersions = await getPublishableProjects(); /** read the main package version */ - if (dryRun) { console.log( - `doing a dry run to publish current version, under ${yellow(preReleaseTrain ? 'next' : 'latest')} tag, no changes will be made to do an actual release add the ${yellow( - '--doActualPublish' - )} cmd line option\n` + `doing a dry run to publish current version, under ${yellow( + preReleaseTrain ? 'next' : 'latest' + )} tag, no changes will be made to do an actual release add the ${yellow('--doActualPublish')} cmd line option\n` ); } - for (const pkg of currentVersions) { const originalPackage = readJson(join(folder, pkg.root, 'package.json')); const distPackage = readJson(join(folder, pkg.dist, 'package.json')); diff --git a/tools/publishLocal.ts b/tools/publishLocal.ts index 81900b56f..4d71a9391 100644 --- a/tools/publishLocal.ts +++ b/tools/publishLocal.ts @@ -14,12 +14,11 @@ const timeStamp = new Date() await checkAndPublishChangedPackages(); async function checkAndPublishChangedPackages() { - const currentVersions = await getPublishableProjects(); try { for (const pkg of currentVersions) { // console.dir(pkg) - updateAndPublish(pkg) + updateAndPublish(pkg); } } catch (e) { console.error(e); @@ -29,7 +28,7 @@ async function checkAndPublishChangedPackages() { async function updateAndPublish(toRelease: ReleaseData) { try { const pkgPath = join(folder, toRelease.dist, 'package.json'); - const original = (readFileSync(pkgPath) as unknown) as string; + const original = readFileSync(pkgPath) as unknown as string; const pkg = JSON.parse(original); const tag = 'latest'; // pkg.version = `${newVersion}`; @@ -44,4 +43,3 @@ async function updateAndPublish(toRelease: ReleaseData) { // while ! echo exit | nc localhost 13000; do sleep 10; done // npm publish --registry http://localhost:4873/ - diff --git a/tools/publishPackage.ts b/tools/publishPackage.ts index 12ada1e7b..cf42cb6be 100644 --- a/tools/publishPackage.ts +++ b/tools/publishPackage.ts @@ -3,15 +3,13 @@ import { join } from 'path'; import { yellow, green } from './cmdLineOptions.js'; import { folder, ReleaseData } from './utils.js'; - - export async function publishPackage(tag: string, toRelease: ReleaseData, dryRun = true, local = true) { - let cmd = `npm publish --access public --ignore-scripts --tag ${tag}` + let cmd = `npm publish --access public --ignore-scripts --tag ${tag}`; if (dryRun) { - cmd = `${cmd} --dry-run` + cmd = `${cmd} --dry-run`; } if (local) { - cmd = `${cmd} --registry http://localhost:4873/` + cmd = `${cmd} --registry http://localhost:4873/`; } const { nodeError, stdOut, stdErr } = await new Promise((resolve, reject) => {