Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cask): Add option to convert Cask to Eask #145

Merged
merged 4 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* Allow linter list through all errors (#134 and #137)
* Omit `nil` value for conditions in `development` scope (#143 and #144)
* Move `pkg-file` and `autoloads` commands under `generate` subcommand (#142)
* Add option to convert Cask to Eask (#141 and #145)

## 0.7.x
> Released Sep 08, 2022
Expand Down
37 changes: 31 additions & 6 deletions cmds/core/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,40 @@ const path = require('path');
const fs = require('fs');
const readline = require('readline');

var instance; /* `readline` instance */

exports.command = ['init'];
exports.desc = 'Create new Eask file in current directory';
exports.command = ['init [files..]'];
exports.desc = 'Initialize project to use Eask';
exports.builder = {
from: {
description: 'build from an existing package',
requiresArg: true,
type: 'string',
},
files: {
description: 'files to use with `from` flag',
requiresArg: false,
type: 'array',
},
};

exports.handler = async ({}) => {
await create_eask_file();
exports.handler = async (argv) => {
if (argv.from) {
switch (argv.from) {
case 'cask':
await UTIL.e_call(argv, 'init/cask'
, UTIL.def_flag(argv.from, '--from', argv.from)
, argv.files);
break;
default:
console.log(`Invalid argument, from: ${argv.from}`);
break;
}
} else {
await create_eask_file();
}
};

var instance; /* `readline` instance */

async function create_eask_file(dir) {
let basename = path.basename(process.cwd());
instance = readline.createInterface({
Expand Down
4 changes: 2 additions & 2 deletions docs/content/en/Getting Started/Basic Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ Commands:
path [patterns..] Print the PATH (exec-path) from workspace [aliases: exec-path]
exec [args..] Execute command with correct environment PATH set up
files [patterns..] Print all package files
generate <type> Generate files use for development
generate <type> Generate files that are used for the development
info Display information about the current package
init Create new Eask file in current directory
init [files..] Initialize project to use Eask
install-deps Automatically install package dependencies [aliases: install-dependencies, prepare]
install [names..] Install packages
keywords List available keywords that can be used in the header section
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/Getting Started/Commands and options.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Often use commands that are uncategorized.

## 🔍 eask init

Eask will generate file like:
Eask will generate the file like this:

```elisp
(package "PACKAGE-NAME"
Expand Down
27 changes: 22 additions & 5 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ will return `lint-checkdoc' with a dash between two subcommands."

(defun eask-special-p ()
"Return t if the command that can be run without Eask-file existence."
(member (eask-command) '("keywords")))
(member (eask-command) '("init-cask" "keywords")))

(defun eask-checker-p ()
"Return t if running Eask as the checker."
Expand Down Expand Up @@ -454,6 +454,7 @@ the `eask-start' execution.")
(defun eask-no-proxy () (eask--flag-value "--no-proxy")) ; --no-proxy
(defun eask-destination () (eask--flag-value "--dest")) ; --dest, --destination
(defalias 'eask-dest #'eask-destination)
(defun eask-from () (eask--flag-value "--from")) ; --from

;;; Number (with arguments)
(defun eask-depth () (eask--str2num (eask--flag-value "--depth"))) ; --depth
Expand Down Expand Up @@ -517,7 +518,8 @@ other scripts internally. See function `eask-call'.")
'("--output"
"--proxy" "--http-proxy" "--https-proxy" "--no-proxy"
"--verbose" "--silent"
"--depth" "--dest"))
"--depth" "--dest"
"--from"))
"List of arguments (number/string) type options.")

(defconst eask--command-list
Expand Down Expand Up @@ -604,7 +606,8 @@ Eask file in the workspace."

(defun eask-root-del (filename)
"Remove Eask file root path from FILENAME."
(when (stringp filename) (eask-s-replace eask-file-root "" filename)))
(when (stringp filename)
(eask-s-replace (or eask-file-root default-directory) "" filename)))

(defun eask-file-load (location &optional noerror)
"Load Eask file in the LOCATION."
Expand Down Expand Up @@ -1276,15 +1279,29 @@ Standard is, 0 (error), 1 (warning), 2 (info), 3 (log), 4 or above (debug)."
;;
;;; Help

(defun eask--help-display ()
"Display help instruction."
(goto-char (point-min))
(let ((max-column 0))
(while (not (eobp))
(forward-line 1)
(goto-char (line-beginning-position))
(insert " ")
(goto-char (line-end-position))
(setq max-column (max (current-column) max-column)))
(eask-msg (concat "''" (spaces-string max-column) "''"))
(eask-msg (ansi-white (buffer-string)))
(eask-msg (concat "''" (spaces-string max-column) "'" "'"))))

(defun eask-help (command)
"Show help."
"Show COMMAND's help instruction."
(let* ((command (eask-2str command)) ; convert to string
(help-file (concat eask-lisp-root "help/" command)))
(if (file-exists-p help-file)
(with-temp-buffer
(insert-file-contents help-file)
(unless (string= (buffer-string) "")
(eask-msg (ansi-white (buffer-string)))))
(eask--help-display)))
(eask-error "Help manual missig %s" help-file))))

;;
Expand Down
6 changes: 6 additions & 0 deletions lisp/help/init/cask
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

💡 Make sure you have a valid Cask-file in your directory

💡 Or specify Cask-file explicitly, like:

$ eask init --from=cask /path/to/Cask
66 changes: 66 additions & 0 deletions lisp/init/cask.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
;;; init/cask.el --- Initialize Eask from Cask -*- lexical-binding: t; -*-

;;; Commentary:
;;
;; Commmand use to convert Cask-file to Eask-file
;;
;; $ eask init --from cask
;;

;;; Code:

(load (expand-file-name
"../_prepare.el"
(file-name-directory (nth 1 (member "-scriptload" command-line-args))))
nil t)

(defun eask--convert-cask (filename)
"Convert Cask FILENAME to Eask."
(let* ((filename (expand-file-name filename))
(file (eask-root-del filename))
(new-file (eask-s-replace "Cask" "Eask" file))
(new-filename (expand-file-name new-file))
(converted))
(eask-with-progress
(format "Converting file `%s` to `%s`... " file new-file)
(eask-with-verbosity 'debug
(cond ((not (string-prefix-p "Cask" file))
(eask-debug "✗ Invalid Cask filename, the file should start with `Cask`"))
((file-exists-p new-filename)
(eask-debug "✗ The file `%s` already presented" new-file))
(t
(with-current-buffer (find-file new-filename)
(insert-file-contents file)
(goto-char (point-min))
(while (re-search-forward "(source " nil t)
(insert "'")) ; make it symbol
(save-buffer))
(setq converted t))))
(if converted "done ✓" "skipped ✗"))
converted))

(eask-start
(let* ((patterns (eask-args))
(files (if patterns
(eask-expand-file-specs patterns)
(directory-files default-directory t "Cask")))
(converted 0))
(cond
;; Files found, do the action!
(files
(dolist (file files)
(when (eask--convert-cask file)
(cl-incf converted)))
(eask-msg "")
(eask-info "(Total of %s Cask-file%s converted)" converted
(eask--sinr converted "" "s")))
;; Pattern defined, but no file found!
(patterns
(eask-info "No files found with wildcard pattern: %s"
(mapconcat #'identity patterns " ")))
;; Default, print help!
(t
(eask-info "(No Cask-files have been converted to Eask)")
(eask-help "init/cask")))))

;;; init/cask.el ends here
1 change: 0 additions & 1 deletion lisp/lint/checkdoc.el
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
(mapconcat #'identity patterns " ")))
;; Default, print help!
(t
(eask-msg "")
(eask-info "(No files have been checked (checkdoc))")
(eask-help "lint/checkdoc")))))

Expand Down
1 change: 0 additions & 1 deletion lisp/lint/declare.el
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
(mapconcat #'identity patterns " ")))
;; Default, print help!
(t
(eask-msg "")
(eask-info "(No files have been checked (declare))")
(eask-help "lint/declare")))))

Expand Down
1 change: 0 additions & 1 deletion lisp/lint/indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
(mapconcat #'identity patterns " ")))
;; Default, print help!
(t
(eask-msg "")
(eask-info "(No files have been linted)")
(eask-help "lint/indent")))))

Expand Down