Skip to content

Commit 4c809fc

Browse files
committed
dropping unneeded components
1 parent db9d01b commit 4c809fc

File tree

2 files changed

+3
-153
lines changed

2 files changed

+3
-153
lines changed

lib/utils/templates.js

+2-152
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { deepMerge } from './objects';
22
import { fetchFileAsync } from './files';
3-
//import template_manifest from '../../web/templates/manifest.json';
43
import { menu, getSchema } from 'schemas';
54

65

@@ -24,28 +23,12 @@ export function getTemplatePathInScope() {
2423
return templatePath;
2524
}
2625

27-
const isSchema = (el) => el.name === 'schema.json';
28-
const isLocale = (el) => el.name === 'locales';
29-
3026
const schemaFromChildPath = (childPath) =>
3127
childPath.replace(/\/templates\/(.+)\/schema.json/, '$1');
3228

33-
// Actually this is accessSchema - and not language variant.
34-
35-
// Returns default template built from schema
36-
export async function accessTemplate(schema_folder) { // e.g. canada_covid19
37-
38-
const template = template_manifest.children.find(
39-
(el) => el.name === schema_folder
40-
);
41-
console.log("template from manifest", template)
42-
return template ? processNode(template) : null;
43-
}
44-
4529
// Returns default template built from schema
4630
async function compileSchema(schema_folder) { // e.g. canada_covid19
4731

48-
//////////////////////////////////////////////////
4932
for (const [schema_name, schema_obj] of Object.entries(menu)) {
5033
if (schema_obj.folder === schema_folder) {
5134
var schema = await fetchSchema(`/templates/${schema_folder}/schema.json`);
@@ -86,134 +69,6 @@ async function fetchSchema(path) {
8669
return null;
8770

8871
}
89-
/*
90-
// processNode() only used here.
91-
async function processNode(node) {
92-
const { name, children } = node;
93-
94-
// Base case
95-
if (!children || children.length === 0) {
96-
return [];
97-
}
98-
99-
let schema = [];
100-
let locales = [];
101-
102-
await Promise.all(
103-
children.map(async (child) => {
104-
if (isSchema(child)) {
105-
let schemaData = null;
106-
// Running locally so get schema from schemas.json
107-
if (window.location.protocol.startsWith('file')) {
108-
// child.path e.g. /templates/SDRF/schema.json
109-
schemaData = await getSchema(schemaFromChildPath(child.path));
110-
} else if (window.location.protocol.startsWith('http')) {
111-
schemaData = await fetchFileAsync(child.path);
112-
}
113-
114-
schema.push(schemaData);
115-
} else if (isLocale(child)) {
116-
const processedLocale = await processNode(child);
117-
if (processedLocale.length) {
118-
locales.push(processedLocale);
119-
}
120-
}
121-
else {
122-
const processedChild = await processNode(child);
123-
// CRITICAL FOR LOCAL HIERARCHY SCAN
124-
if (processedChild.length) {
125-
locales.push(processedChild);
126-
}
127-
}
128-
})
129-
);
130-
131-
const folded_template_spec = [name, [schema], locales];
132-
console.log(folded_template_spec);
133-
return folded_template_spec;
134-
}
135-
136-
// This returns template from input [[][][]]; and nothing else
137-
export function buildTemplate(input) {
138-
// Check if the input format is correct
139-
if (!Array.isArray(input) || input.length !== 3) {
140-
throw new Error('Invalid input format. Expected an array of 3 elements.');
141-
}
142-
143-
let [name, innerArray, childFolders] = input;
144-
145-
// Check the innerArray format
146-
if (!Array.isArray(innerArray) || innerArray.length !== 1) {
147-
throw new Error(
148-
'Invalid format for the second parameter. Expected an array of 2 elements.'
149-
);
150-
}
151-
152-
const [schemas] = innerArray;
153-
154-
if (!Array.isArray(schemas)) {
155-
throw new Error('Schemas must be arrays.');
156-
}
157-
158-
const schema = schemas[0];
159-
160-
if (!Array.isArray(childFolders) || childFolders.length === 0) {
161-
childFolders = [[], [], []];
162-
}
163-
164-
const locales_folder = childFolders.filter((ln) => ln[0] === 'locales')[0];
165-
let locales = [];
166-
if (typeof locales_folder !== 'undefined') {
167-
try {
168-
if (Array.isArray(locales_folder) && locales_folder.length > 2) {
169-
locales = locales_folder[2];
170-
} else {
171-
throw new Error(
172-
'locales_folder is not an array or does not have enough elements.'
173-
);
174-
}
175-
} catch (err) {
176-
throw new Error(`Error extracting locales from childFolders: ${err}`);
177-
}
178-
179-
if (!Array.isArray(locales)) {
180-
throw new Error('Locales is not an array.');
181-
}
182-
}
183-
184-
let template = {
185-
name,
186-
default: {
187-
schema
188-
},
189-
locales: {},
190-
};
191-
192-
try {
193-
template.locales = locales.reduce((acc, localization) => {
194-
if (!Array.isArray(localization) || localization.length < 3) {
195-
throw new Error(
196-
'Invalid localization format. Expected an array with at least 3 elements.'
197-
);
198-
}
199-
const locale_label = localization[0];
200-
const schemaMerge =
201-
localization[1][0] && localization[1][0][0]
202-
? deepMerge(schemas[0], localization[1][0][0])
203-
: null;
204-
return Object.assign(acc, {
205-
[locale_label]: {
206-
schema: schemaMerge
207-
},
208-
});
209-
}, {});
210-
} catch (err) {
211-
throw new Error('Error processing locales. ' + err.message);
212-
}
213-
214-
return template;
215-
}
216-
*/
21772

21873
//Used only in this script in create()
21974
function buildTemplateFromUploadedSchema(schema) {
@@ -312,16 +167,13 @@ class TemplateProxy {
312167

313168
let template;
314169
if (forced_schema !== null) {
315-
// returns {name:..., default: {schema}, locales: {[locale]:{ schema}}}
316170
template = buildTemplateFromUploadedSchema(forced_schema);
317171
} else {
318-
// access schema_folder from directory in the manifest
319-
//const fetchedTemplateData = await accessTemplate(schema_folder);
320-
//template = buildTemplate(fetchedTemplateData);
321-
172+
// Access schema_folder via menu content
322173
template = await compileSchema(schema_folder);
323174
}
324175

176+
// template = {name:..., default: {schema}, locales: {[locale]:{ schema}}}
325177
await instance._init(template, locale);
326178

327179
// NOTE: Why Proxy? it allows us to call all of the template's properties in an "inherited" fashion
@@ -490,7 +342,5 @@ export const Template = TemplateProxy;
490342
export default {
491343
TemplateProxy,
492344
Template,
493-
//accessTemplate,
494-
//buildTemplate,
495345
findBestLocaleMatch,
496346
};

web/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path');
22

33
const HtmlWebpackPlugin = require('html-webpack-plugin');
44
const CopyPlugin = require('copy-webpack-plugin');
5-
const DirectoryTreePlugin = require('directory-tree-webpack-plugin');
5+
//const DirectoryTreePlugin = require('directory-tree-webpack-plugin');
66

77
module.exports = (env, argv) => {
88
var config = {

0 commit comments

Comments
 (0)