@servicenow/sdk-build-plugins 2.0.1 → 2.1.1
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/dist/AttachmentPlugin.d.ts +8 -6
- package/dist/AttachmentPlugin.js +4 -2
- package/dist/AttachmentPlugin.js.map +1 -1
- package/dist/BusinessRulePlugin.d.ts +5 -31
- package/dist/BusinessRulePlugin.js +45 -72
- package/dist/BusinessRulePlugin.js.map +1 -1
- package/dist/CrossScopePrivilegePlugin.d.ts +14 -1
- package/dist/CrossScopePrivilegePlugin.js +36 -1
- package/dist/CrossScopePrivilegePlugin.js.map +1 -1
- package/dist/DefaultPlugin.d.ts +60 -57
- package/dist/DefaultPlugin.js +151 -146
- package/dist/DefaultPlugin.js.map +1 -1
- package/dist/HtmlTemplatePlugin.d.ts +21 -0
- package/dist/HtmlTemplatePlugin.js +52 -0
- package/dist/HtmlTemplatePlugin.js.map +1 -0
- package/dist/IdPlugin.d.ts +18 -8
- package/dist/IdPlugin.js +55 -28
- package/dist/IdPlugin.js.map +1 -1
- package/dist/JsonPlugin.d.ts +23 -0
- package/dist/JsonPlugin.js +74 -0
- package/dist/JsonPlugin.js.map +1 -0
- package/dist/ListPlugin.d.ts +7 -13
- package/dist/ListPlugin.js +32 -15
- package/dist/ListPlugin.js.map +1 -1
- package/dist/NowConfigPlugin.d.ts +45 -0
- package/dist/NowConfigPlugin.js +90 -0
- package/dist/NowConfigPlugin.js.map +1 -0
- package/dist/PackageJsonPlugin.d.ts +20 -0
- package/dist/PackageJsonPlugin.js +48 -0
- package/dist/PackageJsonPlugin.js.map +1 -0
- package/dist/PropertyPlugin.d.ts +9 -35
- package/dist/PropertyPlugin.js +53 -32
- package/dist/PropertyPlugin.js.map +1 -1
- package/dist/ScriptTemplatePlugin.d.ts +3 -20
- package/dist/ScriptTemplatePlugin.js +20 -138
- package/dist/ScriptTemplatePlugin.js.map +1 -1
- package/dist/ServerModulePlugin.d.ts +62 -0
- package/dist/ServerModulePlugin.js +231 -0
- package/dist/ServerModulePlugin.js.map +1 -0
- package/dist/UserPreferencePlugin.d.ts +4 -1
- package/dist/UserPreferencePlugin.js +12 -10
- package/dist/UserPreferencePlugin.js.map +1 -1
- package/dist/aclAndRole/AclPlugin.d.ts +41 -79
- package/dist/aclAndRole/AclPlugin.js +50 -72
- package/dist/aclAndRole/AclPlugin.js.map +1 -1
- package/dist/aclAndRole/RolePlugin.d.ts +27 -18
- package/dist/aclAndRole/RolePlugin.js +66 -41
- package/dist/aclAndRole/RolePlugin.js.map +1 -1
- package/dist/app/ApplicationMenuPlugin.d.ts +4 -2
- package/dist/app/ApplicationMenuPlugin.js +12 -7
- package/dist/app/ApplicationMenuPlugin.js.map +1 -1
- package/dist/atf/ATFComposer.js +324 -324
- package/dist/atf/TestPlugin.d.ts +12 -10
- package/dist/atf/TestPlugin.js +14 -12
- package/dist/atf/TestPlugin.js.map +1 -1
- package/dist/db/ColumnPlugins.d.ts +559 -97
- package/dist/db/ColumnPlugins.js +28 -24
- package/dist/db/ColumnPlugins.js.map +1 -1
- package/dist/db/DBUtils.d.ts +2 -0
- package/dist/db/DBUtils.js +27 -0
- package/dist/db/DBUtils.js.map +1 -0
- package/dist/db/DocumentationPlugin.d.ts +58 -0
- package/dist/db/DocumentationPlugin.js +248 -0
- package/dist/db/DocumentationPlugin.js.map +1 -0
- package/dist/db/RecordPlugin.d.ts +15 -13
- package/dist/db/RecordPlugin.js +74 -79
- package/dist/db/RecordPlugin.js.map +1 -1
- package/dist/db/TablePlugin.d.ts +38 -105
- package/dist/db/TablePlugin.js +205 -111
- package/dist/db/TablePlugin.js.map +1 -1
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.js +4 -1
- package/dist/db/index.js.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.js +8 -6
- package/dist/scriptedRESTAPI/RESTDeserializationUtils.js.map +1 -1
- package/dist/scriptedRESTAPI/RESTSerializationUtils.js +7 -6
- package/dist/scriptedRESTAPI/RESTSerializationUtils.js.map +1 -1
- package/dist/scriptedRESTAPI/RestApiPlugin.d.ts +74 -85
- package/dist/scriptedRESTAPI/RestApiPlugin.js +71 -54
- package/dist/scriptedRESTAPI/RestApiPlugin.js.map +1 -1
- package/dist/scriptedRESTAPI/RestUtils.d.ts +2 -0
- package/dist/scriptedRESTAPI/RestUtils.js +37 -9
- package/dist/scriptedRESTAPI/RestUtils.js.map +1 -1
- package/dist/scripts/ClientScriptPlugin.d.ts +18 -16
- package/dist/scripts/ClientScriptPlugin.js +48 -45
- package/dist/scripts/ClientScriptPlugin.js.map +1 -1
- package/dist/scripts/scriptUtils.d.ts +0 -14
- package/dist/scripts/scriptUtils.js +0 -74
- package/dist/scripts/scriptUtils.js.map +1 -1
- package/dist/uxf/ExperiencePlugin.d.ts +31 -3
- package/dist/uxf/ExperiencePlugin.js +10 -4
- package/dist/uxf/ExperiencePlugin.js.map +1 -1
- package/dist/uxf/RoutesPlugin.d.ts +10 -3
- package/dist/uxf/RoutesPlugin.js +20 -14
- package/dist/uxf/RoutesPlugin.js.map +1 -1
- package/package.json +6 -6
- package/src/AttachmentPlugin.ts +10 -2
- package/src/BusinessRulePlugin.ts +79 -104
- package/src/CrossScopePrivilegePlugin.ts +65 -5
- package/src/DefaultPlugin.ts +181 -173
- package/src/HtmlTemplatePlugin.ts +31 -0
- package/src/IdPlugin.ts +59 -28
- package/src/JsonPlugin.ts +81 -0
- package/src/ListPlugin.ts +38 -19
- package/src/NowConfigPlugin.ts +72 -0
- package/src/PackageJsonPlugin.ts +24 -0
- package/src/PropertyPlugin.ts +60 -38
- package/src/ScriptTemplatePlugin.ts +22 -179
- package/src/ServerModulePlugin.ts +267 -0
- package/src/UserPreferencePlugin.ts +28 -19
- package/src/aclAndRole/AclPlugin.ts +78 -109
- package/src/aclAndRole/RolePlugin.ts +85 -58
- package/src/app/ApplicationMenuPlugin.ts +15 -11
- package/src/atf/ATFComposer.ts +1 -1
- package/src/atf/TestPlugin.ts +14 -12
- package/src/db/ColumnPlugins.ts +36 -37
- package/src/db/DBUtils.ts +36 -0
- package/src/db/DocumentationPlugin.ts +282 -0
- package/src/db/RecordPlugin.ts +96 -98
- package/src/db/TablePlugin.ts +278 -152
- package/src/db/index.ts +2 -0
- package/src/index.ts +7 -2
- package/src/scriptedRESTAPI/RESTDeserializationUtils.ts +15 -7
- package/src/scriptedRESTAPI/RESTSerializationUtils.ts +7 -6
- package/src/scriptedRESTAPI/RestApiPlugin.ts +85 -75
- package/src/scriptedRESTAPI/RestUtils.ts +44 -11
- package/src/scripts/ClientScriptPlugin.ts +64 -68
- package/src/scripts/scriptUtils.ts +0 -76
- package/src/uxf/ExperiencePlugin.ts +14 -13
- package/src/uxf/RoutesPlugin.ts +22 -27
package/dist/PropertyPlugin.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PropertyDocumentSchema = void 0;
|
|
4
4
|
const app_1 = require("@servicenow/sdk-core/runtime/app");
|
|
5
5
|
const db_1 = require("@servicenow/sdk-core/runtime/db");
|
|
6
|
-
const
|
|
6
|
+
const fluent_1 = require("@servicenow/sdk-core/runtime/fluent");
|
|
7
7
|
const sdk_build_core_1 = require("@servicenow/sdk-build-core");
|
|
8
8
|
const RecordPlugin_1 = require("./db/RecordPlugin");
|
|
9
9
|
const zod_1 = require("zod");
|
|
10
10
|
const ts_morph_1 = require("ts-morph");
|
|
11
11
|
const lodash_1 = require("lodash");
|
|
12
12
|
const sdk_project_1 = require("@servicenow/sdk-project");
|
|
13
|
+
const RolePlugin_1 = require("./aclAndRole/RolePlugin");
|
|
13
14
|
const PropertySchema = zod_1.z.object({
|
|
14
15
|
$id: zod_1.z.string().or(zod_1.z.number()),
|
|
15
16
|
name: zod_1.z.string(),
|
|
16
|
-
type:
|
|
17
|
+
type: fluent_1.PropertyType.or(zod_1.z.literal('')).default(''),
|
|
17
18
|
value: zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean()]).default(''),
|
|
18
19
|
description: zod_1.z.string().default(''),
|
|
19
20
|
ignoreCache: zod_1.z.boolean().default(false),
|
|
@@ -32,6 +33,7 @@ const PropertyConfigSchema = zod_1.z.object({
|
|
|
32
33
|
ignore_cache: PropertySchema.shape.ignoreCache,
|
|
33
34
|
read_roles: zod_1.z.string().optional(),
|
|
34
35
|
write_roles: zod_1.z.string().optional(),
|
|
36
|
+
choices: zod_1.z.string().optional(),
|
|
35
37
|
});
|
|
36
38
|
exports.PropertyDocumentSchema = zod_1.z.object({
|
|
37
39
|
table: zod_1.z.literal('sys_properties'),
|
|
@@ -40,10 +42,10 @@ exports.PropertyDocumentSchema = zod_1.z.object({
|
|
|
40
42
|
const transformProperties = (data, xmlRoles) => {
|
|
41
43
|
const { read_roles, write_roles, ...rest } = data;
|
|
42
44
|
let roles;
|
|
43
|
-
if (read_roles || write_roles) {
|
|
45
|
+
if (read_roles !== undefined || write_roles !== undefined) {
|
|
44
46
|
roles = {
|
|
45
|
-
...(xmlRoles.read_roles && { read: (0, app_1.getRolesArray)(xmlRoles.read_roles) }),
|
|
46
|
-
...(xmlRoles.write_roles && { write: (0, app_1.getRolesArray)(xmlRoles.write_roles) }),
|
|
47
|
+
...(xmlRoles.read_roles !== undefined && { read: (0, app_1.getRolesArray)(xmlRoles.read_roles) }),
|
|
48
|
+
...(xmlRoles.write_roles !== undefined && { write: (0, app_1.getRolesArray)(xmlRoles.write_roles) }),
|
|
47
49
|
};
|
|
48
50
|
}
|
|
49
51
|
const result = {
|
|
@@ -54,10 +56,13 @@ const transformProperties = (data, xmlRoles) => {
|
|
|
54
56
|
ignoreCache: rest.ignore_cache,
|
|
55
57
|
isPrivate: rest.is_private,
|
|
56
58
|
roles: roles,
|
|
59
|
+
choices: rest.choices
|
|
60
|
+
?.split(/\r?\n/)
|
|
61
|
+
.map((choice) => choice.trim())
|
|
62
|
+
.filter((choice) => choice),
|
|
57
63
|
};
|
|
58
64
|
return (0, lodash_1.pickBy)(result, (v) => v !== undefined);
|
|
59
65
|
};
|
|
60
|
-
exports.transformProperties = transformProperties;
|
|
61
66
|
exports.default = (0, sdk_build_core_1.Plugin)({
|
|
62
67
|
name: 'Property',
|
|
63
68
|
ownedTables: {
|
|
@@ -65,24 +70,26 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
65
70
|
},
|
|
66
71
|
extractors: {
|
|
67
72
|
entity: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
73
|
+
fluent: {
|
|
74
|
+
CallExpression: (node, context) => {
|
|
75
|
+
const result = (0, sdk_build_core_1.extractCallExpression)(app_1.Property, 'property', node, context, (prop) => context.registerExplicitId('sys_properties', prop.$id));
|
|
76
|
+
if (!result.handled || !(0 in result.data)) {
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
const propertyData = result.data[0];
|
|
80
|
+
const diagnostics = result.diagnostics;
|
|
81
|
+
const scope = context.app.config.scope;
|
|
82
|
+
const nameData = propertyData.getProperty('name');
|
|
83
|
+
const nameNode = nameData.getNode();
|
|
84
|
+
if (!(0, sdk_build_core_1.isSNScope)(scope) && !nameData.getValue().startsWith(`${scope}.`)) {
|
|
85
|
+
diagnostics.push(new sdk_build_core_1.FluentDiagnostic(nameNode, `Property name must begin with '${scope}.'`));
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
handled: true,
|
|
89
|
+
diagnostics,
|
|
90
|
+
data: [propertyData],
|
|
91
|
+
};
|
|
92
|
+
},
|
|
86
93
|
},
|
|
87
94
|
},
|
|
88
95
|
},
|
|
@@ -94,9 +101,12 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
94
101
|
if (!property.success) {
|
|
95
102
|
return undefined;
|
|
96
103
|
}
|
|
97
|
-
const { $id, name,
|
|
98
|
-
const
|
|
99
|
-
const
|
|
104
|
+
const { $id, name, value, isPrivate, ignoreCache, choices, type, roles: _, ...rest } = property.data;
|
|
105
|
+
const roles = entity.getProperty('roles', 'object');
|
|
106
|
+
const readRoles = roles?.getProperty('read', 'array');
|
|
107
|
+
const writeRoles = roles?.getProperty('write', 'array');
|
|
108
|
+
const readRolesString = readRoles ? (0, RolePlugin_1.getRolesString)(readRoles) : '';
|
|
109
|
+
const writeRolesString = writeRoles ? (0, RolePlugin_1.getRolesString)(writeRoles) : '';
|
|
100
110
|
const suffix = name.replace(new RegExp(`^${scope}\\.`), '');
|
|
101
111
|
const propertyRecord = (0, db_1.Record)({
|
|
102
112
|
table: 'sys_properties',
|
|
@@ -110,8 +120,8 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
110
120
|
is_private: isPrivate,
|
|
111
121
|
ignore_cache: ignoreCache,
|
|
112
122
|
choices: choices.join('\n'),
|
|
113
|
-
read_roles:
|
|
114
|
-
write_roles:
|
|
123
|
+
read_roles: readRolesString,
|
|
124
|
+
write_roles: writeRolesString,
|
|
115
125
|
},
|
|
116
126
|
});
|
|
117
127
|
return context.composeEntities([
|
|
@@ -122,7 +132,8 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
122
132
|
},
|
|
123
133
|
generators: {
|
|
124
134
|
record(document, context) {
|
|
125
|
-
|
|
135
|
+
const tableName = document.data['table'];
|
|
136
|
+
if (tableName !== 'sys_properties') {
|
|
126
137
|
return undefined;
|
|
127
138
|
}
|
|
128
139
|
return (0, sdk_build_core_1.linkDocument)(document, (0, sdk_build_core_1.generateCallExpressionExportForDocument)(context, {
|
|
@@ -145,7 +156,7 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
145
156
|
return false;
|
|
146
157
|
}
|
|
147
158
|
const { read_roles, write_roles } = document.xmlData.data;
|
|
148
|
-
const data =
|
|
159
|
+
const data = transformProperties(document.changedData['data'], {
|
|
149
160
|
read_roles,
|
|
150
161
|
write_roles,
|
|
151
162
|
});
|
|
@@ -155,6 +166,7 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
155
166
|
}
|
|
156
167
|
(0, sdk_build_core_1.transformFunctionArguments)(document.node, app_1.Property, data);
|
|
157
168
|
if (data.roles) {
|
|
169
|
+
removeEmptyRoles(args, data);
|
|
158
170
|
(0, sdk_build_core_1.writePropertyAsReference)(args, 'roles', '{}', data.roles);
|
|
159
171
|
}
|
|
160
172
|
return true;
|
|
@@ -162,4 +174,13 @@ exports.default = (0, sdk_build_core_1.Plugin)({
|
|
|
162
174
|
},
|
|
163
175
|
},
|
|
164
176
|
});
|
|
177
|
+
function removeEmptyRoles(arg, data) {
|
|
178
|
+
;
|
|
179
|
+
['read', 'write'].forEach((type) => {
|
|
180
|
+
if (data.roles?.[type].length === 0) {
|
|
181
|
+
arg.getProperty('roles')?.asKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression)?.getProperty(type)?.remove();
|
|
182
|
+
delete data.roles?.[type];
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
165
186
|
//# sourceMappingURL=PropertyPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyPlugin.js","sourceRoot":"","sources":["../src/PropertyPlugin.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"PropertyPlugin.js","sourceRoot":"","sources":["../src/PropertyPlugin.ts"],"names":[],"mappings":";;;AAAA,0DAAsF;AACtF,wDAAwD;AACxD,gEAAkE;AAClE,+DAemC;AACnC,oDAAgD;AAChD,6BAAuB;AACvB,uCAAoE;AACpE,mCAA+B;AAC/B,yDAAoD;AACpD,wDAAwD;AAExD,MAAM,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;oBACV,WAAW;iBACd,CAAC,CAAA;gBAEF,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,CAAA;gBAC3C,IAAI,CAAC,eAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxC,OAAO,KAAK,CAAA;gBAChB,CAAC;gBACD,IAAA,2CAA0B,EAAC,QAAQ,CAAC,IAAI,EAAE,cAAQ,EAAE,IAAI,CAAC,CAAA;gBAEzD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;oBACb,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;oBAC5B,IAAA,yCAAwB,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;gBAC7D,CAAC;gBAED,OAAO,IAAI,CAAA;YACf,CAAC;SACJ;KACJ;CACJ,CAAC,CAAA;AAEF,SAAS,gBAAgB,CAAC,GAA4B,EAAE,IAAuB;IAC3E,CAAC;IAAA,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAChC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,qBAAU,CAAC,uBAAuB,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;YACjG,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAA;QAC7B,CAAC;IACL,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -1,31 +1,14 @@
|
|
|
1
|
-
import { Context, StringData, UndefinedData } from '@servicenow/sdk-build-core';
|
|
2
1
|
import * as ts from 'ts-morph';
|
|
3
|
-
export declare const UNIQUE_SCRIPT_FILES = "unique_script_files";
|
|
4
2
|
declare const _default: {
|
|
5
3
|
readonly name: "scriptTemplate";
|
|
6
4
|
readonly extractors: {
|
|
7
5
|
readonly raw: {
|
|
8
|
-
readonly
|
|
9
|
-
|
|
10
|
-
diagnostics?: never;
|
|
11
|
-
data?: never;
|
|
12
|
-
} | {
|
|
13
|
-
handled: true;
|
|
14
|
-
diagnostics: never[];
|
|
15
|
-
data: (StringData<string> | UndefinedData)[];
|
|
16
|
-
};
|
|
17
|
-
readonly ExportAssignment: (node: ts.ExportAssignment, context: Context) => {
|
|
18
|
-
handled: false;
|
|
19
|
-
diagnostics?: never;
|
|
20
|
-
data?: never;
|
|
21
|
-
} | {
|
|
22
|
-
handled: true;
|
|
23
|
-
diagnostics: never[];
|
|
24
|
-
data: (StringData<string> | UndefinedData)[];
|
|
6
|
+
readonly fluent: {
|
|
7
|
+
readonly TaggedTemplateExpression: (node: ts.TaggedTemplateExpression, context: import("@servicenow/sdk-build-core").Context) => import("@servicenow/sdk-build-core").ExtractionResult;
|
|
25
8
|
};
|
|
26
9
|
};
|
|
27
10
|
};
|
|
28
11
|
};
|
|
29
12
|
export default _default;
|
|
30
|
-
export declare function processScript(args: ts.ObjectLiteralExpression, argName: string, script: string
|
|
13
|
+
export declare function processScript(args: ts.ObjectLiteralExpression, argName: string, script: string): void;
|
|
31
14
|
export declare function formatScript(script: string, spacing?: number): string;
|
|
@@ -23,90 +23,43 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.UNIQUE_SCRIPT_FILES = void 0;
|
|
27
26
|
exports.processScript = processScript;
|
|
28
27
|
exports.formatScript = formatScript;
|
|
29
28
|
const sdk_build_core_1 = require("@servicenow/sdk-build-core");
|
|
30
29
|
const ts = __importStar(require("ts-morph"));
|
|
31
|
-
const path = __importStar(require("path"));
|
|
32
|
-
const sdk_project_1 = require("@servicenow/sdk-project");
|
|
33
30
|
const os = __importStar(require("os"));
|
|
34
|
-
exports.UNIQUE_SCRIPT_FILES = 'unique_script_files';
|
|
35
31
|
exports.default = (0, sdk_build_core_1.Plugin)({
|
|
36
32
|
name: 'scriptTemplate',
|
|
37
33
|
extractors: {
|
|
38
34
|
raw: {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
diagnostics: [],
|
|
47
|
-
data: [typeof value === 'string' ? new sdk_build_core_1.StringData(value, node) : new sdk_build_core_1.UndefinedData(node)],
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
ExportAssignment: (node, context) => {
|
|
51
|
-
const expression = node.getExpression();
|
|
52
|
-
if (!expression ||
|
|
53
|
-
expression.getKind() !== ts.SyntaxKind.TaggedTemplateExpression ||
|
|
54
|
-
expression.asKind(ts.SyntaxKind.TaggedTemplateExpression).getTag().getText() !== 'script') {
|
|
55
|
-
return { handled: false };
|
|
56
|
-
}
|
|
57
|
-
validateScriptFile(node, context);
|
|
58
|
-
const value = getTemplateLiteralValue(node.getExpression().asKind(ts.SyntaxKind.TaggedTemplateExpression));
|
|
59
|
-
return {
|
|
60
|
-
handled: true,
|
|
61
|
-
diagnostics: [],
|
|
62
|
-
data: [typeof value === 'string' ? new sdk_build_core_1.StringData(value, node) : new sdk_build_core_1.UndefinedData(node)],
|
|
63
|
-
};
|
|
35
|
+
fluent: {
|
|
36
|
+
TaggedTemplateExpression(node, context) {
|
|
37
|
+
if (node.getTag().getText() !== 'script') {
|
|
38
|
+
return { handled: false };
|
|
39
|
+
}
|
|
40
|
+
return context.extractAst(node.getTemplate());
|
|
41
|
+
},
|
|
64
42
|
},
|
|
65
43
|
},
|
|
66
44
|
},
|
|
67
45
|
});
|
|
68
|
-
function
|
|
69
|
-
const filePath = path.normalize(node.getSourceFile().getFilePath());
|
|
70
|
-
const uniqueScriptFiles = context.store[exports.UNIQUE_SCRIPT_FILES] ?? new Set();
|
|
71
|
-
if (uniqueScriptFiles.has(filePath)) {
|
|
72
|
-
throw Error(`Tagged template script files should be unique per entity but expression in ${filePath.replace(context.app.rootDir, '')} is referenced in multiple nodes.`);
|
|
73
|
-
}
|
|
74
|
-
uniqueScriptFiles.add(filePath);
|
|
75
|
-
context.store[exports.UNIQUE_SCRIPT_FILES] = uniqueScriptFiles;
|
|
76
|
-
}
|
|
77
|
-
function processScript(args, argName, script, docId, tableName, context) {
|
|
46
|
+
function processScript(args, argName, script) {
|
|
78
47
|
if (!args.getProperty(argName)) {
|
|
79
|
-
createNewScriptTemplate(args, argName, script
|
|
48
|
+
createNewScriptTemplate(args, argName, script);
|
|
80
49
|
}
|
|
81
50
|
else {
|
|
82
51
|
const prop = args.getProperty(argName).asKindOrThrow(ts.SyntaxKind.PropertyAssignment);
|
|
83
52
|
const kind = prop.getInitializer()?.getKind();
|
|
84
53
|
if (kind === ts.SyntaxKind.TaggedTemplateExpression) {
|
|
85
|
-
|
|
86
|
-
args.getProperty(argName)?.remove();
|
|
87
|
-
createNewScriptTemplate(args, argName, script, docId, tableName, context);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
const taggedTempExp = prop.getInitializer()?.asKind(ts.SyntaxKind.TaggedTemplateExpression);
|
|
91
|
-
updateTaggedTempExpWithScript(taggedTempExp, script);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else if (kind === ts.SyntaxKind.Identifier && checkIfItsScriptTemplate(prop)) {
|
|
95
|
-
const taggedTempExp = getTaggedTemplate(prop);
|
|
54
|
+
const taggedTempExp = prop.getInitializer()?.asKind(ts.SyntaxKind.TaggedTemplateExpression);
|
|
96
55
|
updateTaggedTempExpWithScript(taggedTempExp, script);
|
|
97
56
|
}
|
|
98
57
|
else {
|
|
99
58
|
args.getProperty(argName)?.remove();
|
|
100
|
-
createNewScriptTemplate(args, argName, script
|
|
59
|
+
createNewScriptTemplate(args, argName, script);
|
|
101
60
|
}
|
|
102
61
|
}
|
|
103
62
|
}
|
|
104
|
-
function getTemplateLiteralValue(node) {
|
|
105
|
-
return node?.getTemplate().asKind(ts.SyntaxKind.NoSubstitutionTemplateLiteral)?.getLiteralValue();
|
|
106
|
-
}
|
|
107
|
-
function shouldCreateScriptFile(script, context) {
|
|
108
|
-
return script.replaceAll(/\r\n/g, '\n').split('\n').length > context.app.config.maxInlineScriptLines;
|
|
109
|
-
}
|
|
110
63
|
function formatScript(script, spacing = 4) {
|
|
111
64
|
const indent = ' '.repeat(spacing);
|
|
112
65
|
return script
|
|
@@ -118,91 +71,20 @@ function formatScript(script, spacing = 4) {
|
|
|
118
71
|
.replaceAll('`', '\\`')
|
|
119
72
|
.replaceAll('${', '\\${');
|
|
120
73
|
}
|
|
121
|
-
function
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
usedIdentifiers.add(node.getText().trim());
|
|
74
|
+
function createNewScriptTemplate(args, argName, script) {
|
|
75
|
+
const prop = args.addPropertyAssignment({ name: argName, initializer: '"place_holder"' });
|
|
76
|
+
const startPos = prop.getInitializer().getStart();
|
|
77
|
+
const lAndCol = args.getSourceFile().getLineAndColumnAtPos(startPos);
|
|
78
|
+
script = formatScript(script, lAndCol.column);
|
|
79
|
+
prop.setInitializer((writer) => {
|
|
80
|
+
writer.writeLine('script`');
|
|
81
|
+
writer.write(script);
|
|
82
|
+
writer.write('`');
|
|
131
83
|
});
|
|
132
|
-
while (usedIdentifiers.has(uniqueScriptName)) {
|
|
133
|
-
uniqueScriptName = `genScript${i}`;
|
|
134
|
-
i += 1;
|
|
135
|
-
}
|
|
136
|
-
return uniqueScriptName;
|
|
137
|
-
}
|
|
138
|
-
function createNewScriptTemplate(args, argName, script, docId, tableName, context) {
|
|
139
|
-
if (shouldCreateScriptFile(script, context)) {
|
|
140
|
-
const { filePath } = createScriptFile(script, `${tableName}_${docId}`, context);
|
|
141
|
-
const nodeFileDir = path.dirname(path.normalize(args.getSourceFile().getFilePath()));
|
|
142
|
-
let relativePath = path.relative(nodeFileDir, filePath).split(path.sep).join(path.posix.sep);
|
|
143
|
-
relativePath = relativePath.replace(path.extname(relativePath), '');
|
|
144
|
-
relativePath = relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
|
145
|
-
const uniqueScriptName = getUniqueScriptModuleName(args.getSourceFile());
|
|
146
|
-
args.addPropertyAssignment({ name: argName, initializer: uniqueScriptName });
|
|
147
|
-
(0, sdk_build_core_1.addDefaultImportIfAbsent)(args.getSourceFile(), relativePath, uniqueScriptName);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
const prop = args.addPropertyAssignment({ name: argName, initializer: '"place_holder"' });
|
|
151
|
-
const startPos = prop.getInitializer().getStart();
|
|
152
|
-
const lAndCol = args.getSourceFile().getLineAndColumnAtPos(startPos);
|
|
153
|
-
script = formatScript(script, lAndCol.column);
|
|
154
|
-
prop.setInitializer((writer) => {
|
|
155
|
-
writer.writeLine('script`');
|
|
156
|
-
writer.write(script);
|
|
157
|
-
writer.write('`');
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
84
|
}
|
|
161
85
|
function updateTaggedTempExpWithScript(node, script) {
|
|
162
86
|
const literal = node.getTemplate().asKind(ts.SyntaxKind.NoSubstitutionTemplateLiteral);
|
|
163
87
|
const lAndCol = literal.getSourceFile().getLineAndColumnAtPos(node.getStart());
|
|
164
88
|
literal.setLiteralValue(`${os.EOL}${formatScript(script, lAndCol.column)}`);
|
|
165
89
|
}
|
|
166
|
-
function checkIfItsScriptTemplate(node) {
|
|
167
|
-
const taggedTemp = getTaggedTemplate(node);
|
|
168
|
-
if (!taggedTemp) {
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
const identifer = taggedTemp.getTag();
|
|
172
|
-
if (!identifer || identifer.getText() !== 'script') {
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
function getTaggedTemplate(node) {
|
|
178
|
-
const definitions = node.getInitializer()?.asKind(ts.SyntaxKind.Identifier)?.getDefinitions();
|
|
179
|
-
if (!definitions || definitions.length > 1) {
|
|
180
|
-
return undefined;
|
|
181
|
-
}
|
|
182
|
-
const exportAssignments = definitions[0]?.getSourceFile().getDescendantsOfKind(ts.SyntaxKind.ExportAssignment);
|
|
183
|
-
if (!exportAssignments || exportAssignments.length > 1) {
|
|
184
|
-
return undefined;
|
|
185
|
-
}
|
|
186
|
-
return exportAssignments[0]?.getExpression()?.asKind(ts.SyntaxKind.TaggedTemplateExpression);
|
|
187
|
-
}
|
|
188
|
-
const getGeneratedFilePath = (context, fileName) => {
|
|
189
|
-
const resolvedDirPath = path.resolve(context.app.rootDir, context.app.config.generatedDir);
|
|
190
|
-
return path.join(resolvedDirPath, fileName);
|
|
191
|
-
};
|
|
192
|
-
function createScriptFile(script, fileName, context) {
|
|
193
|
-
let uniqueFileName = `${fileName}_script.now.ts`;
|
|
194
|
-
let filePath = getGeneratedFilePath(context, uniqueFileName);
|
|
195
|
-
let i = 0;
|
|
196
|
-
while (sdk_project_1.FileSystem.existsSync(context.fs, filePath)) {
|
|
197
|
-
uniqueFileName = `${fileName}_script${i}.now.ts`;
|
|
198
|
-
filePath = getGeneratedFilePath(context, uniqueFileName);
|
|
199
|
-
i++;
|
|
200
|
-
}
|
|
201
|
-
const directory = path.dirname(filePath);
|
|
202
|
-
if (!sdk_project_1.FileSystem.existsSync(context.fs, directory)) {
|
|
203
|
-
context.fs.mkdirSync(directory, { recursive: true });
|
|
204
|
-
}
|
|
205
|
-
context.fs.writeFileSync(filePath, templateScript(script), { encoding: 'utf-8' });
|
|
206
|
-
return { filePath };
|
|
207
|
-
}
|
|
208
90
|
//# sourceMappingURL=ScriptTemplatePlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScriptTemplatePlugin.js","sourceRoot":"","sources":["../src/ScriptTemplatePlugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{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CAAC,GAAG,CAAC,CAAA;IACrB,CAAC,CAAC,CAAA;AACN,CAAC;AAED,SAAS,6BAA6B,CAAC,IAAiC,EAAE,MAAc;IACpF,MAAM,OAAO,GAAG,IAAK,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,6BAA6B,CAAE,CAAA;IACxF,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC9E,OAAO,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC,GAAG,GAAG,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAC/E,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Context, Data, EntityData, ExtractionResult, ObjectData } from '@servicenow/sdk-build-core';
|
|
2
|
+
import { Diagnostic } from '@servicenow/sdk-project';
|
|
3
|
+
import { FunctionDeclaration, SourceFile, SyntaxKind, VariableDeclaration } from 'ts-morph';
|
|
4
|
+
export declare class ModuleEntityData extends EntityData {
|
|
5
|
+
constructor(content: string, file: SourceFile, context: Context);
|
|
6
|
+
}
|
|
7
|
+
export declare class ModuleFunctionData extends ObjectData<{
|
|
8
|
+
exportName: string;
|
|
9
|
+
modulePath: string;
|
|
10
|
+
isDefault: boolean;
|
|
11
|
+
}> {
|
|
12
|
+
constructor(name: string, module: ModuleEntityData, node: FunctionDeclaration | VariableDeclaration);
|
|
13
|
+
getGlueCode(callExpressionProvider: (functionName: string) => string): string;
|
|
14
|
+
static getGlueCode(scriptData: Data | ReturnType<ModuleFunctionData['getValue']> | undefined, callExpressionProvider: (functionName: string) => string): string;
|
|
15
|
+
}
|
|
16
|
+
declare function extractFunctionDeclaration(node: FunctionDeclaration | VariableDeclaration, context: Context): ExtractionResult<ModuleFunctionData>;
|
|
17
|
+
declare const _default: {
|
|
18
|
+
readonly name: "ServerModule";
|
|
19
|
+
readonly extractors: {
|
|
20
|
+
readonly raw: {
|
|
21
|
+
readonly module: {
|
|
22
|
+
readonly FunctionDeclaration: typeof extractFunctionDeclaration;
|
|
23
|
+
readonly FunctionExpression: (node: import("ts-morph").FunctionExpression, context: Context) => ExtractionResult<ModuleFunctionData>;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
readonly entity: {
|
|
27
|
+
readonly module: {
|
|
28
|
+
readonly SourceFile: (file: SourceFile, context: Context) => {
|
|
29
|
+
handled: false;
|
|
30
|
+
data?: never;
|
|
31
|
+
diagnostics?: never;
|
|
32
|
+
} | {
|
|
33
|
+
handled: true;
|
|
34
|
+
data: never[];
|
|
35
|
+
diagnostics: Diagnostic[];
|
|
36
|
+
} | {
|
|
37
|
+
handled: true;
|
|
38
|
+
diagnostics: never[];
|
|
39
|
+
data: ModuleEntityData[];
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
readonly composers: {
|
|
45
|
+
readonly entity: {
|
|
46
|
+
readonly module: (module: EntityData<Record<string, unknown>>) => {
|
|
47
|
+
kind: string;
|
|
48
|
+
guid: string;
|
|
49
|
+
node: import("ts-morph").CallExpression<import("ts-morph").ts.CallExpression> | import("ts-morph").Node<import("ts-morph").ts.EndOfFileToken> | import("ts-morph").TypeAliasDeclaration | import("ts-morph").TypeReferenceNode | import("ts-morph").TypeLiteralNode | import("ts-morph").PropertySignature | import("ts-morph").TupleTypeNode | import("ts-morph").FunctionExpression | FunctionDeclaration | import("ts-morph").ArrayLiteralExpression | import("ts-morph").StringLiteral | import("ts-morph").NumericLiteral | import("ts-morph").TrueLiteral | import("ts-morph").FalseLiteral | import("ts-morph").Identifier | SourceFile | VariableDeclaration | import("ts-morph").ClassDeclaration | import("ts-morph").ExportDeclaration | import("ts-morph").ObjectLiteralExpression | import("ts-morph").AsExpression | import("ts-morph").ComputedPropertyName | import("ts-morph").PropertyAssignment | import("ts-morph").ShorthandPropertyAssignment | import("ts-morph").PropertyAccessExpression<import("ts-morph").ts.PropertyAccessExpression> | import("ts-morph").NoSubstitutionTemplateLiteral | import("ts-morph").ExpressionStatement | import("ts-morph").TaggedTemplateExpression | import("ts-morph").ExportAssignment | import("ts-morph").ElementAccessExpression<import("ts-morph").ts.ElementAccessExpression> | import("ts-morph").TemplateExpression | import("ts-morph").ImportClause | import("ts-morph").ImportSpecifier | import("ts-morph").ImportDeclaration | import("ts-morph").NamedImports | import("ts-morph").VariableStatement | import("ts-morph").VariableDeclarationList | import("ts-morph").Node<import("ts-morph").ts.PlusToken> | import("ts-morph").Node<import("ts-morph").ts.ExportKeyword> | import("ts-morph").Node<import("ts-morph").ts.KeywordTypeNode<SyntaxKind.AnyKeyword>> | import("ts-morph").ModuleDeclaration | import("ts-morph").ModuleBlock | import("ts-morph").Block | import("ts-morph").ParameterDeclaration | import("ts-morph").Node<import("ts-morph").ts.EqualsGreaterThanToken> | import("ts-morph").ArrowFunction | import("ts-morph").TemplateHead | import("ts-morph").TemplateMiddle | import("ts-morph").TemplateSpan | import("ts-morph").TemplateTail | import("ts-morph").PrefixUnaryExpression;
|
|
50
|
+
data: Record<string, unknown>;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
readonly serializers: {
|
|
55
|
+
readonly module: (module: import("@servicenow/sdk-build-core").Document<string> & import("@servicenow/sdk-build-core").Arranged, context: Context) => {
|
|
56
|
+
name: `sys_module_${string}.xml`;
|
|
57
|
+
directory: "update";
|
|
58
|
+
content: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
export default _default;
|