Skip to content

Commit

Permalink
Migrate new packages -> need esm
Browse files Browse the repository at this point in the history
This breaks ncc / node because of __dirname use
Maybe try again when this issue is closed:
vercel/ncc#749
  • Loading branch information
almeric committed Mar 5, 2024
1 parent 111d0b7 commit c994a48
Show file tree
Hide file tree
Showing 16 changed files with 264,313 additions and 268,819 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
Expand Down Expand Up @@ -115,4 +114,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

.github/
critical-conf.json
/.github/
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ inputs:
required: true

runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'
branding:
icon: 'package'
Expand Down
75 changes: 0 additions & 75 deletions dist/.svgo.yml

This file was deleted.

116 changes: 116 additions & 0 deletions dist/49c83d9b5dbe016e619d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { URL } from 'url';
import * as core from '@actions/core';
import { getInput } from './config.js';
import { generate } from 'critical';
import nodeRsync from 'rsyncwrapper';
import fs from 'fs';

const cleanOldCriticalFiles = async (options) => {
core.startGroup('Clean up');
fs.mkdirSync(options.src);
nodeRsync(
options,
(error, stdout, stderr, cmd) => {
if (error) {
core.error(error);
core.error(stdout);
core.error(stderr);
core.error(cmd);
process.exit(1);
} else {
core.info('Rsync cleanup finished');
core.info(stdout);
}
}
);
core.endGroup();
};

const generateCriticalCSS = async (input) => {
const __filename = new URL('', import.meta.url).pathname;
const __dirname = new URL('.', import.meta.url).pathname;

for (let page of input.paths) {

const pageUrl = new URL(`${input.baseUrl}${page.url}`);
const criticalDest =
input.destinationPath + page.template + '_critical.min.css';

core.info(`Generating critical CSS: ${pageUrl.href} -> ${criticalDest}`);

await generate({
src: pageUrl.href,
target: criticalDest,
inline: false,
ignore: [],
// minify: true,
dimensions: [
{
width: 375,
height: 667
},
{
width: 1440,
height: 1280
}
]
});
}
};

const main = async () => {
core.startGroup('Action config');
const input = getInput();
process.env.PUPPETEER_EXECUTABLE_PATH = input.browserPath;

let options = {
src: input.destinationPath,
dest: `${input.syncOptions.sshHost}:${input.syncOptions.targetDir}`,
args: ['-azhcvv'],
delete: true,
ssh: true,
port: input.syncOptions.sshPort
};

if (input.syncOptions.sshPrivateKeyPath.length) {
options['privateKey'] = input.syncOptions.sshPrivateKeyPath;
}

core.endGroup(); // Action config

await cleanOldCriticalFiles(options);

core.startGroup('Start Critical CSS');
await generateCriticalCSS(input);
core.endGroup();

if (input.shouldSync) {
core.startGroup(
`Starting Rsync ${input.destinationPath} -> ${input.syncOptions.targetDir}`
);

nodeRsync(
options,
(error, stdout, stderr, cmd) => {
if (error) {
core.error(error);
core.error(stdout);
core.error(stderr);
core.error(cmd);
process.exit(1);
} else {
core.info('Rsync finished');
core.info(stdout);
}
}
);
core.endGroup();
}
};

main()
.catch((err) => {
core.setFailed(err.message);
process.exit(1);
})
.then(() => core.debug(`done in ${process.uptime()}s`));
Loading

0 comments on commit c994a48

Please sign in to comment.