Skip to content

Commit

Permalink
feat: replace 'js' and 'css' eik.json keys with 'entrypoints'
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalsadhu committed Aug 19, 2020
1 parent 8b300b6 commit 0c21253
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 331 deletions.
20 changes: 3 additions & 17 deletions classes/publish/package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ module.exports = class PublishApp {
name,
version = '1.0.0',
map = [],
js,
css,
entrypoints,
dryRun = false,
out = './.eik',
} = {}) {
Expand All @@ -33,19 +32,7 @@ module.exports = class PublishApp {
this.name = name;
this.version = version;
this.map = map;

this.js = js;
if (typeof js === 'string') {
this.js = {
'./index.js': js,
};
}
this.css = css;
if (typeof css === 'string') {
this.css = {
'./index.css': css,
};
}
this.entrypoints = entrypoints;
this.dryRun = dryRun;
this.out = out;
this.path = isAbsolute(out) ? out : join(cwd, out);
Expand All @@ -68,8 +55,7 @@ module.exports = class PublishApp {

const incoming = {
path: this.path,
js: this.js,
css: this.css,
entrypoints: this.entrypoints,
server: this.server,
name: this.name,
version: this.version,
Expand Down
26 changes: 5 additions & 21 deletions classes/publish/package/tasks/check-bundle-sizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,15 @@ const Task = require('./task');

module.exports = class CheckBundleSizes extends Task {
async process(incoming = {}, outgoing = {}) {
const { js, css, cwd } = incoming;
const { entrypoints, cwd } = incoming;
this.log.debug('Checking bundle file sizes');
try {
if (js) {
for (const [key, val] of Object.entries(js)) {
if (entrypoints) {
for (const [key, val] of Object.entries(entrypoints)) {
const path = isAbsolute(val) ? val : join(cwd, val);
const jsEntrypointFile = gzipSize.sync(
fs.readFileSync(path, 'utf8'),
);
this.log.debug(
` ==> JavaScript entrypoint size (${key} => ${val}): ${bytes(
jsEntrypointFile,
)}`,
);
}
}
if (css) {
for (const [key, val] of Object.entries(css)) {
const path = isAbsolute(val) ? val : join(cwd, val);
const cssEntrypointFile = gzipSize.sync(
fs.readFileSync(path, 'utf8'),
);
this.log.debug(
` ==> CSS entrypoint size (${key} => ${val}): ${bytes(
cssEntrypointFile,
` ==> entrypoint size (${key} => ${val}): ${bytes(
gzipSize.sync(fs.readFileSync(path, 'utf8')),
)}`,
);
}
Expand Down
11 changes: 3 additions & 8 deletions classes/publish/package/tasks/check-if-already-published.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Task = require('./task');
module.exports = class CheckIfAlreadyPublished extends Task {
async process(incoming = {}, outgoing = {}) {
const { log } = this;
const { server, name, version, js, css, path } = incoming;
const { server, name, version, entrypoints, path } = incoming;

log.debug(`Checking for existence of package ${name} version ${version}`);
log.debug(' ==> Fetching package metadata from server');
Expand Down Expand Up @@ -49,13 +49,8 @@ module.exports = class CheckIfAlreadyPublished extends Task {
let localHash;
try {
const localFiles = [join(path, './eik.json')];
if (js) {
for (const key of Object.keys(js)) {
localFiles.push(join(path, key));
}
}
if (css) {
for (const key of Object.keys(css)) {
if (entrypoints) {
for (const key of Object.keys(entrypoints)) {
localFiles.push(join(path, key));
}
}
Expand Down
137 changes: 0 additions & 137 deletions classes/publish/package/tasks/create-bundles.js

This file was deleted.

27 changes: 7 additions & 20 deletions classes/publish/package/tasks/create-zip-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Task = require('./task');
module.exports = class CreateZipFile extends Task {
async process(incoming = {}, outgoing = {}) {
const { log } = this;
const { js, css, path, name, map, server, out, cwd } = incoming;
const { entrypoints, path, name, map, server, out, cwd } = incoming;

log.debug(`Creating zip file`);
log.debug(` ==> ${join(path, `eik.tgz`)}`);
Expand All @@ -20,8 +20,7 @@ module.exports = class CreateZipFile extends Task {
writeFileSync(eikPathDest, JSON.stringify({
name,
server,
js,
css,
entrypoints,
'import-map': map,
out,
}, null, 2));
Expand All @@ -30,27 +29,15 @@ module.exports = class CreateZipFile extends Task {
throw new Error(`Failed to zip eik.json file: ${err.message}`);
}

if (js) {
if (entrypoints) {
try {
for (const [key, val] of Object.entries(js)) {
const jsPathSrc = isAbsolute(val) ? val : join(cwd, val);
copyFileSync(jsPathSrc, join(path, key));
for (const [key, val] of Object.entries(entrypoints)) {
const pathSrc = isAbsolute(val) ? val : join(cwd, val);
copyFileSync(pathSrc, join(path, key));
filesToZip.push(key);
}
} catch (err) {
throw new Error(`Failed to zip JavaScripts: ${err.message}`);
}
}

if (css) {
try {
for (const [key, val] of Object.entries(css)) {
const cssPathSrc = isAbsolute(val) ? val : join(cwd, val);
copyFileSync(cssPathSrc, join(path, key));
filesToZip.push(key);
}
} catch (err) {
throw new Error(`Failed to zip CSS: ${err.message}`);
throw new Error(`Failed to copy files for zipping: ${err.message}`);
}
}

Expand Down
7 changes: 2 additions & 5 deletions classes/publish/package/tasks/dry-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ const Task = require('./task');

module.exports = class DryRun extends Task {
async process(incoming = {}, outgoing = {}) {
const { dryRun, path, zipFile, js, css } = incoming;
const { dryRun, path, zipFile, entrypoints } = incoming;
if (dryRun) {
outgoing.files = [
{ pathname: path, type: 'temporary directory' },
{ pathname: zipFile, type: 'package archive' },
]

for (const key of Object.keys(js)) {
outgoing.files.push({ pathname: join(path, key), type: 'package file' })
}
for (const key of Object.keys(css)) {
for (const key of Object.keys(entrypoints)) {
outgoing.files.push({ pathname: join(path, key), type: 'package file' })
}
}
Expand Down
20 changes: 6 additions & 14 deletions classes/publish/package/tasks/validate-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ValidationError extends Error {
module.exports = class ValidateInput extends Task {
process(incoming = {}, outgoing = {}) {
const { log } = this;
const { cwd, server, name, js, css, map, dryRun, version } = incoming;
const { cwd, server, name, entrypoints, map, dryRun, version } = incoming;

log.debug('Validating input');

Expand Down Expand Up @@ -51,21 +51,13 @@ module.exports = class ValidateInput extends Task {
throw new ValidationError('Parameter "version" is not valid', err);
}

log.debug(` ==> at least 1 of js or css: ${!!js || !!css}`);
if (!js && !css) {
throw new ValidationError(
'At least one of "js" or "css" must be provided',
);
if (!entrypoints) {
throw new ValidationError('Entrypoints must be provided');
}

log.debug(` ==> js: ${JSON.stringify(js)}`);
if (js && typeof js !== 'string' && typeof js !== 'object') {
throw new ValidationError('Parameter "js" is not valid');
}

log.debug(` ==> css: ${JSON.stringify(css)}`);
if (css && typeof css !== 'string' && typeof css !== 'object') {
throw new ValidationError('Parameter "css" is not valid');
log.debug(` ==> entrypoints: ${JSON.stringify(entrypoints)}`);
if (typeof entrypoints !== 'object') {
throw new ValidationError('Parameter "entrypoints" is not valid');
}

log.debug(` ==> map: ${JSON.stringify(map)}`);
Expand Down
Loading

0 comments on commit 0c21253

Please sign in to comment.