| 176 | /// and |
| 177 | /// const { a, b, c } = imports.gi.Source; |
| 178 | function convertImports(text: string) { |
| 179 | const giImports = [ |
| 180 | ['clutter', "'gi://Clutter'"], |
| 181 | ['cogl', "'gi://Cogl'"], |
| 182 | ['gdk', "'gi://Gdk'"], |
| 183 | ['gio', "'gi://Gio'"], |
| 184 | ['glib', "'gi://GLib'"], |
| 185 | ['gnomedesktop', "'gi://GnomeDesktop'"], |
| 186 | ['gobject', "'gi://GObject'"], |
| 187 | ['gtk', "'gi://Gtk'"], |
| 188 | ['meta', "'gi://Meta'"], |
| 189 | ['shell', "'gi://Shell'"], |
| 190 | ['soup', "'gi://Soup'"], |
| 191 | ['st', "'gi://St'"], |
| 192 | ['gjs', 'imports'], |
| 193 | ['ui', "'resource:///org/gnome/shell/ui/main.js'"], |
| 194 | ]; |
| 195 | |
| 196 | const regexes: [RegExp, string][] = giImports.map((x) => { |
| 197 | const [name, importpath] = x; |
| 198 | return [ |
| 199 | new RegExp( |
| 200 | 'import \\* as ([\\w\\d]+) from [\'"]' + name + '[\'"];', |
| 201 | 'g' |
| 202 | ), |
| 203 | 'import $1 from ' + importpath + ';', |
| 204 | ]; |
| 205 | }); |
| 206 | |
| 207 | const regexes2: [RegExp, string][] = giImports.map((x) => { |
| 208 | const [name, importpath] = x; |
| 209 | return [ |
| 210 | new RegExp( |
| 211 | 'import \\{([^\\}]+)\\} from [\'"]' + name + '[\'"];', |
| 212 | 'g' |
| 213 | ), |
| 214 | 'import {$1} from ' + importpath + ';', |
| 215 | ]; |
| 216 | }); |
| 217 | |
| 218 | const regexes3: [RegExp, string][] = giImports.map((x) => { |
| 219 | const [name, importpath] = x; |
| 220 | return [ |
| 221 | new RegExp(`(const {.+) as (.+} = ${importpath};)`, 'g'), |
| 222 | '$1: $2', |
| 223 | ]; |
| 224 | }); |
| 225 | |
| 226 | for (let regex of regexes) { |
| 227 | text = text.replace(regex[0], regex[1]); |
| 228 | } |
| 229 | |
| 230 | for (let regex of regexes2) { |
| 231 | text = text.replace(regex[0], regex[1]); |
| 232 | } |
| 233 | |
| 234 | for (let i = 0; i < 3; i++) { |
| 235 | for (let regex of regexes3) { |