Class: Konstruct::Cli
- Inherits:
-
Object
- Object
- Konstruct::Cli
- Defined in:
- lib/cli/gulp.rb,
lib/cli/init.rb,
lib/cli/scaffold.rb,
lib/cli/skeleton.rb,
lib/cli/documentation.rb
Instance Method Summary collapse
- #documentation ⇒ Object
- #gulp(path) ⇒ Object
- #init ⇒ Object
- #scaffold(path) ⇒ Object
- #skeleton(path) ⇒ Object
Instance Method Details
#documentation ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cli/documentation.rb', line 15 def documentation # B.1. INITIALISE FUNCTIONS ------------------------------------------------------------------------------- msg = Util::Message.new() # B.1. END ------------------------------------------------------------------------------------------------ msg.heading("KONSTRUCT DOCUMENTATION") # B.2. IS YOUR DIRECTORY EMPTY? --------------------------------------------------------------------------- puts Paint["Opening documentation in your default browser!", "999999"] puts "" Launchy.open( "http://konstruct.github.io/" ) exit(0) # B.3. END ------------------------------------------------------------------------------------------------ end |
#gulp(path) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cli/gulp.rb', line 15 def gulp(path) # B.1. INITIALISE FUNCTIONS ------------------------------------------------------------------------------- msg = Util::Message.new() fs = Util::FS.new() gulp = Util::Gulp.new() # B.1. END ------------------------------------------------------------------------------------------------ # B.2. RUN DEFAULT WATCH TASK ----------------------------------------------------------------------------- gulp.default(path) # B.2. END ------------------------------------------------------------------------------------------------ end |
#init ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/cli/init.rb', line 15 def init # B.1. INITIALISE FUNCTIONS ------------------------------------------------------------------------------- msg = Util::Message.new() fs = Util::FS.new() git = Util::Git.new() config_dir = File.('~/.konstruct') # B.1. END ------------------------------------------------------------------------------------------------ msg.heading("WELCOME TO THE KONSTRUCT CLI!") # B.2. INIT VARIABLSE ------------------------------------------------------------------------------------- init = false init_db = false init_gulp = false init_gulp_install = false init_bower = false dir_analytics = "#{config_dir}/analytics" dir_gulp = "#{config_dir}/gulp" # B.2. END ------------------------------------------------------------------------------------------------ # B.3. CHECK IF INIT SHOULD BE DONE ----------------------------------------------------------------------- if Dir[config_dir].length > 0 init = true else fs.make_dir(config_dir) init = true end # B.3. END ------------------------------------------------------------------------------------------------ # B.4. MAKE DATABASE.JSON --------------------------------------------------------------------------------- if File.file?("#{dir_analytics}/data.json") init_db = true else fs.make_dir(dir_analytics) file_data = { "konstruct_version" => Konstruct::VERSION } File.open("#{dir_analytics}/data.json","w") do |f| f.write(JSON.pretty_generate(file_data)) end msg.success("Created #{dir_analytics}/data.json") init_db = true end # B.4. END ------------------------------------------------------------------------------------------------ # B.5. CLONE GULP REPOSITORY ------------------------------------------------------------------------------ if Dir.exists?(dir_gulp) init_gulp = true else fs.make_dir(dir_gulp) git.install(dir_gulp, Konstruct::FRAMEWORK["gulp"], "gulp", "") msg.success("Cloned Gulp to #{dir_gulp}") init_gulp = true end # B.5. END ------------------------------------------------------------------------------------------------ # B.6. INSTALL NPM ---------------------------------------------------------------------------------------- if Dir.exists?("#{dir_gulp}/node_modules") init_gulp_install = true else msg.paragraph("Installing Gulp + Dependencies. This might take a while. ") msg.paragraph("Please enter your root/admin password. NPM needs to install with sudo privileges.") FileUtils.cd(dir_gulp) do `npm install` end msg.success("Installed Gulp to #{dir_gulp}") init_gulp_install = true end # B.6. END ------------------------------------------------------------------------------------------------ # B.3. SHOW THE HELLO SCREEN ------------------------------------------------------------------------------ if init && init_db && init_gulp && init_gulp_install puts "" puts "" puts Paint[' $III7IIIIIIIIIIIIIIIIIIIIIIIIII: ', "#de544b"] puts Paint[' ZZZZZZ$7IIIIIIIIIIIIIIIIIIIIIIII ', "#de544b"] puts Paint[' ZZZZZZZZZZZZ$7IIIIIIIIIIIIIIIIII ', "#de544b"] puts Paint[' ZZZZZZZZZZZZZZZZZZZ$IIIIIIIIIIII~', "#de544b"] puts Paint[' ZZZZZZZZZZZZZZZZZZZZZZZ:,:+IIIIII', "#de544b"] puts Paint[' ZZZZZZZZZZZZZZZZZZZZZZ. :?', "#de544b"] puts Paint[' I$ZZZZZZZZZZZZZZZZZZ7 ', "#de544b"] puts Paint[' III$ZZZZZZZZZZZZZZZ~ ', "#de544b"] puts Paint[' IIIII7ZZZZZZZZZZZZ ', "#de544b"] puts Paint[' IIIIIII7ZZZZZZZZ$ ', "#de544b"] puts Paint[' IIIIIIIIIIZZZZZ: ', "#de544b"] puts Paint[' IIIIIIIIIIIIZI ', "#de544b"] puts Paint[' IIIIIIIIIIIIII ', "#de544b"] puts Paint[' IIIIIIIIIIIIIIII= ', "#de544b"] puts Paint[' IIIIIIIIIIIIIIIII7= ', "#de544b"] puts Paint[' IIIIIIIIIIIIIIIIIIII~ ', "#de544b"] puts Paint[' IIIIIIIIIIIIIIIIIIIIII= ', "#de544b"] puts Paint[' IIIIIIIIIIIIIIIIIIIIIII7~ ', "#de544b"] puts Paint[' IIIIIIIIIIIIIIIIIIIIIIIIIII.. ', "#de544b"] puts Paint[' IIIIIIIIIIIIIIIIIIIIIIIIIIII7 ', "#de544b"] puts Paint[' IIIIIIIIIIIIIIIIIIIIIIIIIIIIIII,.', "#de544b"] puts Paint[' IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII7', "#de544b"] puts "" puts "" puts Paint[' GO BUILD SOMETHING AWESOME!', "#999999"] puts "" puts Paint[' Run "$ konstruct --help" or "$ konstruct documentation" whenever you get stuck!', "#999999"] puts "" exit(0) end # B.3. END ------------------------------------------------------------------------------------------------ end |
#scaffold(path) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/cli/scaffold.rb', line 15 def scaffold(path) # B.1. INITIALISE FUNCTIONS ------------------------------------------------------------------------------- msg = Util::Message.new() fs = Util::FS.new() git = Util::Git.new() config_dir = "#{path}/.konstruct" # B.1. END ------------------------------------------------------------------------------------------------ msg.heading("SCAFFOLDING A NEW SITE FOR YOU") # B.2. IS YOUR DIRECTORY EMPTY? --------------------------------------------------------------------------- fs.clear_directory(path) # B.2. END ------------------------------------------------------------------------------------------------ # B.3. INSTALL BOILERPLATE -------------------------------------------------------------------------------- type = choose("What type of site are you building?", :Default, :Jekyll, :Angular) if type == :Default git.install(path, Konstruct::BOILERPLATE["Default"], "www", "") end if type == :Jekyll git.install(path, Konstruct::BOILERPLATE["Jekyll"], "www", "") end if type == :Angular git.install(path, Konstruct::BOILERPLATE["Angular"], "www", "") end msg.success("Successfully installed the #{ type } repository!"); # B.3. END ------------------------------------------------------------------------------------------------ # B.4. INSTALL CSS ---------------------------------------------------------------------------------------- css_dir = "#{path}/assets/scss" fs.make_dir(css_dir) # B.4.1. INSTALL KONSTRUCT SCSS MODULE git.install(css_dir, Konstruct::FRAMEWORK["scss"], "scss", "konstruct") msg.success("Successfully installed the Konstruct SCSS framework!") # B.4.1. END # B.4.2. INSTALL KONSTRUCT SITE MODULE git.install(css_dir, Konstruct::FRAMEWORK["site"], "site", "site") msg.success("Successfully installed the Konstruct Site module") # B.4.2. END # B.4.1. INSTALL KONSTRUCT GLUE MODULE git.install(css_dir, Konstruct::FRAMEWORK["glue"], "glue", "") msg.success("Successfully installed the Konstruct Glue module") # B.4.1. END # B.4. END ------------------------------------------------------------------------------------------------ # B.5. INSTALL JS ----------------------------------------------------------------------------------------- js_dir = "#{path}/assets/js" if type == :Angular git.install(js_dir, Konstruct::FRAMEWORK["angular"], "scripts", "scripts") msg.success("Successfully installed the Konstruct Angular module") else git.install(js_dir, Konstruct::FRAMEWORK["js"], "scripts", "scripts") msg.success("Successfully installed the Konstruct JS module") end # B.5. END ------------------------------------------------------------------------------------------------ # B.6. INSTALL NPM ASSETS --------------------------------------------------------------------------------- `npm install` msg.success("Installed NPM Assets") # B.6. END ------------------------------------------------------------------------------------------------ # B.6. SET UP NEW GIT REPOSITORY -------------------------------------------------------------------------- want_git = choose("Want to initialise a git repository?", :Yes, :No) if want_git == :Yes git.init(path) has_remote = choose("Do you already have a remote git repository?", :Yes, :No) if has_remote == :Yes remote_url = ask("Remote Url:") git.remote(path, remote_url) git.add(path) msg.success("Successfully initialised your git repo") end end # B.6. END ------------------------------------------------------------------------------------------------ # B.4. INSTALL .konstruct --------------------------------------------------------------------------------- fs.make_dir(config_dir) date = Time.new date_installed = "#{ date.year }-#{ date.month }-#{ date.day }" file_data = { "konstruct_version" => Konstruct::VERSION, "date_installed" => date_installed, "path" => path, "type" => type, "git_remote" => remote_url } File.open("#{config_dir}/data.json","w") do |f| f.write(JSON.pretty_generate(file_data)) end msg.success("Created #{config_dir}/data.json") # B.4. END ------------------------------------------------------------------------------------------------ # B.5. SEND BUILD DATA TO ANALYTICS ----------------------------------------------------------------------- analytics_file = File.('~/.konstruct/analytics/data.json') analytics_data = { "site" => { "path" => path, "date" => date_installed, "actions" => { "action" => "Installed the site.", "date" => date_installed } } } json = File.read(analytics_file) File.open(analytics_file,"w") do |f| f.write(JSON.pretty_generate(analytics_data)) end msg.success("Logged Analytics to #{analytics_file}") # B.5. END ------------------------------------------------------------------------------------------------ end |
#skeleton(path) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cli/skeleton.rb', line 15 def skeleton(path) # B.1. INITIALISE FUNCTIONS ------------------------------------------------------------------------------- msg = Util::Message.new() fs = Util::FS.new() # B.1. END ------------------------------------------------------------------------------------------------ msg.heading("CREATING SKELETON PROJECT STRUCTURE") # B.2. IS YOUR DIRECTORY EMPTY? --------------------------------------------------------------------------- puts fs.clear_directory(path) # B.2. END ------------------------------------------------------------------------------------------------ # B.3. CREATE SKELETON ------------------------------------------------------------------------------------ # B.3.1. FOLDER STRUCTURE structure = ['1--ci', '2--design', '3--working', '4--www'] # B.3.1. END # B.3.2. CONFIRM BUILD puts Paint["The following directory structure will be created for you:", "999999"] puts "" structure.each { |f| puts Paint["-- #{ f }", "999999"] } puts "" choice = choose("Do you want to install the structure above?", :yes, :no) # B.3.2. END # B.3.3. BUILD STRUCTURE if choice == :yes structure.each { |f| Dir.mkdir "#{ path }/#{ f }" } msg.success('Successfully created your skeleton. Go do something awesome!') exit(0) else exit(0) end # B.3.7. END # B.3. END ------------------------------------------------------------------------------------------------ end |