vbapm 0.6.3-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +246 -0
- package/lib/_commonjsHelpers-553b27b3.js +2 -0
- package/lib/_commonjsHelpers-553b27b3.js.map +1 -0
- package/lib/build-project-55e5df48.js +4 -0
- package/lib/build-project-55e5df48.js.map +1 -0
- package/lib/build-target-283e1e7d.js +10 -0
- package/lib/build-target-283e1e7d.js.map +1 -0
- package/lib/create-project-905598ca.js +11 -0
- package/lib/create-project-905598ca.js.map +1 -0
- package/lib/debug.js +2 -0
- package/lib/debug.js.map +1 -0
- package/lib/export-project-55168787.js +5 -0
- package/lib/export-project-55168787.js.map +1 -0
- package/lib/export-target-c9ddd2fa.js +5 -0
- package/lib/export-target-c9ddd2fa.js.map +1 -0
- package/lib/get-target-23b8cc04.js +12 -0
- package/lib/get-target-23b8cc04.js.map +1 -0
- package/lib/index-35cff1d5.js +38 -0
- package/lib/index-35cff1d5.js.map +1 -0
- package/lib/index-87f55e79.js +4 -0
- package/lib/index-87f55e79.js.map +1 -0
- package/lib/index-b49bd5b2.js +2 -0
- package/lib/index-b49bd5b2.js.map +1 -0
- package/lib/index-c97017db.js +2 -0
- package/lib/index-c97017db.js.map +1 -0
- package/lib/index-d9ba3ba0.js +6 -0
- package/lib/index-d9ba3ba0.js.map +1 -0
- package/lib/index-ffbba08f.js +3 -0
- package/lib/index-ffbba08f.js.map +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/inherits-713f4554.js +2 -0
- package/lib/inherits-713f4554.js.map +1 -0
- package/lib/init-project-a62cb644.js +16 -0
- package/lib/init-project-a62cb644.js.map +1 -0
- package/lib/load-from-project-e6530a69.js +6 -0
- package/lib/load-from-project-e6530a69.js.map +1 -0
- package/lib/minimatch-3a1d1fa9.js +2 -0
- package/lib/minimatch-3a1d1fa9.js.map +1 -0
- package/lib/once-9eb67b4f.js +2 -0
- package/lib/once-9eb67b4f.js.map +1 -0
- package/lib/project-d43b4e0c.js +30 -0
- package/lib/project-d43b4e0c.js.map +1 -0
- package/lib/run-macro-f4aa7c14.js +2 -0
- package/lib/run-macro-f4aa7c14.js.map +1 -0
- package/lib/sat-solver-01d6409e.js +2 -0
- package/lib/sat-solver-01d6409e.js.map +1 -0
- package/lib/src/actions/build-project.d.ts +2 -0
- package/lib/src/actions/create-project.d.ts +8 -0
- package/lib/src/actions/export-project.d.ts +6 -0
- package/lib/src/actions/increment-version.d.ts +5 -0
- package/lib/src/actions/init-project.d.ts +9 -0
- package/lib/src/actions/run-macro.d.ts +8 -0
- package/lib/src/actions/test-project.d.ts +5 -0
- package/lib/src/addin.d.ts +36 -0
- package/lib/src/bin/vba-blocks-build.d.ts +2 -0
- package/lib/src/bin/vba-blocks-export.d.ts +2 -0
- package/lib/src/bin/vba-blocks-init.d.ts +2 -0
- package/lib/src/bin/vba-blocks-new.d.ts +2 -0
- package/lib/src/bin/vba-blocks-run.d.ts +2 -0
- package/lib/src/bin/vba-blocks-test.d.ts +2 -0
- package/lib/src/bin/vba-blocks-version.d.ts +2 -0
- package/lib/src/bin/vba-blocks.d.ts +2 -0
- package/lib/src/build/apply-changeset.d.ts +3 -0
- package/lib/src/build/build-graph.d.ts +18 -0
- package/lib/src/build/changeset.d.ts +14 -0
- package/lib/src/build/compare-build-graphs.d.ts +3 -0
- package/lib/src/build/component.d.ts +25 -0
- package/lib/src/build/index.d.ts +7 -0
- package/lib/src/build/load-from-export.d.ts +2 -0
- package/lib/src/build/load-from-project.d.ts +5 -0
- package/lib/src/build/stage-build-graph.d.ts +2 -0
- package/lib/src/build/transform-build-graph.d.ts +3 -0
- package/lib/src/build/transforms/editor-config.d.ts +3 -0
- package/lib/src/cache.d.ts +9 -0
- package/lib/src/config.d.ts +29 -0
- package/lib/src/debug.d.ts +2 -0
- package/lib/src/env.d.ts +21 -0
- package/lib/src/errors.d.ts +56 -0
- package/lib/src/index.d.ts +16 -0
- package/lib/src/installer.d.ts +3 -0
- package/lib/src/lockfile/index.d.ts +23 -0
- package/lib/src/lockfile/is-lockfile-valid.d.ts +10 -0
- package/lib/src/lockfile/lockfile.d.ts +26 -0
- package/lib/src/manifest/dependency.d.ts +25 -0
- package/lib/src/manifest/index.d.ts +34 -0
- package/lib/src/manifest/reference.d.ts +12 -0
- package/lib/src/manifest/source.d.ts +8 -0
- package/lib/src/manifest/target.d.ts +10 -0
- package/lib/src/manifest/version.d.ts +3 -0
- package/lib/src/messages.d.ts +22 -0
- package/lib/src/professional/sources/git-source.d.ts +7 -0
- package/lib/src/professional/workspace.d.ts +10 -0
- package/lib/src/project.d.ts +48 -0
- package/lib/src/reporter.d.ts +12 -0
- package/lib/src/resolve/dependency-graph.d.ts +4 -0
- package/lib/src/resolve/index.d.ts +6 -0
- package/lib/src/resolve/latest-solver.d.ts +8 -0
- package/lib/src/resolve/resolver.d.ts +23 -0
- package/lib/src/resolve/sat-solver.d.ts +7 -0
- package/lib/src/sources/index.d.ts +16 -0
- package/lib/src/sources/path-source.d.ts +7 -0
- package/lib/src/sources/registration.d.ts +17 -0
- package/lib/src/sources/registry-source.d.ts +32 -0
- package/lib/src/sources/source.d.ts +6 -0
- package/lib/src/targets/add-target.d.ts +8 -0
- package/lib/src/targets/build-target.d.ts +41 -0
- package/lib/src/targets/export-target.d.ts +15 -0
- package/lib/src/targets/get-target.d.ts +7 -0
- package/lib/src/targets/index.d.ts +3 -0
- package/lib/src/targets/project-info.d.ts +7 -0
- package/lib/src/targets/transform-target.d.ts +3 -0
- package/lib/src/targets/transforms/core-xml.d.ts +2 -0
- package/lib/src/targets/transforms/workbook-xml.d.ts +2 -0
- package/lib/src/utils/async-map.d.ts +4 -0
- package/lib/src/utils/download.d.ts +1 -0
- package/lib/src/utils/fs.d.ts +23 -0
- package/lib/src/utils/get-staging.d.ts +1 -0
- package/lib/src/utils/git.d.ts +4 -0
- package/lib/src/utils/github.d.ts +9 -0
- package/lib/src/utils/has.d.ts +1 -0
- package/lib/src/utils/hash.d.ts +8 -0
- package/lib/src/utils/interop.d.ts +1 -0
- package/lib/src/utils/is.d.ts +5 -0
- package/lib/src/utils/noop.d.ts +1 -0
- package/lib/src/utils/observable.d.ts +15 -0
- package/lib/src/utils/parallel.d.ts +6 -0
- package/lib/src/utils/path.d.ts +7 -0
- package/lib/src/utils/pipe.d.ts +5 -0
- package/lib/src/utils/run.d.ts +17 -0
- package/lib/src/utils/stdout-file.d.ts +3 -0
- package/lib/src/utils/text.d.ts +4 -0
- package/lib/src/utils/toml.d.ts +4 -0
- package/lib/src/utils/unique.d.ts +1 -0
- package/lib/src/utils/without.d.ts +1 -0
- package/lib/src/utils/xml.d.ts +10 -0
- package/lib/src/utils/zip.d.ts +17 -0
- package/lib/test-project-d4f237d1.js +2 -0
- package/lib/test-project-d4f237d1.js.map +1 -0
- package/lib/text-ba532b40.js +10 -0
- package/lib/text-ba532b40.js.map +1 -0
- package/lib/tmp-bc08ebcf.js +10 -0
- package/lib/tmp-bc08ebcf.js.map +1 -0
- package/lib/toml-patch.es-6bd2145d.js +4 -0
- package/lib/toml-patch.es-6bd2145d.js.map +1 -0
- package/lib/vba-blocks-build-a717fcdb.js +10 -0
- package/lib/vba-blocks-build-a717fcdb.js.map +1 -0
- package/lib/vba-blocks-export-7e2c75cc.js +8 -0
- package/lib/vba-blocks-export-7e2c75cc.js.map +1 -0
- package/lib/vba-blocks-init-54531020.js +17 -0
- package/lib/vba-blocks-init-54531020.js.map +1 -0
- package/lib/vba-blocks-new-3210d92c.js +18 -0
- package/lib/vba-blocks-new-3210d92c.js.map +1 -0
- package/lib/vba-blocks-run-ab9d4ad4.js +11 -0
- package/lib/vba-blocks-run-ab9d4ad4.js.map +1 -0
- package/lib/vba-blocks-test-da5dba90.js +16 -0
- package/lib/vba-blocks-test-da5dba90.js.map +1 -0
- package/lib/vba-blocks-version-e1b3c35a.js +9 -0
- package/lib/vba-blocks-version-e1b3c35a.js.map +1 -0
- package/lib/vba-blocks.js +43 -0
- package/lib/vba-blocks.js.map +1 -0
- package/lib/workbook-xml-69fff4ae.js +3 -0
- package/lib/workbook-xml-69fff4ae.js.map +1 -0
- package/package.json +116 -0
- package/run-scripts/run.applescript +78 -0
- package/run-scripts/run.ps1 +211 -0
package/package.json
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vbapm",
|
|
3
|
+
"version": "0.6.3-alpha",
|
|
4
|
+
"description": "A package manager and build tool for VBA",
|
|
5
|
+
"contributors": [
|
|
6
|
+
"Tim Hall <tim.hall.engr@gmail.com>",
|
|
7
|
+
"Martin Leduc <31558169+DecimalTurn@users.noreply.github.com>"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"homepage": "https://github.com/vbapm/core",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/vbapm/core.git"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=18.0.0"
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"vba-blocks": "lib/vba-blocks.js",
|
|
20
|
+
"vba": "lib/vba-blocks.js"
|
|
21
|
+
},
|
|
22
|
+
"main": "lib/index.js",
|
|
23
|
+
"types": "lib/src/index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"require": "./lib/index.js",
|
|
27
|
+
"types": "./lib/src/index.d.ts"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"lib/",
|
|
32
|
+
"addins/build/",
|
|
33
|
+
"run-scripts/",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"format": "prettier --write \"**/*.{ts,js}\"",
|
|
39
|
+
"test": "jest --runInBand",
|
|
40
|
+
"typecheck": "tsc",
|
|
41
|
+
"test:e2e": "jest --config e2e.config.js --runInBand",
|
|
42
|
+
"build": "rimraf lib && rollup -c && tsc -p tsconfig.build.json",
|
|
43
|
+
"build:dev": "cross-env NODE_ENV=development rollup -c",
|
|
44
|
+
"build:addins": "cd addins && node --no-warnings ../scripts/build-addins",
|
|
45
|
+
"build:bootstrap": "cd scripts/bootstrap && node --no-warnings ../../lib/vba-blocks build",
|
|
46
|
+
"prepublishOnly": "npm run build",
|
|
47
|
+
"postversion": "git push && git push --tags",
|
|
48
|
+
"clean": "rimraf lib && rimraf dist && rimraf addins/build"
|
|
49
|
+
},
|
|
50
|
+
"jest": {
|
|
51
|
+
"preset": "ts-jest",
|
|
52
|
+
"testEnvironment": "node",
|
|
53
|
+
"testPathIgnorePatterns": [
|
|
54
|
+
"/node_modules/",
|
|
55
|
+
"/lib/"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@decimalturn/toml-patch": "^0.7.0",
|
|
60
|
+
"@timhall/ansi-colors": "^5.0.0",
|
|
61
|
+
"@timhall/dedent": "^0.9.1",
|
|
62
|
+
"archiver": "^3",
|
|
63
|
+
"conf": "^3",
|
|
64
|
+
"date-fns": "^2",
|
|
65
|
+
"debug": "^4",
|
|
66
|
+
"decompress": "^4",
|
|
67
|
+
"editorconfig": "^0.15.3",
|
|
68
|
+
"env-paths": "^2",
|
|
69
|
+
"fs-extra": "^7",
|
|
70
|
+
"isomorphic-git": "^1.8.2",
|
|
71
|
+
"logic-solver": "^2",
|
|
72
|
+
"meant": "^1.0",
|
|
73
|
+
"mri": "^1",
|
|
74
|
+
"node-fetch": "^2",
|
|
75
|
+
"open": "^6",
|
|
76
|
+
"pretty-hrtime": "^1",
|
|
77
|
+
"sanitize-filename": "^1",
|
|
78
|
+
"semver": "^5",
|
|
79
|
+
"tmp": "^0.0",
|
|
80
|
+
"walk-sync": "^1",
|
|
81
|
+
"xml-js": "^1.6"
|
|
82
|
+
},
|
|
83
|
+
"devDependencies": {
|
|
84
|
+
"@octokit/core": "^3.1.4",
|
|
85
|
+
"@octokit/rest": "^16.21.1",
|
|
86
|
+
"@rollup/plugin-commonjs": "^15.1.0",
|
|
87
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
88
|
+
"@rollup/plugin-node-resolve": "^9.0.0",
|
|
89
|
+
"@rollup/plugin-replace": "^2.3.3",
|
|
90
|
+
"@rollup/plugin-typescript": "^6.0.0",
|
|
91
|
+
"@types/archiver": "^2",
|
|
92
|
+
"@types/fs-extra": "^5",
|
|
93
|
+
"@types/glob": "^7.2.0",
|
|
94
|
+
"@types/jest": "^23",
|
|
95
|
+
"@types/node": "^10",
|
|
96
|
+
"@types/node-fetch": "^2.1.7",
|
|
97
|
+
"@types/semver": "^5",
|
|
98
|
+
"@types/tmp": "^0.0",
|
|
99
|
+
"aws-sdk": "^2.562.0",
|
|
100
|
+
"builtin-modules": "^3.0.0",
|
|
101
|
+
"cross-env": "^5",
|
|
102
|
+
"dotenv": "^7.0.0",
|
|
103
|
+
"editor": "^1.0.0",
|
|
104
|
+
"jest": "^26.6.1",
|
|
105
|
+
"mustache": "^3",
|
|
106
|
+
"npm-run-all": "^4",
|
|
107
|
+
"prettier": "^1",
|
|
108
|
+
"rimraf": "^2",
|
|
109
|
+
"rollup": "^2.32.1",
|
|
110
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
111
|
+
"ts-jest": "^26.4.2",
|
|
112
|
+
"tslib": "^1.9.3",
|
|
113
|
+
"typescript": "^4.9.5",
|
|
114
|
+
"url-join": "^4.0.1"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
-- Arguments
|
|
2
|
+
--
|
|
3
|
+
-- appname (e.g. "excel")
|
|
4
|
+
-- addin: posix full path to addin (e.g. "...")
|
|
5
|
+
-- command: macro to execute in addin (e.g. "Build.ImportGraph")
|
|
6
|
+
-- ...args: arguments to pass to macro (up to 10)
|
|
7
|
+
|
|
8
|
+
on run argv
|
|
9
|
+
set output to ""
|
|
10
|
+
|
|
11
|
+
if (count of argv) >= 3 and (count of argv) <= 13 then
|
|
12
|
+
set appname to (item 1 of argv)
|
|
13
|
+
set addin to POSIX file (item 2 of argv)
|
|
14
|
+
set command to (item 3 of argv)
|
|
15
|
+
|
|
16
|
+
set args to {}
|
|
17
|
+
repeat with index from 4 to count of argv
|
|
18
|
+
set end of args to (item index of argv)
|
|
19
|
+
end repeat
|
|
20
|
+
|
|
21
|
+
if appname is "excel" then
|
|
22
|
+
set workbook_name to name of (info for addin)
|
|
23
|
+
|
|
24
|
+
tell application "Microsoft Excel"
|
|
25
|
+
set workbook_was_open to (exists workbook workbook_name)
|
|
26
|
+
if not workbook_was_open then
|
|
27
|
+
open workbook workbook file name addin without notify
|
|
28
|
+
end if
|
|
29
|
+
|
|
30
|
+
set output to output & my run_excel_macro(command, args)
|
|
31
|
+
|
|
32
|
+
if not workbook_was_open then
|
|
33
|
+
close workbook workbook_name saving yes
|
|
34
|
+
end if
|
|
35
|
+
end tell
|
|
36
|
+
end if
|
|
37
|
+
else
|
|
38
|
+
if (count of argv) < 3 then
|
|
39
|
+
set output to output & "ERROR #1: Invalid Input (appname, file, and macro are required"
|
|
40
|
+
else
|
|
41
|
+
set output to output & "ERROR #2: Invalid Input (only 10 arguments are supported)"
|
|
42
|
+
end if
|
|
43
|
+
end if
|
|
44
|
+
|
|
45
|
+
return output
|
|
46
|
+
end run
|
|
47
|
+
|
|
48
|
+
on run_excel_macro(command, args)
|
|
49
|
+
set result to ""
|
|
50
|
+
|
|
51
|
+
tell application "Microsoft Excel"
|
|
52
|
+
if (count of args) = 0 then
|
|
53
|
+
set result to result & (run VB macro command)
|
|
54
|
+
else if (count of args) = 1 then
|
|
55
|
+
set result to result & (run VB macro command arg1 (item 1 of args))
|
|
56
|
+
else if (count of args) = 2 then
|
|
57
|
+
set result to result & (run VB macro command arg1 (item 1 of args) arg2 (item 2 of args))
|
|
58
|
+
else if (count of args) = 3 then
|
|
59
|
+
set result to result & (run VB macro command arg1 (item 1 of args) arg2 (item 2 of args) arg3 (item 3 of args))
|
|
60
|
+
else if (count of args) = 4 then
|
|
61
|
+
set result to result & (run VB macro command arg1 (item 1 of args) arg2 (item 2 of args) arg3 (item 3 of args) arg4 (item 4 of args))
|
|
62
|
+
else if (count of args) = 5 then
|
|
63
|
+
set result to result & (run VB macro command arg1 (item 1 of args) arg2 (item 2 of args) arg3 (item 3 of args) arg4 (item 4 of args) arg5 (item 5 of args))
|
|
64
|
+
else if (count of args) = 6 then
|
|
65
|
+
set result to result & (run VB macro command arg1 (item 1 of args) arg2 (item 2 of args) arg3 (item 3 of args) arg4 (item 4 of args) arg5 (item 5 of args) arg6 (item 6 of args))
|
|
66
|
+
else if (count of args) = 7 then
|
|
67
|
+
set result to result & (run VB macro command arg1 (item 1 of args) arg2 (item 2 of args) arg3 (item 3 of args) arg4 (item 4 of args) arg5 (item 5 of args) arg6 (item 6 of args) arg7 (item 7 of args))
|
|
68
|
+
else if (count of args) = 8 then
|
|
69
|
+
set result to result & (run VB macro command arg1 (item 1 of args) arg2 (item 2 of args) arg3 (item 3 of args) arg4 (item 4 of args) arg5 (item 5 of args) arg6 (item 6 of args) arg7 (item 7 of args) arg8 (item 8 of args))
|
|
70
|
+
else if (count of args) = 9 then
|
|
71
|
+
set result to result & (run VB macro command arg1 (item 1 of args) arg2 (item 2 of args) arg3 (item 3 of args) arg4 (item 4 of args) arg5 (item 5 of args) arg6 (item 6 of args) arg7 (item 7 of args) arg8 (item 8 of args) arg9 (item 9 of args))
|
|
72
|
+
else if (count of args) = 10 then
|
|
73
|
+
set result to result & (run VB macro command arg1 (item 1 of args) arg2 (item 2 of args) arg3 (item 3 of args) arg4 (item 4 of args) arg5 (item 5 of args) arg6 (item 6 of args) arg7 (item 7 of args) arg8 (item 8 of args) arg9 (item 9 of args) arg10 (item 10 of args))
|
|
74
|
+
end if
|
|
75
|
+
end tell
|
|
76
|
+
|
|
77
|
+
return result
|
|
78
|
+
end run_macro
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
param(
|
|
2
|
+
[Parameter(Position=0)]
|
|
3
|
+
[string]$AppName,
|
|
4
|
+
|
|
5
|
+
[Parameter(Position=1)]
|
|
6
|
+
[string]$File,
|
|
7
|
+
|
|
8
|
+
[Parameter(Position=2)]
|
|
9
|
+
[string]$Command,
|
|
10
|
+
|
|
11
|
+
[Parameter(Position=3, ValueFromRemainingArguments=$true)]
|
|
12
|
+
[string[]]$MacroArgs
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
$ErrorActionPreference = 'Stop'
|
|
16
|
+
|
|
17
|
+
if (-not $AppName -or -not $File -or -not $Command) {
|
|
18
|
+
Fail "ERROR #1: Invalid Input (appname, file, and macro are required)"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if ($MacroArgs.Count -gt 10) {
|
|
22
|
+
Fail "ERROR #2: Invalid Input (only 10 arguments are supported)"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
# Unescape arguments
|
|
26
|
+
$UnescapedArgs = @()
|
|
27
|
+
foreach ($arg in $MacroArgs) {
|
|
28
|
+
$UnescapedArgs += Unescape $arg
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Run $AppName $File $Command $UnescapedArgs
|
|
32
|
+
exit 0
|
|
33
|
+
|
|
34
|
+
# -------
|
|
35
|
+
# Run
|
|
36
|
+
# -------
|
|
37
|
+
|
|
38
|
+
function Run {
|
|
39
|
+
param(
|
|
40
|
+
[string]$AppName,
|
|
41
|
+
[string]$File,
|
|
42
|
+
[string]$Command,
|
|
43
|
+
[string[]]$Args
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
switch ($AppName) {
|
|
47
|
+
"excel" {
|
|
48
|
+
$excel = [Excel]::new()
|
|
49
|
+
try {
|
|
50
|
+
$result = $excel.Run($File, $Command, $Args)
|
|
51
|
+
} finally {
|
|
52
|
+
$excel.Dispose()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
default {
|
|
56
|
+
Fail "ERROR #3: Unsupported App `"$AppName`""
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
PrintLn $result
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# -------
|
|
64
|
+
# Excel
|
|
65
|
+
# -------
|
|
66
|
+
|
|
67
|
+
class Excel {
|
|
68
|
+
hidden [object]$App
|
|
69
|
+
hidden [bool]$ExcelWasOpen = $false
|
|
70
|
+
hidden [object]$Workbook
|
|
71
|
+
hidden [bool]$WorkbookWasOpen = $false
|
|
72
|
+
|
|
73
|
+
Excel() {
|
|
74
|
+
$this.OpenExcel()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
[string] Run([string]$File, [string]$Command, [string[]]$Args) {
|
|
78
|
+
$this.OpenWorkbook($File)
|
|
79
|
+
$result = RunMacro $this.App $Command $Args
|
|
80
|
+
|
|
81
|
+
return $result
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
hidden [void] OpenExcel() {
|
|
85
|
+
try {
|
|
86
|
+
$this.App = [System.Runtime.InteropServices.Marshal]::GetActiveObject("Excel.Application")
|
|
87
|
+
$this.ExcelWasOpen = $true
|
|
88
|
+
} catch {
|
|
89
|
+
try {
|
|
90
|
+
$this.App = New-Object -ComObject "Excel.Application"
|
|
91
|
+
$this.App.Visible = $false
|
|
92
|
+
} catch {
|
|
93
|
+
Fail "ERROR #5: Failed to open Excel - $($_.Exception.Message)"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
hidden [void] OpenWorkbook([string]$Path) {
|
|
99
|
+
$fileName = GetFileName $Path
|
|
100
|
+
$fileBase = GetFileBase $Path
|
|
101
|
+
|
|
102
|
+
# Check add-ins first
|
|
103
|
+
try {
|
|
104
|
+
$addin = $this.App.AddIns($fileName)
|
|
105
|
+
if ($addin.IsOpen) {
|
|
106
|
+
$this.Workbook = $addin
|
|
107
|
+
$this.WorkbookWasOpen = $true
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
} catch {
|
|
111
|
+
# Not found in add-ins, continue
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
# Check already-open workbooks
|
|
115
|
+
try {
|
|
116
|
+
$this.Workbook = $this.App.Workbooks($fileBase)
|
|
117
|
+
$this.WorkbookWasOpen = $true
|
|
118
|
+
return
|
|
119
|
+
} catch {
|
|
120
|
+
# Not already open, continue
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
# Open the workbook
|
|
124
|
+
try {
|
|
125
|
+
$this.Workbook = $this.App.Workbooks.Open($Path)
|
|
126
|
+
} catch {
|
|
127
|
+
Fail "ERROR #6: Failed to open workbook - $($_.Exception.Message)"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
[void] Dispose() {
|
|
132
|
+
if (-not $this.WorkbookWasOpen -and $null -ne $this.Workbook) {
|
|
133
|
+
$this.Workbook.Close($true)
|
|
134
|
+
$this.Workbook = $null
|
|
135
|
+
}
|
|
136
|
+
if (-not $this.ExcelWasOpen -and $null -ne $this.App) {
|
|
137
|
+
$this.App.Quit()
|
|
138
|
+
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($this.App) | Out-Null
|
|
139
|
+
$this.App = $null
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
# -------
|
|
145
|
+
# Run Macro
|
|
146
|
+
# -------
|
|
147
|
+
|
|
148
|
+
function RunMacro {
|
|
149
|
+
param(
|
|
150
|
+
[object]$App,
|
|
151
|
+
[string]$Command,
|
|
152
|
+
[string[]]$Args
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
$numArgs = $Args.Count
|
|
156
|
+
switch ($numArgs) {
|
|
157
|
+
0 { return $App.Run($Command) }
|
|
158
|
+
1 { return $App.Run($Command, $Args[0]) }
|
|
159
|
+
2 { return $App.Run($Command, $Args[0], $Args[1]) }
|
|
160
|
+
3 { return $App.Run($Command, $Args[0], $Args[1], $Args[2]) }
|
|
161
|
+
4 { return $App.Run($Command, $Args[0], $Args[1], $Args[2], $Args[3]) }
|
|
162
|
+
5 { return $App.Run($Command, $Args[0], $Args[1], $Args[2], $Args[3], $Args[4]) }
|
|
163
|
+
6 { return $App.Run($Command, $Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5]) }
|
|
164
|
+
7 { return $App.Run($Command, $Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6]) }
|
|
165
|
+
8 { return $App.Run($Command, $Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], $Args[7]) }
|
|
166
|
+
9 { return $App.Run($Command, $Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], $Args[7], $Args[8]) }
|
|
167
|
+
10 { return $App.Run($Command, $Args[0], $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], $Args[7], $Args[8], $Args[9]) }
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return $null
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
# -------
|
|
174
|
+
# Helpers
|
|
175
|
+
# -------
|
|
176
|
+
|
|
177
|
+
function Unescape {
|
|
178
|
+
param([string]$Value)
|
|
179
|
+
return $Value -replace '\^q', '"'
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function GetFileBase {
|
|
183
|
+
param([string]$Path)
|
|
184
|
+
return [System.IO.Path]::GetFileName($Path)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function GetFileName {
|
|
188
|
+
param([string]$Path)
|
|
189
|
+
return [System.IO.Path]::GetFileNameWithoutExtension($Path)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function Fail {
|
|
193
|
+
param([string]$Message)
|
|
194
|
+
PrintLn "{`"success`":false,`"errors`":[`"$Message`"]}"
|
|
195
|
+
exit 1
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function Print {
|
|
199
|
+
param([string]$Message)
|
|
200
|
+
[Console]::Out.Write($Message)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function PrintLn {
|
|
204
|
+
param([string]$Message)
|
|
205
|
+
[Console]::Out.WriteLine($Message)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function PrintErr {
|
|
209
|
+
param([string]$Message)
|
|
210
|
+
[Console]::Error.Write($Message)
|
|
211
|
+
}
|