Skip to content

Instantly share code, notes, and snippets.

@Oldes
Last active August 8, 2024 14:20
Show Gist options
  • Save Oldes/2703696531869daa2d65054ce0f753f4 to your computer and use it in GitHub Desktop.
Save Oldes/2703696531869daa2d65054ce0f753f4 to your computer and use it in GitHub Desktop.
Prepare a new Rebol extension project
Rebol [
title: "Prepare a new Rebol extension project"
needs: 3.7.0 ;; because it is using ZIP codec
]
ext-name1: ask "Name of the new extension (uppercase without `Rebol-` part): "
ext-name2: lowercase copy ext-name1
ext-root: join %Rebol- ext-name1
;; Check if there is already a project with this name.
if exists? ext-root [
print as-purple ["*** There is already a project with name:" as-yellow ext-root]
wait 3
quit
]
;; Make the root directory
make-dir ext-root
;; As we will work with binary data later, prepare the names as binary as well.
name1: to binary! ext-name1
name2: to binary! ext-name2
;; Try to download all template files as a ZIP archive.
try/with [
template: load https://github.com/Oldes/Rebol-C-Extension-Template/archive/refs/heads/master.zip
][
print as-purple "*** Failed to download a template sources!"
wait 3
quit
]
;; For each file in the archive, replace all template names in both its path and content.
foreach [path data] template [
path: find/tail path #"/"
if empty? path [continue]
probe path
replace/all/case path %template ext-name2
replace/all/case path %Template ext-name1
either dir? path [
make-dir/deep ext-root/:path
][
bin: second data
;; Replace names only in files of specified types
if find [%.md %.r3 %.c %.h %.yml %.nest] suffix? path [
replace/all bin #{74656D706C617465} name2 ;; replaces "template"
replace/all bin #{54656D706C617465} name1 ;; replaces "Template"
]
write ext-root/:path :bin
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment