Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion scripts/commands/developer/export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Command() {
cp -r dev/* tmp/
cd tmp || cdhalt

if ! node "$FOLDER/scripts/helpers/normalize-conf-yaml.js" conf.yml; then
PRINT FATAL "Unable to normalize extension configuration to UTF-8."
return 1
fi

# Assign variables to extension flags.
flags="$conf_info_flags"
PRINT INFO "Reading and assigning extension flags.."
Expand Down Expand Up @@ -76,4 +81,4 @@ Command() {
else
PRINT SUCCESS "Extension has been exported to '${FOLDER}/${identifier}.blueprint'."
fi
}
}
12 changes: 11 additions & 1 deletion scripts/commands/extensions/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,17 @@ InstallExtension() {
return 1
fi

eval "$(parse_yaml .blueprint/extensions/"${identifier}"/private/.store/conf.yml old_)"
while IFS= read -r assignment; do
if [[ -z "$assignment" ]]; then
continue
fi

if [[ $assignment =~ ^old_[a-zA-Z0-9_]*= ]]; then
eval "$assignment"
else
PRINT WARNING "Ignoring malformed stored extension configuration entry while updating '$identifier'."
fi
done < <(parse_yaml ".blueprint/extensions/${identifier}/private/.store/conf.yml" old_)
local DUPLICATE="y"

# run extension update script
Expand Down
12 changes: 11 additions & 1 deletion scripts/commands/extensions/remove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ RemoveExtension() {
((PROGRESS_NOW++))

if [[ -f ".blueprint/extensions/$EXTENSION/private/.store/conf.yml" ]]; then
eval "$(parse_yaml ".blueprint/extensions/$EXTENSION/private/.store/conf.yml" conf_)"
while IFS= read -r assignment; do
if [[ -z "$assignment" ]]; then
continue
fi

if [[ $assignment =~ ^conf_[a-zA-Z0-9_]*= ]]; then
eval "$assignment"
else
PRINT WARNING "Ignoring malformed stored extension configuration entry while removing '$EXTENSION'."
fi
done < <(parse_yaml ".blueprint/extensions/${EXTENSION}/private/.store/conf.yml" conf_)
# Add aliases for config values to make working with them easier.
local name="${conf_info_name//&/\\&}"
local identifier="${conf_info_identifier//&/\\&}"
Expand Down
38 changes: 38 additions & 0 deletions scripts/helpers/normalize-conf-yaml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const fs = require('fs');

const path = process.argv[2];

if (!path) {
console.error('Usage: node normalize-conf-yaml.js <conf.yml>');
process.exit(1);
}

let contents;

try {
contents = fs.readFileSync(path);
} catch {
console.error(`Unable to read ${path}.`);
process.exit(1);
}

let encoding = 'utf-8';
let offset = 0;

if (contents.subarray(0, 3).equals(Buffer.from([0xef, 0xbb, 0xbf]))) {
offset = 3;
} else if (contents.subarray(0, 2).equals(Buffer.from([0xff, 0xfe]))) {
encoding = 'utf-16le';
offset = 2;
} else if (contents.subarray(0, 2).equals(Buffer.from([0xfe, 0xff]))) {
encoding = 'utf-16be';
offset = 2;
}

try {
const text = new TextDecoder(encoding, { fatal: true }).decode(contents.subarray(offset));
fs.writeFileSync(path, text, 'utf8');
} catch {
console.error(`Unable to convert ${path} to UTF-8.`);
process.exit(1);
}