Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"ajv": "^6.12.3",
"axios": "^0.18.1",
"chalk": "^2.4.2",
"dc-management-sdk-js": "^1.9.0",
"dc-management-sdk-js": "^1.13.0",
"lodash": "^4.17.15",
"node-fetch": "^2.6.0",
"promise-retry": "^2.0.1",
Expand Down
28 changes: 23 additions & 5 deletions src/commands/configure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('configure command', function() {
jest.spyOn(fs, 'mkdirSync').mockReturnValueOnce(undefined);
jest.spyOn(fs, 'writeFileSync').mockReturnValueOnce(undefined);

handler({ ...yargArgs, ...configFixture });
handler({ ...yargArgs, ...configFixture, config: CONFIG_FILENAME() });

expect(fs.existsSync).toHaveBeenCalledWith(expect.stringMatching(/\.amplience$/));
expect(fs.mkdirSync).toHaveBeenCalledWith(expect.stringMatching(/\.amplience$/), { recursive: true });
Expand All @@ -48,7 +48,7 @@ describe('configure command', function() {
jest.spyOn(fs, 'mkdirSync');
jest.spyOn(fs, 'writeFileSync').mockReturnValueOnce(undefined);

handler({ ...yargArgs, ...configFixture });
handler({ ...yargArgs, ...configFixture, config: CONFIG_FILENAME() });

expect(fs.existsSync).toHaveBeenCalledWith(expect.stringMatching(/\.amplience$/));
expect(fs.mkdirSync).not.toHaveBeenCalled();
Expand All @@ -58,6 +58,24 @@ describe('configure command', function() {
);
});

it('should write a config file and use the specified file', () => {
jest
.spyOn(fs, 'existsSync')
.mockReturnValueOnce(false)
.mockReturnValueOnce(false);
jest.spyOn(fs, 'mkdirSync').mockReturnValueOnce(undefined);
jest.spyOn(fs, 'writeFileSync').mockReturnValueOnce(undefined);

handler({ ...yargArgs, ...configFixture, config: 'subdirectory/custom-config.json' });

expect(fs.existsSync).toHaveBeenCalledWith(expect.stringMatching(/subdirectory$/));
expect(fs.mkdirSync).toHaveBeenCalledWith(expect.stringMatching(/subdirectory$/), { recursive: true });
expect(fs.writeFileSync).toHaveBeenCalledWith(
expect.stringMatching(new RegExp('subdirectory/custom-config.json$')),
JSON.stringify(configFixture)
);
});

it('should report an error if its not possible to create the .amplience dir', () => {
jest
.spyOn(fs, 'existsSync')
Expand All @@ -69,7 +87,7 @@ describe('configure command', function() {
jest.spyOn(fs, 'writeFileSync').mockReturnValueOnce(undefined);

expect(() => {
handler({ ...yargArgs, ...configFixture });
handler({ ...yargArgs, ...configFixture, config: CONFIG_FILENAME() });
}).toThrowError(/^Unable to create dir ".*". Reason: .*/);

expect(fs.existsSync).toHaveBeenCalledWith(expect.stringMatching(/\.amplience$/));
Expand All @@ -88,7 +106,7 @@ describe('configure command', function() {
});

expect(() => {
handler({ ...yargArgs, ...configFixture });
handler({ ...yargArgs, ...configFixture, config: CONFIG_FILENAME() });
}).toThrowError(/^Unable to write config file ".*". Reason: .*/);

expect(fs.existsSync).toHaveBeenCalledWith(expect.stringMatching(/\.amplience$/));
Expand All @@ -104,7 +122,7 @@ describe('configure command', function() {
jest.spyOn(fs, 'readFileSync').mockReturnValueOnce(JSON.stringify(configFixture));
jest.spyOn(fs, 'writeFileSync');

handler({ ...yargArgs, ...configFixture });
handler({ ...yargArgs, ...configFixture, config: CONFIG_FILENAME() });

expect(fs.writeFileSync).not.toHaveBeenCalled();
});
Expand Down
10 changes: 7 additions & 3 deletions src/commands/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export type ConfigurationParameters = {
hubId: string;
};

type ConfigArgument = {
config: string;
};

export const configureCommandOptions: CommandOptions = {
clientId: { type: 'string', demandOption: true },
clientSecret: { type: 'string', demandOption: true },
Expand All @@ -43,14 +47,14 @@ const writeConfigFile = (configFile: string, parameters: ConfigurationParameters
export const readConfigFile = (configFile: string): object =>
fs.existsSync(configFile) ? JSON.parse(fs.readFileSync(configFile, 'utf-8')) : {};

export const handler = (argv: Arguments<ConfigurationParameters>): void => {
export const handler = (argv: Arguments<ConfigurationParameters & ConfigArgument>): void => {
const { clientId, clientSecret, hubId } = argv;
const storedConfig = readConfigFile(CONFIG_FILENAME());
const storedConfig = readConfigFile(argv.config);

if (isEqual(storedConfig, { clientId, clientSecret, hubId })) {
console.log('Config file up-to-date. Please use `--help` for command usage.');
return;
}
writeConfigFile(CONFIG_FILENAME(), { clientId, clientSecret, hubId });
writeConfigFile(argv.config, { clientId, clientSecret, hubId });
console.log('Config file updated.');
};
5 changes: 4 additions & 1 deletion src/commands/content-item/__mocks__/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export const setForceFail = (fail: boolean): void => {
export const handler = async (argv: Arguments<CopyItemBuilderOptions & ConfigurationParameters>): Promise<boolean> => {
calls.push(argv);
const idOut = argv.exportedIds as string[];
idOut.push(...outputIds);

if (idOut) {
idOut.push(...outputIds);
}

return !forceFail;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { ContentDependancy } from '../../../common/content-item/content-dependan
function dependancy(id: string): ContentDependancy {
return {
_meta: {
schema: 'http://bigcontent.io/cms/schema/v1/core#/definitions/content-link'
schema: 'http://bigcontent.io/cms/schema/v1/core#/definitions/content-link',
name: 'content-link'
},
contentType: 'https://dev-solutions.s3.amazonaws.com/DynamicContentTypes/Accelerators/blog.json',
id: id
Expand Down
86 changes: 86 additions & 0 deletions src/commands/content-item/__snapshots__/tree.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`content-item tree command handler tests should detect and print circular dependencies with a double line indicator 1`] = `
"=== LEVEL 2 (1) ===
item6
└─ item5

=== LEVEL 1 (3) ===
item3

item7

=== CIRCULAR (3) ===
item1 ═════════════════╗
├─ item2 ║
│ └─ item4 ║
│ └─ *** (item1) ══╝
└─ (item3)

Finished. Circular Dependencies printed: 1"
`;

exports[`content-item tree command handler tests should detect intertwined circular dependencies with multiple lines with different position 1`] = `
"=== CIRCULAR (6) ===
item5 ══════════════╗
└─ item6 ║
└─ *** (item5) ══╝

item1 ══════════════════════╗
└─ item2 ═════════════════╗ ║
└─ item3 ║ ║
├─ *** (item2) ═════╝ ║
└─ item4 ║
├─ *** (item1) ════╝
└─ (item5)

Finished. Circular Dependencies printed: 2"
`;

exports[`content-item tree command handler tests should print a single content item by itself 1`] = `
"=== LEVEL 1 (1) ===
item1

Finished. Circular Dependencies printed: 0"
`;

exports[`content-item tree command handler tests should print a tree of content items 1`] = `
"=== LEVEL 4 (1) ===
item1
├─ item2
│ ├─ item4
│ └─ item6
│ └─ item5
└─ item3

=== LEVEL 3 (1) ===
=== LEVEL 2 (1) ===
=== LEVEL 1 (3) ===
Finished. Circular Dependencies printed: 0"
`;

exports[`content-item tree command handler tests should print an error when invalid json is found 1`] = `
"=== LEVEL 1 (1) ===
item1

Finished. Circular Dependencies printed: 0"
`;

exports[`content-item tree command handler tests should print multiple disjoint trees of content items 1`] = `
"=== LEVEL 3 (1) ===
item1
├─ item2
│ └─ item4
└─ item3

=== LEVEL 2 (2) ===
item6
└─ item5

=== LEVEL 1 (4) ===
item7

Finished. Circular Dependencies printed: 0"
`;

exports[`content-item tree command handler tests should print nothing if no content is present 1`] = `"Finished. Circular Dependencies printed: 0"`;
10 changes: 6 additions & 4 deletions src/commands/content-item/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ArchiveLog } from '../../common/archive/archive-log';
import paginator from '../../common/dc-management-sdk-js/paginator';
import { confirmArchive } from '../../common/archive/archive-helpers';
import ArchiveOptions from '../../common/archive/archive-options';
import { ContentItem, DynamicContent } from 'dc-management-sdk-js';
import { ContentItem, DynamicContent, Status } from 'dc-management-sdk-js';
import { equalsOrRegex } from '../../common/filter/filter';
import { getDefaultLogPath, createLog } from '../../common/log-helpers';
import { FileLog } from '../../common/file-log';
Expand Down Expand Up @@ -153,7 +153,7 @@ export const getContentItems = async ({
contentType
}: {
client: DynamicContent;
id?: string;
id?: string | string[];
hubId: string;
repoId?: string | string[];
folderId?: string | string[];
Expand All @@ -165,7 +165,9 @@ export const getContentItems = async ({
const contentItems: ContentItem[] = [];

if (id != null) {
contentItems.push(await client.contentItems.get(id));
const itemIds = Array.isArray(id) ? id : [id];
const items = await Promise.all(itemIds.map(id => client.contentItems.get(id)));
contentItems.push(...items);

return {
contentItems,
Expand All @@ -192,7 +194,7 @@ export const getContentItems = async ({
)
: await Promise.all(
contentRepositories.map(async source => {
const items = await paginator(source.related.contentItems.list, { status: 'ACTIVE' });
const items = await paginator(source.related.contentItems.list, { status: Status.ACTIVE });
contentItems.push(...items);
})
);
Expand Down
Loading