|
1 | | -package.path = package.path ..";3rd/json.lua/?.lua" |
| 1 | +package.path = package.path..";3rd/json.lua/?.lua" |
2 | 2 |
|
3 | 3 | local fs = require 'bee.filesystem' |
4 | 4 | local OS = require 'bee.platform'.os |
5 | | -local json = require "json" |
6 | | - |
7 | | -local function readall(filename) |
8 | | - local f <close> = assert(io.open(filename, 'rb')) |
9 | | - return f:read 'a' |
10 | | -end |
11 | | - |
12 | | -local function getExtensionDirName(packageDir) |
13 | | - local package = assert(json.decode(readall(packageDir .. '/package.json'))) |
14 | | - local publisher = package.publisher |
15 | | - local name = package.name |
16 | | - local version = package.version |
17 | | - if not publisher then |
18 | | - error 'Cannot found `publisher` in package.json.' |
19 | | - end |
20 | | - if not name then |
21 | | - error 'Cannot found `name` in package.json.' |
22 | | - end |
23 | | - if not version then |
24 | | - error 'Cannot found `version` in package.json.' |
25 | | - end |
26 | | - return ('%s.%s-%s'):format(publisher,name,version) |
27 | | -end |
28 | 5 |
|
29 | 6 | local function crtdll(path) |
30 | 7 | if path:find("api-ms-win-", 1, true) then |
@@ -66,57 +43,7 @@ local function copy_directory(from, to, filter) |
66 | 43 | end |
67 | 44 | end |
68 | 45 |
|
69 | | -local function what_arch() |
70 | | - if OS == "windows" then |
71 | | - if os.getenv "PROCESSOR_ARCHITECTURE" == "ARM64" then |
72 | | - return "arm64" |
73 | | - end |
74 | | - if os.getenv "PROCESSOR_ARCHITECTURE" == "AMD64" or os.getenv "PROCESSOR_ARCHITEW6432" == "AMD64" then |
75 | | - return "x64" |
76 | | - end |
77 | | - return "ia32" |
78 | | - end |
79 | | - local f <close> = assert(io.popen("uname -m", 'r')) |
80 | | - return f:read 'l':lower() |
81 | | -end |
82 | | - |
83 | | -local function detectPlatform(extensionPath, extensionDirName) |
84 | | - local extensionDirPrefix = fs.path(extensionPath) / extensionDirName |
85 | | - local function guess(platform) |
86 | | - local extensionDir = extensionDirPrefix..platform |
87 | | - if fs.exists(extensionDir / "package.json") then |
88 | | - return extensionDir |
89 | | - end |
90 | | - end |
91 | | - local arch = what_arch() |
92 | | - if OS == "windows" then |
93 | | - local r = guess '-win32-x64' |
94 | | - if r then return r end |
95 | | - elseif OS == "linux" then |
96 | | - if arch == "x86_64" then |
97 | | - local r = guess '-linux-x64' |
98 | | - if r then return r end |
99 | | - elseif arch == "aarch64" then |
100 | | - local r = guess '-linux-arm64' |
101 | | - if r then return r end |
102 | | - end |
103 | | - elseif OS == "macos" then |
104 | | - if arch == "arm64" then |
105 | | - local r = guess '-darwin-arm64' |
106 | | - if r then return r end |
107 | | - end |
108 | | - local r = guess '-darwin-x64' |
109 | | - if r then return r end |
110 | | - end |
111 | | - local r = guess '' |
112 | | - if r then return r end |
113 | | - error("`" .. extensionDirPrefix:string() .. "` is not installed.") |
114 | | -end |
115 | | - |
116 | | -local packageDir,sourceDir,extensionPath = ... |
117 | | -local extensionDirName = getExtensionDirName(packageDir) |
118 | | -local extensionDir = detectPlatform(extensionPath, extensionDirName) |
119 | | - |
| 46 | +local sourceDir, extensionDir = ... |
120 | 47 | local sourceDir = fs.path(sourceDir) |
121 | 48 | copy_directory(sourceDir, extensionDir, function (path) |
122 | 49 | local ext = path:extension() |
|
0 commit comments