Skip to content

Commit

Permalink
fix(init): Enhance guessed package name and entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Dec 6, 2023
1 parent 130345b commit 970ee8a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
33 changes: 26 additions & 7 deletions cmds/core/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,18 @@ async function create_eask_file(dir) {

// Starting writing Eask-file!
let name, version, description, entry_point, emacs_version, website_url, keywords;
await ask(`package name: (${basename}) `, (answer) => { name = answer || basename; });

let guessed_package_name = guess_package_name(basename);
let guessed_entry_point = guess_entry_point(basename);

await ask(`package name: (${guessed_package_name}) `, (answer) => {
name = answer || guessed_package_name;
});
await ask(`version: (1.0.0) `, (answer) => { version = answer || '1.0.0'; });
await ask(`description: `, (answer) => { description = answer; });
await ask(`entry point: (${guess_entry_point(basename)}) `, (answer) => { entry_point = answer || `${basename}.el`; });
await ask(`entry point: (${guessed_entry_point}) `, (answer) => {
entry_point = answer || guessed_entry_point;
});
await ask(`emacs version: (26.1) `, (answer) => { emacs_version = answer || '26.1'; });
await ask(`website: `, (answer) => { website_url = answer; });
await ask(`keywords: `, (answer) => { keywords = answer; });
Expand Down Expand Up @@ -189,14 +197,25 @@ function check_eask_filename(name) {
}

/**
* Return the guess entry point by its basname.
* @param { String } basename - The directory name.
* Return the guessed project name by its basename.
* @param { String } basename - The working directory name.
* @return Guessed project name.
*/
function guess_package_name(basename) {
basename = basename.toLowerCase();
basename = basename.replaceAll('emacs-', '');
basename = basename.replaceAll('-emacs', '');
basename = basename.replace(/[-.]el$/, '');
return basename;
}

/**
* Return the guessed entry point by its basname.
* @param { String } basename - The working directory name.
* @return Guessed entry point filename.
*/
function guess_entry_point(basename) {
if (basename.endsWith(".el")) {
return basename;
}
basename = guess_package_name(basename);
return basename + ".el";
}

Expand Down
35 changes: 23 additions & 12 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,29 @@ The function `directory-empty-p' only exists 28.1 or above; copied it."
;; 27.2 or lower!
(null (directory-files dir nil directory-files-no-dot-files-regexp t)))))

(defun eask-guess-package-name ()
"Return the possible package name."
(or (eask-package-name)
(ignore-errors (file-name-nondirectory
(file-name-sans-extension eask-package-file)))))

(defun eask-guess-entry-point (&optional project-name)
"Return the guess entry point by its PROJECT-NAME."
(let ((project-name (or project-name (eask-guess-package-name))))
(if (string-suffix-p ".el" project-name)
project-name
(format "%s.el" project-name))))
(defun eask--guess-package-name (basename)
"Convert the BASENAME to a valid, commonly seen package name."
(when-let ((name (downcase basename)))
(setq name (eask-s-replace "emacs-" "" name)
name (eask-s-replace "-emacs" "" name)
name (replace-regexp-in-string "[.-]el$" "" name))
name))

(defun eask-guess-package-name (&optional basename)
"Return the possible package name.
Optional argument BASENAME accepts a string; it will convert the string to a
valid, commonly seen package name."
(or (eask--guess-package-name basename)
(eask-package-name)
(eask--guess-package-name
(ignore-errors (file-name-nondirectory
(file-name-sans-extension eask-package-file))))))

(defun eask-guess-entry-point (&optional basename)
"Return the guess entry point by its BASENAME."
(let ((name (eask-guess-package-name basename)))
(format "%s.el" name)))

(defun eask-read-string (prompt &optional
initial-input
Expand Down

0 comments on commit 970ee8a

Please sign in to comment.