@servicenow/sdk 1.0.2

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.
Files changed (101) hide show
  1. package/README.md +24 -0
  2. package/bin/debug.js +3 -0
  3. package/bin/index.js +2 -0
  4. package/dist/auth/index.d.ts +11 -0
  5. package/dist/auth/index.js +206 -0
  6. package/dist/auth/index.js.map +1 -0
  7. package/dist/auth/keychain/index.d.ts +12 -0
  8. package/dist/auth/keychain/index.js +44 -0
  9. package/dist/auth/keychain/index.js.map +1 -0
  10. package/dist/command/auth/commands/clear.d.ts +6 -0
  11. package/dist/command/auth/commands/clear.js +30 -0
  12. package/dist/command/auth/commands/clear.js.map +1 -0
  13. package/dist/command/auth/commands/list.d.ts +6 -0
  14. package/dist/command/auth/commands/list.js +30 -0
  15. package/dist/command/auth/commands/list.js.map +1 -0
  16. package/dist/command/auth/commands/save.d.ts +10 -0
  17. package/dist/command/auth/commands/save.js +96 -0
  18. package/dist/command/auth/commands/save.js.map +1 -0
  19. package/dist/command/auth/commands/setDefault.d.ts +6 -0
  20. package/dist/command/auth/commands/setDefault.js +30 -0
  21. package/dist/command/auth/commands/setDefault.js.map +1 -0
  22. package/dist/command/auth/commands/validate.d.ts +6 -0
  23. package/dist/command/auth/commands/validate.js +43 -0
  24. package/dist/command/auth/commands/validate.js.map +1 -0
  25. package/dist/command/auth/index.d.ts +2 -0
  26. package/dist/command/auth/index.js +35 -0
  27. package/dist/command/auth/index.js.map +1 -0
  28. package/dist/command/build/index.d.ts +11 -0
  29. package/dist/command/build/index.js +98 -0
  30. package/dist/command/build/index.js.map +1 -0
  31. package/dist/command/clean/index.d.ts +6 -0
  32. package/dist/command/clean/index.js +34 -0
  33. package/dist/command/clean/index.js.map +1 -0
  34. package/dist/command/compile/index.d.ts +7 -0
  35. package/dist/command/compile/index.js +42 -0
  36. package/dist/command/compile/index.js.map +1 -0
  37. package/dist/command/convert/index.d.ts +12 -0
  38. package/dist/command/convert/index.js +77 -0
  39. package/dist/command/convert/index.js.map +1 -0
  40. package/dist/command/create/index.d.ts +15 -0
  41. package/dist/command/create/index.js +92 -0
  42. package/dist/command/create/index.js.map +1 -0
  43. package/dist/command/deploy/index.d.ts +12 -0
  44. package/dist/command/deploy/index.js +80 -0
  45. package/dist/command/deploy/index.js.map +1 -0
  46. package/dist/command/fetch/index.d.ts +12 -0
  47. package/dist/command/fetch/index.js +78 -0
  48. package/dist/command/fetch/index.js.map +1 -0
  49. package/dist/command/generate-modules/index.d.ts +7 -0
  50. package/dist/command/generate-modules/index.js +46 -0
  51. package/dist/command/generate-modules/index.js.map +1 -0
  52. package/dist/command/pack/index.d.ts +6 -0
  53. package/dist/command/pack/index.js +40 -0
  54. package/dist/command/pack/index.js.map +1 -0
  55. package/dist/command/package-dependencies/index.d.ts +8 -0
  56. package/dist/command/package-dependencies/index.js +52 -0
  57. package/dist/command/package-dependencies/index.js.map +1 -0
  58. package/dist/command/test/index.d.ts +3 -0
  59. package/dist/command/test/index.js +52 -0
  60. package/dist/command/test/index.js.map +1 -0
  61. package/dist/command/transform/index.d.ts +3 -0
  62. package/dist/command/transform/index.js +63 -0
  63. package/dist/command/transform/index.js.map +1 -0
  64. package/dist/epilogue/index.d.ts +1 -0
  65. package/dist/epilogue/index.js +9 -0
  66. package/dist/epilogue/index.js.map +1 -0
  67. package/dist/index.d.ts +1 -0
  68. package/dist/index.js +55 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/usage/index.d.ts +1 -0
  71. package/dist/usage/index.js +16 -0
  72. package/dist/usage/index.js.map +1 -0
  73. package/dist/util.d.ts +1 -0
  74. package/dist/util.js +25 -0
  75. package/dist/util.js.map +1 -0
  76. package/license +9 -0
  77. package/package.json +42 -0
  78. package/src/auth/index.ts +238 -0
  79. package/src/auth/keychain/index.ts +23 -0
  80. package/src/command/auth/commands/clear.ts +21 -0
  81. package/src/command/auth/commands/list.ts +21 -0
  82. package/src/command/auth/commands/save.ts +100 -0
  83. package/src/command/auth/commands/setDefault.ts +21 -0
  84. package/src/command/auth/commands/validate.ts +35 -0
  85. package/src/command/auth/index.ts +24 -0
  86. package/src/command/build/index.ts +96 -0
  87. package/src/command/clean/index.ts +22 -0
  88. package/src/command/compile/index.ts +31 -0
  89. package/src/command/convert/index.ts +76 -0
  90. package/src/command/create/index.ts +97 -0
  91. package/src/command/deploy/index.ts +84 -0
  92. package/src/command/fetch/index.ts +78 -0
  93. package/src/command/generate-modules/index.ts +36 -0
  94. package/src/command/pack/index.ts +27 -0
  95. package/src/command/package-dependencies/index.ts +43 -0
  96. package/src/command/test/index.ts +40 -0
  97. package/src/command/transform/index.ts +45 -0
  98. package/src/epilogue/index.ts +5 -0
  99. package/src/index.ts +50 -0
  100. package/src/usage/index.ts +13 -0
  101. package/src/util.ts +21 -0
@@ -0,0 +1,76 @@
1
+ import { ArgumentsCamelCase, Argv, CommandModule } from 'yargs'
2
+ import { Creds } from '@servicenow/sdk-cli-core/dist/command/login'
3
+ import { getCredentials } from '../../auth'
4
+ import path from 'path'
5
+
6
+ interface Arguments extends Partial<Creds> {
7
+ scopeName: string
8
+ packageName: string
9
+ directory: string | undefined
10
+ auth: string | undefined
11
+ scopeId: string | undefined
12
+ experimental: boolean
13
+ }
14
+
15
+ export const convert: CommandModule<unknown, Arguments> = {
16
+ command: 'convert <scopeName> <packageName> [directory]',
17
+ describe: 'Convert a legacy ServiceNow App on instance to a nowSDK App',
18
+ builder: (yargs: Argv) => {
19
+ return yargs
20
+ .positional('scopeName', {
21
+ describe: 'Scope of the app to convert. For global apps, use app name',
22
+ type: 'string',
23
+ demandOption: true,
24
+ })
25
+ .positional('packageName', {
26
+ describe: 'Package Name of the App to use in the package.json',
27
+ type: 'string',
28
+ demandOption: true,
29
+ })
30
+ .positional('directory', {
31
+ describe: 'Directory to setup the application',
32
+ type: 'string',
33
+ })
34
+ .option('auth', {
35
+ describe: 'Credential alias to use for authentication with instance',
36
+ type: 'string',
37
+ alias: 'a',
38
+ })
39
+ .option('scopeId', {
40
+ describe: 'Scope ID of application.',
41
+ type: 'string',
42
+ })
43
+ .option('experimental', {
44
+ describe: 'Enables unstable experimental feature that may or may not be supported long term',
45
+ default: false,
46
+ type: 'boolean',
47
+ alias: 'e',
48
+ hidden: true,
49
+ })
50
+ },
51
+ handler: async function (args: ArgumentsCamelCase<Arguments>): Promise<void> {
52
+ const { logger } = await import('@servicenow/sdk-cli-core/dist/cli-util/logger/index.js')
53
+
54
+ try {
55
+ const credentials: Creds = await getCredentials(args)
56
+
57
+ const directory = args.directory ? path.resolve(args.directory) : path.join(process.cwd(), args.packageName)
58
+
59
+ logger.info(
60
+ `Converting application ${args.scopeName} from instance ${credentials.host} to local application package...`
61
+ )
62
+
63
+ const { convert: convertService } = await import('@servicenow/sdk-cli-core/dist/command/convert/index.js')
64
+ await convertService({
65
+ scope: args.scopeName,
66
+ packageName: args.packageName,
67
+ directory,
68
+ credentials,
69
+ scopeId: args.scopeId,
70
+ experimental: args.experimental,
71
+ })
72
+ } catch (error) {
73
+ logger.error(error instanceof Error ? error.message : (error as string), error)
74
+ }
75
+ },
76
+ }
@@ -0,0 +1,97 @@
1
+ import { ArgumentsCamelCase, Argv, CommandModule } from 'yargs'
2
+ import { Creds } from '@servicenow/sdk-cli-core/dist/command/login'
3
+ import { getCredentials } from '../../auth'
4
+
5
+ interface Arguments extends Partial<Creds> {
6
+ projectName: string | undefined
7
+ description: string | undefined
8
+ scopeName: string | undefined
9
+ sampleTable: boolean | undefined
10
+ directory: string | undefined
11
+ offline: boolean | undefined
12
+ interactive: boolean | undefined
13
+ auth: string | undefined
14
+ 'open-browser': boolean
15
+ }
16
+
17
+ export const create: CommandModule<unknown, Arguments> = {
18
+ command: 'create <projectName> <scopeName> [directory]',
19
+ describe: 'Scaffold new ServiceNow custom application',
20
+ builder: (yargs: Argv) => {
21
+ return yargs
22
+ .positional('projectName', {
23
+ describe: 'Name of ServiceNow App project',
24
+ type: 'string',
25
+ })
26
+ .positional('scopeName', {
27
+ describe:
28
+ 'Scope name (Must start with vendor prefix if applicable and cannot be greater than 12 characters)',
29
+ type: 'string',
30
+ })
31
+ .positional('directory', {
32
+ describe: 'Directory to setup the application',
33
+ type: 'string',
34
+ })
35
+ .option('description', {
36
+ describe: 'Description associated with sys_app',
37
+ type: 'string',
38
+ })
39
+ .option('sampleTable', {
40
+ describe: 'Add a sample table to the application?',
41
+ type: 'boolean',
42
+ })
43
+ .option('offline', {
44
+ describe: 'Build and register application on instance?',
45
+ type: 'boolean',
46
+ alias: 'o',
47
+ })
48
+ .option('auth', {
49
+ describe: 'Target host for application deployment',
50
+ type: 'string',
51
+ alias: 'a',
52
+ })
53
+ .option('interactive', {
54
+ describe: 'Provide create options via interactive UI',
55
+ type: 'boolean',
56
+ alias: 'i',
57
+ })
58
+ .option('open-browser', {
59
+ describe: 'Open sys_app page in the default browser on successful deploy',
60
+ default: false,
61
+ type: 'boolean',
62
+ alias: 'b',
63
+ })
64
+ .middleware(async (args: ArgumentsCamelCase<Arguments>) => {
65
+ if (args.auth) {
66
+ args.offline = false
67
+ }
68
+
69
+ if (!args.interactive && !args.offline) {
70
+ args.offline = false
71
+ }
72
+ })
73
+ },
74
+ handler: async function (args: ArgumentsCamelCase<Arguments>): Promise<void> {
75
+ const { logger } = await import('@servicenow/sdk-cli-core/dist/cli-util/logger/index.js')
76
+ logger.info(`Bootstrapping a new ServiceNow application project...`)
77
+
78
+ const { create: createService } = await import('@servicenow/sdk-cli-core/dist/command/create/index.js')
79
+ try {
80
+ let credentials: Creds | undefined
81
+ if (!args.offline) {
82
+ try {
83
+ credentials = await getCredentials(args)
84
+ } catch (error) {
85
+ // Ignore
86
+ }
87
+ }
88
+
89
+ await createService({
90
+ ...args,
91
+ ...(credentials && { ...credentials }),
92
+ })
93
+ } catch (error) {
94
+ logger.error(error instanceof Error ? error.message : (error as string), error)
95
+ }
96
+ },
97
+ }
@@ -0,0 +1,84 @@
1
+ import { Argv, ArgumentsCamelCase, CommandModule } from 'yargs'
2
+ import { Creds } from '@servicenow/sdk-cli-core/dist/command/login'
3
+ import { DeploymentMode } from '@servicenow/sdk-cli-core/dist/cli-util/Enums'
4
+ import { getCredentials } from '../../auth'
5
+ import { cwd } from '../../util'
6
+
7
+ interface Arguments extends Partial<Creds> {
8
+ source: string
9
+ mode: DeploymentMode
10
+ 'open-browser': boolean
11
+ auth: string | undefined
12
+ info: boolean
13
+ }
14
+
15
+ export const deploy: CommandModule<unknown, Arguments> = {
16
+ command: 'deploy',
17
+ describe: 'Install or update application on instance',
18
+ builder: async (yargs: Argv) => {
19
+ return yargs
20
+ .option('source', {
21
+ describe: 'Path to the nowSDK project',
22
+ default: cwd(),
23
+ type: 'string',
24
+ })
25
+ .option('mode', {
26
+ describe:
27
+ 'Mode of application deployment, \n\n Reinstall:\n' +
28
+ 'Uninstall and reinstall the application on the instance to ensure metadata on instance matches deployment package.\n' +
29
+ 'Warning: Metadata created on-instance that is not present locally will be lost\n\n' +
30
+ 'Complete:\n Deploy entire application.\n\nIncremental:\n Deploy changes since last deployment.',
31
+ choices: [DeploymentMode.REINSTALL, DeploymentMode.COMPLETE, DeploymentMode.INCREMENTAL],
32
+ type: 'string',
33
+ default: DeploymentMode.INCREMENTAL,
34
+ coerce: (arg) => arg.toLowerCase(),
35
+ alias: 'm',
36
+ })
37
+ .option('auth', {
38
+ describe: 'Credential alias to use for authentication with instance',
39
+ type: 'string',
40
+ alias: 'a',
41
+ })
42
+ .option('open-browser', {
43
+ describe: 'Open sys_app page in the default browser on successful deploy',
44
+ default: false,
45
+ type: 'boolean',
46
+ alias: 'b',
47
+ })
48
+ .option('info', {
49
+ describe: 'Get information from instance for most recent install of this app',
50
+ default: false,
51
+ type: 'boolean',
52
+ alias: 'i',
53
+ })
54
+ },
55
+ handler: async function (args: ArgumentsCamelCase<Arguments>): Promise<void> {
56
+ const { logger } = await import('@servicenow/sdk-cli-core/dist/cli-util/logger/index.js')
57
+
58
+ try {
59
+ const credentials: Creds = await getCredentials(args)
60
+
61
+ if (args.info) {
62
+ logger.info('Fetching most recent installation details for application.')
63
+ const { info: infoService } = await import('@servicenow/sdk-cli-core/dist/command/deploy/index.js')
64
+ await infoService({ ...credentials, ...args })
65
+ return
66
+ }
67
+ logger.info('Starting deployment...')
68
+ const { updateDeployManifest } = await import('@servicenow/sdk-cli-core/dist/cli-util/DeployUtils.js')
69
+
70
+ const { deploy: deployService } = await import('@servicenow/sdk-cli-core/dist/command/deploy/index.js')
71
+ const isDeployed = await deployService({
72
+ source: args.source,
73
+ mode: args.mode,
74
+ 'open-browser': args['open-browser'],
75
+ ...credentials,
76
+ })
77
+ if (isDeployed) {
78
+ updateDeployManifest(args.source)
79
+ }
80
+ } catch (error) {
81
+ logger.error(error instanceof Error ? error.message : (error as string), error)
82
+ }
83
+ },
84
+ }
@@ -0,0 +1,78 @@
1
+ import { Argv, ArgumentsCamelCase, CommandModule } from 'yargs'
2
+ import { Creds } from '@servicenow/sdk-cli-core/dist/command/login'
3
+ import { FetchMode } from '@servicenow/sdk-cli-core/dist/cli-util/Enums'
4
+ import { getCredentials } from '../../auth'
5
+ import { cwd } from '../../util'
6
+
7
+ interface Arguments extends Partial<Creds> {
8
+ directory: string
9
+ mode: FetchMode
10
+ auth: string | undefined
11
+ debug: boolean
12
+ experimental: boolean
13
+ }
14
+
15
+ export const fetch: CommandModule<unknown, Arguments> = {
16
+ command: 'fetch',
17
+ describe: 'Download application metadata from instance and update local metadata folder.',
18
+ builder: (yargs: Argv) => {
19
+ return yargs
20
+ .option('directory', {
21
+ describe: `Path to expand application`,
22
+ default: cwd(),
23
+ type: 'string',
24
+ })
25
+ .option('mode', {
26
+ describe:
27
+ 'Application fetch mode,\n\n' +
28
+ 'complete:\n Download and extract the complete application\n\n' +
29
+ 'incremental:\n Download changes since last fetch.',
30
+ choices: [FetchMode.COMPLETE, FetchMode.INCREMENTAL],
31
+ type: 'string',
32
+ default: FetchMode.INCREMENTAL,
33
+ coerce: (arg) => arg.toLowerCase(),
34
+ alias: 'm',
35
+ })
36
+ .option('auth', {
37
+ describe: 'Credential alias to use for authentication with instance',
38
+ type: 'string',
39
+ alias: 'a',
40
+ })
41
+ .option('debug', {
42
+ describe: 'Enable debug output',
43
+ type: 'boolean',
44
+ alias: 'd',
45
+ default: false,
46
+ })
47
+ .option('experimental', {
48
+ describe: 'Enables unstable experimental feature that may or may not be supported long term',
49
+ default: false,
50
+ type: 'boolean',
51
+ alias: 'e',
52
+ hidden: true,
53
+ })
54
+ },
55
+ handler: async function (args: ArgumentsCamelCase<Arguments>): Promise<void> {
56
+ const { logger } = await import('@servicenow/sdk-cli-core/dist/cli-util/logger/index.js')
57
+ logger.info('Fetching application metadata from instance...')
58
+
59
+ const { fetch: fetchService } = await import('@servicenow/sdk-cli-core/dist/command/fetch/index.js')
60
+ try {
61
+ const credentials: Creds = await getCredentials(args)
62
+
63
+ logger.warn(
64
+ 'WARN: Updates to JavaScript modules are not included when fetching application metadata from your instance.'
65
+ )
66
+ await fetchService({
67
+ directory: args.directory,
68
+ credentials,
69
+ mode: args.mode,
70
+ debug: args.debug,
71
+ experimental: args.experimental,
72
+ })
73
+ } catch (error) {
74
+ logger.error('Failed to fetch application: ')
75
+ logger.error(error instanceof Error ? error.message : (error as string), error)
76
+ }
77
+ },
78
+ }
@@ -0,0 +1,36 @@
1
+ import { Argv, ArgumentsCamelCase, CommandModule } from 'yargs'
2
+ import path from 'node:path'
3
+ import { cwd } from '../../util'
4
+
5
+ interface Arguments {
6
+ source: string
7
+ 'generate-deletes': boolean
8
+ }
9
+
10
+ export const generateModules: CommandModule<unknown, Arguments> = {
11
+ describe: 'Wrap modular JS source files into sys_module XMLs',
12
+ builder: (yargs: Argv) => {
13
+ return yargs
14
+ .positional('source', {
15
+ describe: `Path to "package.json"`,
16
+ default: cwd(),
17
+ type: 'string',
18
+ })
19
+ .option('generate-deletes', {
20
+ describe: 'Generate DELETE record updates for modules removed between builds',
21
+ default: true,
22
+ type: 'boolean',
23
+ })
24
+ },
25
+ handler: async function (args: ArgumentsCamelCase<Arguments>): Promise<void> {
26
+ const { logger } = await import('@servicenow/sdk-cli-core/dist/cli-util/logger/index.js')
27
+ const { generateModules: generateModulesService } = await import(
28
+ '@servicenow/sdk-cli-core/dist/command/generate-modules/index.js'
29
+ )
30
+ try {
31
+ await generateModulesService(path.resolve(args.source), args['generate-deletes'])
32
+ } catch (error) {
33
+ logger.error(error instanceof Error ? error.message : (error as string), error)
34
+ }
35
+ },
36
+ }
@@ -0,0 +1,27 @@
1
+ import { Argv, ArgumentsCamelCase, CommandModule } from 'yargs'
2
+ import path from 'node:path'
3
+ import { cwd } from '../../util'
4
+
5
+ interface Arguments {
6
+ source: string
7
+ }
8
+
9
+ export const pack: CommandModule<unknown, Arguments> = {
10
+ describe: 'Zip built app into deployable artifact',
11
+ builder: (yargs: Argv) => {
12
+ return yargs.positional('source', {
13
+ describe: `Path to "package.json"`,
14
+ default: cwd(),
15
+ type: 'string',
16
+ })
17
+ },
18
+ handler: async function (args: ArgumentsCamelCase<Arguments>): Promise<void> {
19
+ const { pack: packService } = await import('@servicenow/sdk-cli-core/dist/command/pack/index.js')
20
+ const { logger } = await import('@servicenow/sdk-cli-core/dist/cli-util/logger/index.js')
21
+ try {
22
+ await packService(path.resolve(args.source))
23
+ } catch (error) {
24
+ logger.error(error instanceof Error ? error.message : (error as string), error)
25
+ }
26
+ },
27
+ }
@@ -0,0 +1,43 @@
1
+ import { Argv, ArgumentsCamelCase, CommandModule } from 'yargs'
2
+ import path from 'node:path'
3
+ import { cwd } from '../../util'
4
+
5
+ interface Arguments {
6
+ source: string
7
+ 'generate-deletes': boolean
8
+ optimize: boolean
9
+ }
10
+
11
+ export const packageDependencies: CommandModule<unknown, Arguments> = {
12
+ describe: 'Wrap 3rd Party dependencies into sys_module XMLs',
13
+ builder: (yargs: Argv) => {
14
+ return yargs
15
+ .positional('source', {
16
+ describe: `Path to "package.json"`,
17
+ default: cwd(),
18
+ type: 'string',
19
+ })
20
+ .option('generate-deletes', {
21
+ describe: 'Generate DELETE record updates for dependencies removed between builds',
22
+ default: true,
23
+ type: 'boolean',
24
+ })
25
+ .option('optimize', {
26
+ describe: 'Optimize dependency packaging by reusing unchanged dependency xmls',
27
+ default: true,
28
+ type: 'boolean',
29
+ alias: 'o',
30
+ })
31
+ },
32
+ handler: async function (args: ArgumentsCamelCase<Arguments>): Promise<void> {
33
+ const { logger } = await import('@servicenow/sdk-cli-core/dist/cli-util/logger/index.js')
34
+ const { packageDependencies: packageDependenciesService } = await import(
35
+ '@servicenow/sdk-cli-core/dist/command/package-dependencies/index.js'
36
+ )
37
+ try {
38
+ await packageDependenciesService(path.resolve(args.source), args['generate-deletes'], args.optimize)
39
+ } catch (error) {
40
+ logger.error(error instanceof Error ? error.message : (error as string), error)
41
+ }
42
+ },
43
+ }
@@ -0,0 +1,40 @@
1
+ import { Argv, CommandModule } from 'yargs'
2
+ import { deploy } from '../deploy'
3
+ import { fetch } from '../fetch'
4
+ import { convert } from '../convert'
5
+ import { create } from '../create'
6
+ import { NowSDKError } from '@servicenow/sdk-cli-core/dist/cli-util/Error'
7
+
8
+ export const TEST_COMMAND = 'test'
9
+
10
+ export const test: CommandModule<unknown, any> = {
11
+ describe: 'Test command for development and testing purposes',
12
+ builder: (yargs: Argv) => {
13
+ return yargs
14
+ .option('host', {
15
+ describe: 'Target host for application deployment',
16
+ type: 'string',
17
+ })
18
+ .option('username', {
19
+ describe: 'The username to authenticate with host',
20
+ type: 'string',
21
+ })
22
+ .option('password', {
23
+ describe: 'The password to authenticate with host',
24
+ type: 'string',
25
+ })
26
+ .command(deploy)
27
+ .command(fetch)
28
+ .command(convert)
29
+ .command(create)
30
+ .demandCommand(1)
31
+ .check((args) => {
32
+ const { username, password, host } = args
33
+ if (!username || !password || !host) {
34
+ throw new NowSDKError('Missing required arguments, please provide username, password and host')
35
+ }
36
+ return true
37
+ })
38
+ },
39
+ handler: async function (): Promise<void> {},
40
+ }
@@ -0,0 +1,45 @@
1
+ import { Argv, CommandModule } from 'yargs'
2
+ import { transform as transformService, TransformArguments } from '@servicenow/sdk-cli-core/dist/command/transform'
3
+ import path from 'path'
4
+
5
+ export const transform: CommandModule<unknown, TransformArguments> = {
6
+ describe: 'Parse XML data from a directory and use it to transform source code for bi-directional sync',
7
+ builder: (yargs: Argv) => {
8
+ return yargs
9
+ .option('directory', {
10
+ describe: 'Directory from which to parse XML files',
11
+ type: 'string',
12
+ requiresArg: true,
13
+ alias: ['D', 'dir'],
14
+ default: path.resolve(process.cwd(), 'incoming'),
15
+ })
16
+ .option('clean', {
17
+ describe: 'Delete parsed XML files when finished',
18
+ type: 'boolean',
19
+ alias: 'c',
20
+ default: false,
21
+ })
22
+ .option('debug', {
23
+ describe: 'Enable debug output',
24
+ type: 'boolean',
25
+ alias: 'd',
26
+ default: false,
27
+ })
28
+ .option('experimental', {
29
+ describe: 'Enables unstable experimental feature that may or may not be supported long term',
30
+ default: false,
31
+ type: 'boolean',
32
+ alias: 'e',
33
+ hidden: true,
34
+ })
35
+ },
36
+ handler: async function (args: TransformArguments) {
37
+ const { logger } = await import('@servicenow/sdk-cli-core/dist/cli-util/logger/index.js')
38
+ try {
39
+ await transformService(args)
40
+ } catch (error) {
41
+ logger.error('Transform failed:')
42
+ logger.error((error as Error).stack ?? error)
43
+ }
44
+ },
45
+ }
@@ -0,0 +1,5 @@
1
+ export const epilogue = `
2
+ Use $now-sdk <command> --help for usage information.
3
+
4
+ For more information, please visit https://docs.servicenow.com/bundle/washingtondc-api-reference/page/script/sdk/reference/servicenow-sdk-cli-commands.html.
5
+ `
package/src/index.ts ADDED
@@ -0,0 +1,50 @@
1
+ import yargs from 'yargs'
2
+ import { usage } from './usage'
3
+ import { epilogue } from './epilogue'
4
+ import { clean } from './command/clean'
5
+ import { create } from './command/create'
6
+ import { convert } from './command/convert'
7
+ import { build } from './command/build'
8
+ import { compile } from './command/compile'
9
+ import { generateModules } from './command/generate-modules'
10
+ import { packageDependencies } from './command/package-dependencies'
11
+ import { pack } from './command/pack'
12
+ import { deploy } from './command/deploy'
13
+ import { fetch } from './command/fetch'
14
+ import { transform } from './command/transform'
15
+ import { auth } from './command/auth'
16
+ import { TEST_COMMAND, test } from './command/test'
17
+ import { lt } from 'semver'
18
+ import { logger } from '@servicenow/sdk-cli-core/dist/cli-util/logger'
19
+
20
+ yargs
21
+ .check(() => {
22
+ if (lt(process.version, '16.16.0')) {
23
+ logger.error('now-sdk requires node version to be >= 16.16.0')
24
+ process.exit(1)
25
+ }
26
+ return true
27
+ })
28
+ .usage(usage)
29
+ .command(auth)
30
+ .command(create)
31
+ .command(convert)
32
+ .command(fetch)
33
+ .command(build)
34
+ .command(deploy)
35
+ .command('transform', false, transform)
36
+ .command('clean [source]', false, clean)
37
+ .command('compile [source]', false, compile)
38
+ .command('generate-modules [source]', false, generateModules)
39
+ .command('package-dependencies [source]', false, packageDependencies)
40
+ .command('pack [source]', false, pack)
41
+ .command(`${TEST_COMMAND} <command>`, false, test)
42
+ .demandCommand()
43
+ .epilogue(epilogue)
44
+ .strictCommands()
45
+ .help()
46
+ .updateStrings({
47
+ 'Positionals:': 'Parameters:',
48
+ })
49
+ .alias('h', 'help')
50
+ .scriptName('now-sdk').argv
@@ -0,0 +1,13 @@
1
+ /* eslint-disable no-useless-escape */
2
+
3
+ // TODO: Prepending underscores for now, because yargs removes
4
+ // leading whitespace from the usage() argument
5
+ export const usage = `
6
+ _____ ______ _ __ _____ ____ __ \u2009__
7
+ ___/ | / / __ /| / / / ___// __ / /\u2009/_/
8
+ __/ |/ / / / / | /| / / \\__ \// / / / <
9
+ _/ /| / /_/ /| |/ |/ / ___/ / /_/ / /| |
10
+ /_/ |_/\_____/ |__/|__/ /____/_____/_/ |_|
11
+
12
+ Source-driven applications by writing actual code, and using modern, industry-standard development paradigms.
13
+ `
package/src/util.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { NowSDKError } from '@servicenow/sdk-cli-core/dist/cli-util/Error'
2
+ import path from 'path'
3
+ import fs from 'fs'
4
+
5
+ export function cwd(): string {
6
+ try {
7
+ const dir = process.cwd()
8
+ if (fs.existsSync(path.join(dir, 'package.json'))) {
9
+ return dir
10
+ }
11
+
12
+ throw new NowSDKError(
13
+ 'Could not find package.json. Please ensure you are running command in the intended directory or specify source as an argument.',
14
+ { type: 'missing_package_json' }
15
+ )
16
+ } catch (error) {
17
+ const { logger } = require('@servicenow/sdk-cli-core/dist/cli-util/logger')
18
+ logger.error(error instanceof Error ? error.message : (error as string), error)
19
+ process.exit()
20
+ }
21
+ }