Я пытаюсь преобразовать проект из coffeescript в javascript.Я успешно использовал инструмент decaffeinate, но что-то скучно преобразовывать вручную: комментарии JSdoc
В coffescript мы привыкли писать их, как в формализме этого примера:
##
# This will remove the given file from the machine attachments list. If the file was previously uploaded
# to the server, it will be marked for deletion on the server. Otherwise, it will be simply truncated from
# the attachments array.
# @param file {Object} the file to delete
# @returns {boolean}
##
После использования decaffeinate они были преобразованы в нечто вроде этого:
// #
// This will remove the given file from the machine attachments list. If the file was previously uploaded
// to the server, it will be marked for deletion on the server. Otherwise, it will be simply truncated from
// the attachments array.
// @param file {Object} the file to delete
// @returns {boolean}
// #
Поэтому я попытался написать регулярное выражение perl, чтобы они выглядели как стандартный синтаксис JSdoc.Но я застрял с центральными линиями: я не могу найти способ поставить звезду в начале каждой строки ... Вот лучшее, к чему я пришел:
find . -type f -name "*.js" | xargs perl -0777 -i -pe 's~// #\n( +// (.+\n)+)( +)// #~/**\n$1$3 */~gm;'
Какие результатыв:
/**
// This will remove the given file from the machine attachments list. If the file was previously uploaded
// to the server, it will be marked for deletion on the server. Otherwise, it will be simply truncated from
// the attachments array.
// @param file {Object} the file to delete
// @returns {boolean}
*/
Но в идеале его следует преобразовать в:
/**
* This will remove the given file from the machine attachments list. If the file was previously uploaded
* to the server, it will be marked for deletion on the server. Otherwise, it will be simply truncated from
* the attachments array.
* @param file {Object} the file to delete
* @returns {boolean}
*/
Вот пример полного файла для преобразования: https://gist.github.com/sylvainbx/96e53b879b4dd7ef7cdd153c3fc3c5b8
Любая помощьбыл бы оценен:)