Skip to content

Commit

Permalink
Merge pull request #3354 from nulib/deploy/staging
Browse files Browse the repository at this point in the history
Deploy v8.0.0 to production
  • Loading branch information
kdid authored May 24, 2023
2 parents 1685b1c + ce882dc commit 297007e
Show file tree
Hide file tree
Showing 112 changed files with 2,746 additions and 3,343 deletions.
48 changes: 23 additions & 25 deletions app/assets/build.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
#!/usr/bin/env node

const aliasGlob = require("./build/esbuild-plugin-alias-glob");
const { copy } = require("esbuild-plugin-copy");
const esbuild = require("esbuild");
const fs = require("node:fs");
const path = require("node:path");
const sassMapper = require("./build/sass-mapper");
const { sassPlugin } = require("esbuild-sass-plugin");
const svgr = require("esbuild-plugin-svgr");

const args = process.argv.slice(2);
const watch = args.includes("--watch");
const deploy = args.includes("--deploy");

const cwd = process.cwd();

const elasticsearchIndex = (suffix) =>
JSON.stringify(
[process.env.DEV_PREFIX, process.env.DEV_ENV, "dc-v2", suffix]
.filter((e) => e)
.join("-")
);

const define = {
__HONEYBADGER_API_KEY__: JSON.stringify(
process.env.HONEYBADGER_API_KEY_FRONTEND || ""
Expand All @@ -20,36 +32,16 @@ const define = {
process.env.HONEYBADGER_REVISION || ""
),
__MEADOW_VERSION__: JSON.stringify(process.env.MEADOW_VERSION || ""),
__ELASTICSEARCH_INDEX__: JSON.stringify(
[process.env.DEV_PREFIX, process.env.DEV_ENV, "meadow"]
.filter((e) => e)
.join("-")
),
__ELASTICSEARCH_WORK_INDEX__: elasticsearchIndex("work"),
__ELASTICSEARCH_COLLECTION_INDEX__: elasticsearchIndex("collection"),
__ELASTICSEARCH_FILE_SET_INDEX__: elasticsearchIndex("file-set"),
};

const loader = {
".js": "jsx",
".png": "file",
};

const importMapper = (loc) => {
const relativePathResolver = new RegExp(
"^(?<prefix>.+?/)(node_modules/.+/)(?<path>node_modules/.+$)"
);
let result = loc.replace(relativePathResolver, "$<prefix>$<path>");

if (result.startsWith("@")) {
result = path.join(process.cwd(), "node_modules", result);
}

if (fs.existsSync(path.join(result, "package.json"))) {
const spec = JSON.parse(fs.readFileSync(path.join(result, "package.json")));
result = path.join(result, spec.sass || spec.main);
}

return result;
};

const plugins = [
copy({
assets: {
Expand All @@ -58,7 +50,12 @@ const plugins = [
},
watch: true,
}),
sassPlugin({ cssImports: true, importMapper }),
aliasGlob({
"@js": {
to: path.resolve(cwd, "./js"),
},
}),
sassPlugin({ cssImports: true, importMapper: sassMapper }),
svgr(),
];

Expand All @@ -72,6 +69,7 @@ let opts = {
define,
loader,
plugins,
resolveExtensions: [".mjs", ".js", ".jsx", ".json", ".tsx", ".ts"],
};

async function watchMode(opts) {
Expand Down
39 changes: 39 additions & 0 deletions app/assets/build/esbuild-plugin-alias-glob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const fs = require("node:fs");
const { globSync } = require("glob");
const path = require("node:path");

const DEFAULT_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".css", ".json"];

function indexFile(source) {
const candidate = path.resolve(source, "./index.js");
if (fs.existsSync(candidate)) return candidate;
return null;
}

function matchingFile(source, glob) {
const candidates = globSync(`${source}.{${glob}}`);
return candidates[0] || source;
}

function resolveFile(source, glob) {
return indexFile(source) || matchingFile(source, glob);
}

module.exports = (specs) => {
return {
name: "aliasGlob",
setup(build) {
for (const alias in specs) {
const { to } = specs[alias];
const exts = build.initialOptions?.resolveExtensions || DEFAULT_EXTENSIONS;
const fileGlob = exts.join(",").replaceAll(/\./g, "") || "";
const filter = new RegExp(`^${alias}/`);
build.onResolve({ filter }, async (opts) => {
const source = opts.path.replace(filter, "");
const result = resolveFile(path.resolve(to, source), fileGlob);
return { path: result };
});
}
}
}
};
20 changes: 20 additions & 0 deletions app/assets/build/sass-mapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = require("node:fs");
const path = require("node:path");

module.exports = (loc) => {
const relativePathResolver = new RegExp(
"^(?<prefix>.+?/)(node_modules/.+/)(?<path>node_modules/.+$)"
);
let result = loc.replace(relativePathResolver, "$<prefix>$<path>");

if (result.startsWith("@")) {
result = path.join(process.cwd(), "node_modules", result);
}

if (fs.existsSync(path.join(result, "package.json"))) {
const spec = JSON.parse(fs.readFileSync(path.join(result, "package.json")));
result = path.join(result, spec.sass || spec.main);
}

return result;
};
25 changes: 2 additions & 23 deletions app/assets/js/components/BatchEdit/Administrative/General.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React from "react";
import PropTypes from "prop-types";
import React from "react";
import UIFormField from "../../UI/Form/Field";
import { useFormContext } from "react-hook-form";
import { useCodeLists } from "@js/context/code-list-context";
import UIFormSelect from "@js/components/UI/Form/Select";
import UIFormReadingRoomHelperText from "@js/components/UI/Form/ReadingRoomHelperText";
import { useFormContext } from "react-hook-form";

const BatchEditAdministrativeGeneral = ({ ...restProps }) => {
const context = useFormContext();
Expand Down Expand Up @@ -96,25 +94,6 @@ const BatchEditAdministrativeGeneral = ({ ...restProps }) => {
</select>
</div>
</UIFormField>
<UIFormField label="Reading Room" data-testid="reading-room">
<UIFormSelect
isReactHookForm
name="readingRoom"
label="Reading Room"
showHelper
options={[
{
value: "set",
label: "Set",
},
{
value: "unset",
label: "Unset",
},
]}
/>
<UIFormReadingRoomHelperText />
</UIFormField>
</div>
);
};
Expand Down
6 changes: 1 addition & 5 deletions app/assets/js/components/BatchEdit/Confirmation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ const BatchEditConfirmation = ({
batchReplaces &&
(Object.keys(batchReplaces.administrativeMetadata).length > 0 ||
Object.keys(batchReplaces.descriptiveMetadata).length > 0 ||
batchReplaces.published ||
Boolean(batchReplaces.readingRoom));
batchReplaces.published);

const hasCollection =
batchCollection && Object.keys(batchCollection).length > 0;
Expand Down Expand Up @@ -211,9 +210,6 @@ const BatchEditConfirmation = ({
? "Publish works"
: "Unpublish works",
}),
...(batchReplaces.readingRoom && {
readingRoom: batchReplaces.readingRoom,
}),
}}
type="replace"
/>
Expand Down
3 changes: 0 additions & 3 deletions app/assets/js/components/BatchEdit/Tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ export default function BatchEditTabs() {
...((batchPublish.publish || batchPublish.unpublish) && {
published: { ...batchPublish },
}),
...(currentFormValues.readingRoom && {
readingRoom: currentFormValues.readingRoom,
}),
descriptiveMetadata: {
...replaceItems.descriptive,
...descriptiveMultiValues.replace,
Expand Down
13 changes: 7 additions & 6 deletions app/assets/js/components/Charts/Visibility.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React from "react";
import {
BarChart,
Bar,
Cell,
XAxis,
YAxis,
BarChart,
CartesianGrid,
Tooltip,
Cell,
Legend,
ResponsiveContainer,
Tooltip,
XAxis,
YAxis,
} from "recharts";

import React from "react";

export default function ChartsVisibility({ data = [] }) {
return (
<div style={{ width: "100%", height: "300px" }}>
Expand Down
14 changes: 7 additions & 7 deletions app/assets/js/components/Dashboards/BatchEdit/Details.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from "react";
import PropTypes from "prop-types";
import { useQuery } from "@apollo/client";
import { GET_BATCH } from "@js/components/Dashboards/dashboards.gql";
import { IconImages } from "@js/components/Icon";
import JSONPretty from "react-json-pretty";
import UIDate from "@js/components/UI/Date";
import UISkeleton from "@js/components/UI/Skeleton";
import { Link } from "react-router-dom";
import { IconImages } from "@js/components/Icon";
import { Notification } from "@nulib/design-system";
import PropTypes from "prop-types";
import React from "react";
import UIDate from "@js/components/UI/Date";
import UISkeleton from "@js/components/UI/Skeleton";
import { useQuery } from "@apollo/client";

function DashboardsBatchEditDetails({ id }) {
const { error, loading, data } = useQuery(GET_BATCH, {
Expand Down Expand Up @@ -75,7 +75,7 @@ function DashboardsBatchEditDetails({ id }) {
className="button is-primary"
to={{
pathname: "/search",
state: { passedInSearchTerm: `batches:\"${id}\"` },
state: { passedInSearchTerm: `batch_ids:\"${id}\"` },
}}
>
<IconImages />
Expand Down
11 changes: 6 additions & 5 deletions app/assets/js/components/Dashboards/BatchEdit/List.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from "react";
import { useQuery } from "@apollo/client";
import { IconImages, IconView } from "@js/components/Icon";

import { GET_BATCHES } from "@js/components/Dashboards/dashboards.gql";
import { Link } from "react-router-dom";
import UIDate from "@js/components/UI/Date";
import { IconImages, IconView } from "@js/components/Icon";
import React from "react";
import { Tag } from "@nulib/design-system";
import UIDate from "@js/components/UI/Date";
import { useQuery } from "@apollo/client";

const colHeaders = [
"Nickname",
Expand Down Expand Up @@ -80,7 +81,7 @@ export default function DashboardsBatchEditList() {
title="View updated works"
to={{
pathname: "/search",
state: { passedInSearchTerm: `batches:\"${id}\"` },
state: { passedInSearchTerm: `batch_ids:\"${id}\"` },
}}
>
<IconImages />
Expand Down
10 changes: 5 additions & 5 deletions app/assets/js/components/Dashboards/Csv/Details.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import PropTypes from "prop-types";
import UIDate from "@js/components/UI/Date";
import DashboardsCsvErrors from "@js/components/Dashboards/Csv/Errors";
import DashboardsCsvStatus from "@js/components/Dashboards/Csv/Status";
import { Link } from "react-router-dom";
import { IconImages } from "@js/components/Icon";
import { Link } from "react-router-dom";
import PropTypes from "prop-types";
import React from "react";
import UIDate from "@js/components/UI/Date";

function DashboardsCsvDetails({ csvMetadataUpdateJob }) {
const {
Expand Down Expand Up @@ -66,7 +66,7 @@ function DashboardsCsvDetails({ csvMetadataUpdateJob }) {
to={{
pathname: "/search",
state: {
passedInSearchTerm: `metadataUpdateJobs:\"${updateId}\"`,
passedInSearchTerm: `csv_metadata_update_jobs:\"${updateId}\"`,
},
}}
>
Expand Down
17 changes: 9 additions & 8 deletions app/assets/js/components/Dashboards/Csv/List.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from "react";
import { IconImages, IconView } from "@js/components/Icon";

import DashboardsCsvStatus from "@js/components/Dashboards/Csv/Status";
import { GET_CSV_METADATA_UPDATE_JOBS } from "@js/components/Dashboards/dashboards.gql";
import { Link } from "react-router-dom";
import PropTypes from "prop-types";
import UISearchBarRow from "@js/components/UI/SearchBarRow";
import React from "react";
import UIFormInput from "@js/components/UI/Form/Input";
import { useQuery } from "@apollo/client";
import { GET_CSV_METADATA_UPDATE_JOBS } from "@js/components/Dashboards/dashboards.gql";
import UISearchBarRow from "@js/components/UI/SearchBarRow";
import { formatDate } from "@js/services/helpers";
import { Link } from "react-router-dom";
import { IconImages, IconView } from "@js/components/Icon";
import DashboardsCsvStatus from "@js/components/Dashboards/Csv/Status";
import { useQuery } from "@apollo/client";

const displayFields = [
{
Expand Down Expand Up @@ -125,7 +126,7 @@ function DashboardsCsvList(props) {
to={{
pathname: "/search",
state: {
passedInSearchTerm: `metadataUpdateJobs:\"${id}\"`,
passedInSearchTerm: `csv_metadata_update_jobs:\"${id}\"`,
},
}}
>
Expand Down
Loading

0 comments on commit 297007e

Please sign in to comment.