Browse Source

Improved the user experience by checking for missing files, empty build directory when building, cleaning, or serving

main
Jesse Laprade 2 weeks ago
parent
commit
e299119c65
2 changed files with 43 additions and 26 deletions
  1. +0
    -4
      README.md
  2. +43
    -22
      wg.fnl

+ 0
- 4
README.md View File

@ -94,10 +94,6 @@ will install wg into `~/.local/bin`.
This section will guide you through installing wg to a custom location.
**Note**: Installing wg to your homepage directory will prevent you from
accidentally running wg elsewhere on your system or in a sub directory
of your homepage's source.
#### To install wg to a custom location
1. `cd wg`

+ 43
- 22
wg.fnl View File

@ -44,6 +44,13 @@
(fn print-format [str ...]
(print (string.format str ...)))
(fn print-not-initialized []
(print "Error: wg has not been initialized or there are missing files.")
(print "Try running the following command to initialize or check for missing files:")
(print " wg init")
(print "For more information, type the following command:")
(print " wg help"))
;; ---------------------------------------
;; Path, directory, and file utils
;; ---------------------------------------
@ -101,6 +108,13 @@
(table.insert seq file)))
seq))
(fn required-paths-missing? []
(or (> (# (directories-missing directories-required)) 0)
(> (# (files-missing files-required)) 0)))
(fn build-directory-has-contents? []
(> (# (directory-contents :build)) 0))
;; ---------------------------------------
;; init
;; ---------------------------------------
@ -149,8 +163,7 @@
(init/read-input))
(fn init []
(if (or (> (# (directories-missing directories-required)) 0)
(> (# (files-missing files-required)) 0))
(if (required-paths-missing?)
(init/prompt)
(print "The required directories and files exist.")))
@ -158,7 +171,13 @@
;; serve
;; ---------------------------------------
(fn serve []
(os.execute "python3 -m http.server 8000 --directory build/"))
(if (required-paths-missing?)
(print-not-initialized)
(if (build-directory-has-contents?)
(os.execute "python3 -m http.server 8000 --directory build/")
(do (print "Error: 'build/' directory has no contents.")
(print "Try running the following command first:")
(print " wg build")))))
;; ---------------------------------------
;; clean
@ -178,13 +197,11 @@
(print "Cancelled the deletion of the 'build/' directory's contents."))))
(fn clean []
(if (directory-exists? :build)
(if (> (# (directory-contents :build)) 0)
(if (required-paths-missing?)
(print-not-initialized)
(if (build-directory-has-contents?)
(clean/prompt)
(print "'build/' directory empty. Nothing to clean."))
(do (print "'build/' directory doesn't exist.")
(print "For more information, run the following command:")
(print "wg help"))))
(print "'build/' directory empty. Nothing to clean."))))
;; ---------------------------------------
;; build
@ -219,18 +236,21 @@
(build/convert source))))))
(fn build []
;; Copy paths
(if (= (# (directory-contents :copy)) 0)
(print "No directories or files found in the 'copy/' directory. Skipping...")
(do (print "Copying files in 'copy/' directory...")
(path-copy (.. :copy "/*") :build)
(print "Copying complete!")))
;; Convert paths
(if (= (# (directory-contents :convert)) 0)
(print "No directories or files found in the 'convert/' directory. Skipping...")
(do (print "Converting files in 'convert/' directory...")
(build/convert :convert)
(print "Conversion complete!"))))
(if (required-paths-missing?)
(print-not-initialized)
(do
;; Copy paths
(if (= (# (directory-contents :copy)) 0)
(print "No directories or files found in the 'copy/' directory. Skipping...")
(do (print "Copying files in 'copy/' directory...")
(path-copy (.. :copy "/*") :build)
(print "Copying complete!")))
;; Convert paths
(if (= (# (directory-contents :convert)) 0)
(print "No directories or files found in the 'convert/' directory. Skipping...")
(do (print "Converting files in 'convert/' directory...")
(build/convert :convert)
(print "Conversion complete!"))))))
(fn help []
(print
@ -284,6 +304,7 @@
[:serve nil] (serve)
[:clean nil] (clean)
[:help nil] (help)
_ (print "For more information, type the following command:\nwg help")))
_ (do (print "For more information, type the following command:")
(print " wg help"))))
(main arg)

Loading…
Cancel
Save