devlogs 0.1.6 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7ac238f0667f25c6b370f32660aa2d089ebbfff0ecec9bffb012f9851188174
4
- data.tar.gz: 93aaabcee373c6511a479e6cf21b6803af0cfec922e4416fed2406a966307ced
3
+ metadata.gz: 0ee70029616eb23078cfe60734052a855642617338f776543da002c18986cfad
4
+ data.tar.gz: 8169a90b74e0524f6b9b0ebdb786ff0fb1df38e8d59c7d6bbdbbce7936d037d5
5
5
  SHA512:
6
- metadata.gz: 5833adbd0231c8fe941364cec3dd6d83878999ed67b8ebf055dda56a12289a0e609ac8cb3e2868db2f4e570e52958622f7f25f997701baf130cf86e730a5daa1
7
- data.tar.gz: fe438af20e0f8ec3326bf56ee410f037ef81495e39218586ad70ff8ae7a50a056f2c409db0b4dc02914c47dfb7dca157a9c4082bf0926c6bf739f8f9800f26a3
6
+ metadata.gz: 3aba32f26e6905b876ad6e0777a86d29abfe1ea0642180fe1320ee82b20cc3a8efd2e22088d3b469149f920fa12808166ee7572b1f2207337afbf146bbac38cc
7
+ data.tar.gz: 9fa406dae78b034c22c9db6f992e00a0255c920bb569f68fb4c5a20a295df8bcab8fad4f7f58f1d8a4f0870e05025f0d7b7c135bd50feea06e5b31ccf5b62fcf
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ __devlog
10
10
  *.gem
11
11
  __devlogs
12
12
  mirror
13
+ _devlogs
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- devlogs (0.1.6)
4
+ devlogs (0.2.0)
5
5
  rsync (~> 1.0, >= 1.0.9)
6
6
  thor (~> 1.2.1)
7
7
  tty-prompt (~> 0.23.1)
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
1
  # devlogs
2
- ![Version](https://img.shields.io/badge/version-0.1.4-green)
3
-
4
2
  Project based session logging for solo-developers with the option to mirror changes to another directory.
5
3
 
6
4
  https://stacktrace.one/blog/avoid-project-management-solo-dev/
@@ -25,12 +23,12 @@ Or install it yourself as:
25
23
 
26
24
  ## Usage
27
25
  ### Initialize
28
- Inside your project initialize the `__devlogs` repository:
26
+ Inside your project initialize the `_devlogs` repository:
29
27
  ```bash
30
28
  $ devlogs init
31
29
  ```
32
30
 
33
- Follow the prompts to setup the project configuration located in `__devlogs/.devlogs.config`.
31
+ Follow the prompts to setup the project configuration located in `_devlogs/.devlogs.config`.
34
32
 
35
33
  You can setup a mirror directory path in the configuration stage to sync changes to another directory on your machine, for example to Obsidian.md.
36
34
 
@@ -38,7 +36,7 @@ Example:
38
36
 
39
37
  ```
40
38
  myproject
41
- __devlogs
39
+ _devlogs
42
40
  >> content
43
41
  ```
44
42
 
@@ -68,6 +66,15 @@ Your editor will pop up and you can fill in cliff notes.
68
66
 
69
67
  Save and if you set a mirror it will sync over!
70
68
 
69
+ ### Retrieve previous entry
70
+ You can use the `last` command to retrieve the most recent entry
71
+
72
+ ```bash
73
+ devlogs last
74
+ ```
75
+
76
+ The `--open` command will cause the entry to be opened in a new default editor.
77
+
71
78
  ## Development
72
79
 
73
80
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/devlogs/cli.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "version"
4
4
  require_relative "repository"
5
+ require_relative "editor"
5
6
  require "thor"
6
7
 
7
8
  module Devlogs
@@ -34,12 +35,27 @@ module Devlogs
34
35
 
35
36
  Repository::Initialize.run(
36
37
  { force: options.force? },
37
- File.join(".", "__devlogs")
38
+ File.join(".", "_devlogs")
38
39
  )
39
40
 
40
41
  puts "Created devlogs"
41
42
  end
42
43
 
44
+ #
45
+ # Retrieves the most recent entry from the repository
46
+ #
47
+ desc "last", "Retrieves the last entry in the repository"
48
+ method_options open: :boolean, alias: :string
49
+ def last
50
+ puts "Reading last entry"
51
+ last_entry = repo.ls.first
52
+
53
+ if options.open?
54
+ Editor.open(last_entry)
55
+ else
56
+ puts File.read(last_entry)
57
+ end
58
+ end
43
59
  #
44
60
  # Creates a devlogs entry in the repository and syncs changes
45
61
  # to the mirrored directory if set
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Wrapper for terminal editor
4
+ class Editor
5
+ def initialize
6
+ @program = ENV["EDITOR"]
7
+ end
8
+
9
+ # Opens the file contained at the path
10
+ def open(path)
11
+ command = "#{@program} #{path}"
12
+
13
+ system command
14
+ end
15
+
16
+ class << self
17
+ # Opens the file at +path+ using system editor
18
+ def open(path)
19
+ session = new
20
+
21
+ session.open(path)
22
+ end
23
+ end
24
+ end
@@ -5,6 +5,8 @@ require "tty-prompt"
5
5
  require "yaml"
6
6
  require "rsync"
7
7
  require "pry"
8
+ require "time"
9
+ require_relative "editor"
8
10
 
9
11
  # Repostiroy is an accessor object for the devlogs directory
10
12
  class Repository
@@ -13,20 +15,22 @@ class Repository
13
15
  # TODO: should be part of configuration
14
16
  DEFAULT_LOG_SUFFIX = "devlogs.md"
15
17
  DEFAULT_DIRECTORY_PATH = "."
16
- DEFAULT_DIRECTORY_NAME = "__devlogs"
18
+ DEFAULT_DIRECTORY_NAME = "_devlogs"
17
19
 
18
20
  # Example: 11-22-2022_1343
19
21
  DEFAULT_TIME_FORMAT_FILE_PREFIX = "%m-%d-%Y__%kh%Mm"
20
22
  DEFAULT_TIME_FORMAT_TEXT_ENTRY = "%m-%d-%Y %k:%M"
21
23
 
22
- # Initializes a __devlogs repository with the supplied configuration
24
+ VALID_DIRECTION = %i[asc desc].freeze
25
+
26
+ # Initializes a _devlogs repository with the supplied configuration
23
27
  # @param repo_config [Repository::Config]
24
28
  #
25
29
  def initialize(repo_config)
26
30
  @config = repo_config
27
31
  end
28
32
 
29
- # Creates a new __devlogs entry for recording session completion
33
+ # Creates a new _devlogs entry for recording session completion
30
34
  #
31
35
  # @returns nil
32
36
  def create
@@ -50,9 +54,7 @@ class Repository
50
54
  end
51
55
  end
52
56
 
53
- editor_program = ENV["EDITOR"]
54
-
55
- system("#{editor_program} #{entry_file_path}")
57
+ Editor.open(entry_file_path)
56
58
 
57
59
  puts "Writing entry to #{entry_file_path}.."
58
60
  end
@@ -67,9 +69,8 @@ class Repository
67
69
 
68
70
  # Use trailing slash to avoid sub-directory
69
71
  # See rsync manual page
70
- path = @config.path[-1] == "/" ? @config.path : @config.path + "/"
71
72
 
72
- Rsync.run("-av", path, @config.mirror.path) do |result|
73
+ Rsync.run("-av", @config.path(with_trailing: true), @config.mirror.path) do |result|
73
74
  if result.success?
74
75
  puts "Mirror sync complete."
75
76
  result.changes.each do |change|
@@ -82,6 +83,25 @@ class Repository
82
83
  end
83
84
  end
84
85
 
86
+ # Lists the files in the repository
87
+ def ls(direction = :desc)
88
+ raise ArgumentError, "Must be one of: " + VALID_DIRECTION unless VALID_DIRECTION.include?(direction.to_sym)
89
+
90
+ Dir.glob(File.join(@config.path, "*_#{DEFAULT_LOG_SUFFIX}")).sort_by do |fpath|
91
+ # The date is joined by two underscores to the suffix
92
+ date, = File.basename(fpath).split("__")
93
+
94
+ time_ms = Time.strptime(date, "%m-%d-%Y").to_i
95
+
96
+ # Descending
97
+ if direction == :asc
98
+ time_ms
99
+ else
100
+ -time_ms
101
+ end
102
+ end
103
+ end
104
+
85
105
  class << self
86
106
  # Loads a repository from the provided path
87
107
  #
@@ -105,15 +125,16 @@ class Repository
105
125
  # Config is a configuration data object for storing Repository configuration
106
126
  # in memory for access.
107
127
  class Config
108
- attr_reader :name, :description, :mirror, :path
128
+ attr_reader :name, :description, :mirror, :path_value
109
129
 
130
+ # Configuration associated with the Mirror
110
131
  MirrorConfig = Struct.new(:use_mirror, :path, keyword_init: true)
111
132
 
112
133
  def initialize(name, desc, mirror, p)
113
134
  @name = name
114
135
  @description = desc
115
136
  @mirror = MirrorConfig.new(mirror)
116
- @path = p
137
+ @path_value = p
117
138
  end
118
139
 
119
140
  # Returns whether or not the devlogs repository is configured to mirror
@@ -123,6 +144,14 @@ class Repository
123
144
  @mirror.use_mirror
124
145
  end
125
146
 
147
+ def path(with_trailing: false)
148
+ if with_trailing
149
+ @path_value[-1] == "/" ? @path_value : @path_value + "/"
150
+ else
151
+ @path_value
152
+ end
153
+ end
154
+
126
155
  # Utility method to build a configuration from a Hash
127
156
  #
128
157
  # @returns [Repository::Config]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Devlogs
4
- VERSION = "0.1.6"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devlogs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aquaflamingo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-21 00:00:00.000000000 Z
11
+ date: 2022-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rsync
@@ -95,6 +95,7 @@ files:
95
95
  - exe/devlogs
96
96
  - lib/devlogs.rb
97
97
  - lib/devlogs/cli.rb
98
+ - lib/devlogs/editor.rb
98
99
  - lib/devlogs/repository.rb
99
100
  - lib/devlogs/version.rb
100
101
  homepage: http://github.com/aquaflamingo/devlogs