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
93 changes: 68 additions & 25 deletions features/template-only-glimmer-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,78 @@ module.exports = {
}

let root = project.root;
let prefix = project.config().podModulePrefix;
let isPod = !!prefix;
let projectConfig = project.config();

let { modulePrefix, podModulePrefix } = projectConfig;
let podsFolder;
if (podModulePrefix) {
if (!modulePrefix || !podModulePrefix.startsWith(`${modulePrefix}/`)) {
console.log(chalk.yellow(`${chalk.bold('Note:')} There is an automated refactor script available for this feature, but your \`podModulePrefix\` could not be processed correctly.\n`));
return;
}

podsFolder = podModulePrefix.slice(modulePrefix.length + 1);
if (!podsFolder) {
console.log(chalk.yellow(`${chalk.bold('Note:')} There is an automated refactor script available for this feature, but your \`podModulePrefix\` could not be processed correctly.\n`));
return;
}
}

let templates = [];
let components = [];

if (isPod) {
// TODO
console.log(chalk.yellow(`${chalk.bold('Note:')} There is an automated refactor script available for this feature, but it does not currently support "pod" apps. PRs welcome!\n`));
return;
} else {
let templatesRoot = path.join(root, 'app/templates/components');
let templateCandidates = yield p(glob)('**/*.hbs', { cwd: templatesRoot });

let componentsRoot = path.join(root, 'app/components');
let componentCandidates = yield p(glob)('**/*.@(j|t)s', { cwd: componentsRoot });

templateCandidates.forEach(templatePath => {
let jsPath = templatePath.replace(/\.hbs$/, '.js');
let tsPath = templatePath.replace(/\.hbs$/, '.ts');

let foundJs = componentCandidates.indexOf(jsPath) >= 0;
let foundTs = componentCandidates.indexOf(tsPath) >= 0;
if (!foundJs && !foundTs) {
templates.push(path.join('app/templates/components', templatePath));
components.push(path.join('app/components', jsPath)); // Always offer to create JS
}
});
}
// Handle "Classic" layout
let templatesRoot = path.join(root, 'app/templates/components');
let templateCandidates = yield p(glob)('**/*.hbs', { cwd: templatesRoot });

templateCandidates.forEach(template => {
let templatePath = path.join('app/templates/components', template);

let jsPath = path.join('app/components', template.replace(/\.hbs$/, '.js'));
if (fs.existsSync(path.join(root, jsPath))) return;

let tsPath = path.join('app/components', template.replace(/\.hbs$/, '.ts'));
if (fs.existsSync(path.join(root, tsPath))) return;

templates.push(templatePath);
components.push(jsPath); // Always offer to create JS
});

// Handle "Pods" layout without prefix

let componentsRoot = path.join(root, 'app/components');
templateCandidates = yield p(glob)('**/template.hbs', { cwd: componentsRoot });

templateCandidates.forEach(template => {
let templatePath = path.join('app/components', template);

let jsPath = path.join('app/components', template.replace(/template\.hbs$/, 'component.js'));
if (fs.existsSync(path.join(root, jsPath))) return;

let tsPath = path.join('app/components', template.replace(/template\.hbs$/, 'component.ts'));
if (fs.existsSync(path.join(root, tsPath))) return;

templates.push(templatePath);
components.push(jsPath); // Always offer to create JS
});

// Handle "Pods" layout *with* prefix

componentsRoot = path.join(root, `app/${podsFolder}/components`);
templateCandidates = yield p(glob)('**/template.hbs', { cwd: componentsRoot });

templateCandidates.forEach(template => {
let templatePath = path.join(`app/${podsFolder}/components`, template);

let jsPath = path.join(`app/${podsFolder}/components`, template.replace(/template\.hbs$/, 'component.js'));
if (fs.existsSync(path.join(root, jsPath))) return;

let tsPath = path.join(`app/${podsFolder}/components`, template.replace(/template\.hbs$/, 'component.ts'));
if (fs.existsSync(path.join(root, tsPath))) return;

templates.push(templatePath);
components.push(jsPath); // Always offer to create JS
});

if (templates.length === 0) {
return;
Expand Down
Loading