Skip to content
Merged
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
16 changes: 7 additions & 9 deletions packages/oc/src/cli/domain/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs-extra';
import targz from 'targz';

import * as validator from '../../registry/domain/validators';
import strings from '../../resources';
import deprecate from '../../utils/deprecate';
import isTemplateLegacy from '../../utils/is-template-legacy';
import type { Logger } from '../logger';
import * as clean from './clean';
Expand Down Expand Up @@ -37,25 +37,23 @@ export default function local() {
componentPath: string;
templateType: string;
}): Promise<void> {
const { componentName, logger } = options;
const { componentName } = options;
let { templateType } = options;
if (!validator.validateComponentName(componentName)) {
throw 'name not valid';
}

// LEGACY TEMPLATES WARNING
if (isTemplateLegacy(templateType)) {
const legacyName = templateType;
templateType = legacyName.replace(
legacyName,
`oc-template-${legacyName}`
);
logger.warn(
strings.messages.cli.legacyTemplateDeprecationWarning(
legacyName,
templateType
)
);
deprecate({
id: `cli-init-legacy-template-${legacyName}`,
subject: `The bare \`${legacyName}\` template type`,
replacement: 'the modern ESM component runtime (`oc-template-es6`)'
});
}
try {
await initTemplate(
Expand Down
5 changes: 0 additions & 5 deletions packages/oc/src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,6 @@ export default {
version: string
): string =>
`${green('✔')} Installed ${compiler} [${template} v${version}]`,
legacyTemplateDeprecationWarning: (
legacyType: string,
newType: string
): string =>
`Template-type "${legacyType}" has been deprecated and is now replaced by "${newType}"`,
CHANGES_DETECTED: (file: string): string =>
`Changes detected on file: ${file}`,
CHECKING_DEPENDENCIES: 'Ensuring dependencies are loaded...',
Expand Down
94 changes: 94 additions & 0 deletions packages/oc/test/unit/cli-domain-local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const expect = require('chai').expect;
const injectr = require('injectr');
const sinon = require('sinon');

const initialise = () => {
const deprecate = sinon.stub();
const initTemplate = sinon.stub().resolves({ ok: true });
const Local = injectr(
'../../dist/cli/domain/local.js',
{
'../../registry/domain/validators': {
validateComponentName: sinon.stub().returns(true)
},
'../../utils/deprecate': { __esModule: true, default: deprecate },
'./clean': {},
'./get-components-by-dir': () => ({}),
'./init-template': initTemplate,
'./mock': () => ({}),
'./package-components': () => () => ({})
},
{}
).default;

return {
deprecate,
initTemplate,
local: Local()
};
};

const initOptions = (templateType) => ({
componentName: 'new-component',
componentPath: '/path/to/new-component',
logger: { warn: sinon.spy() },
templateType
});

describe('cli : domain : local', () => {
for (const [legacyType, templateType] of [
['jade', 'oc-template-jade'],
['handlebars', 'oc-template-handlebars']
]) {
describe(`when initialising with bare ${legacyType}`, () => {
let data;

beforeEach(async () => {
data = initialise();
await data.local.init(initOptions(legacyType));
});

it('emits a deprecation notice pointing to the modern runtime', () => {
expect(data.deprecate.calledOnce).to.be.true;
expect(data.deprecate.args[0][0]).to.deep.include({
id: `cli-init-legacy-template-${legacyType}`,
subject: `The bare \`${legacyType}\` template type`,
replacement:
'the modern ESM component runtime (`oc-template-es6`)'
});
});

it('keeps scaffolding on the package-backed legacy template', () => {
expect(data.initTemplate.args[0][0]).to.include({
compiler: `${templateType}-compiler`,
templateType
});
});
});
}

for (const templateType of [
'oc-template-jade',
'oc-template-handlebars'
]) {
describe(`when initialising with ${templateType}`, () => {
let data;

beforeEach(async () => {
data = initialise();
await data.local.init(initOptions(templateType));
});

it('does not emit the legacy deprecation notice', () => {
expect(data.deprecate.called).to.be.false;
});

it('keeps the selected template and compiler unchanged', () => {
expect(data.initTemplate.args[0][0]).to.include({
compiler: `${templateType}-compiler`,
templateType
});
});
});
}
});
Loading