Skip to content

Commit

Permalink
Updated blueprints (#22)
Browse files Browse the repository at this point in the history
* chore: Updated development dependencies

* chore: Updated dependencies in blueprints

* bugfix: Escaped __gitignore__ and __npmignore__ in blueprints-addon

* feature: Updated ember-cli-build.js

* chore: Ran update-blueprints-addon

* chore: Added changeset

---------

Co-authored-by: ijlee2 <ijlee2@users.noreply.github.com>
  • Loading branch information
ijlee2 and ijlee2 authored Aug 20, 2024
1 parent f599907 commit 046b19f
Show file tree
Hide file tree
Showing 37 changed files with 846 additions and 117 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-ravens-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-v2-addon-repo": minor
---

Updated blueprints
6 changes: 3 additions & 3 deletions configs/eslint/ember/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
},
"dependencies": {
"@rushstack/eslint-patch": "^1.10.3",
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"@typescript-eslint/eslint-plugin": "^8.2.0",
"@typescript-eslint/parser": "^8.2.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-ember": "^12.1.1",
"eslint-plugin-ember": "^12.2.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^17.8.1",
"eslint-plugin-prettier": "^5.1.3",
Expand Down
8 changes: 4 additions & 4 deletions configs/eslint/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"description": "Shared configuration for eslint (Node)",
"main": "typescript/index.js",
"scripts": {
"lint": "concurrently 'npm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint": "concurrently 'pnpm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'pnpm:lint:*:fix' --names 'fix:'",
"lint:js": "prettier --check '**/*.js'",
"lint:js:fix": "prettier --write '**/*.js'"
},
"dependencies": {
"@babel/core": "^7.24.7",
"@babel/eslint-parser": "7.25.1",
"@rushstack/eslint-patch": "^1.10.3",
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"@typescript-eslint/eslint-plugin": "^8.2.0",
"@typescript-eslint/parser": "^8.2.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './update-ember-cli-build.js';
export * from './update-package-json.js';
export * from './update-types.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';

import { AST } from '@codemod-utils/ast-javascript';

import type { Options } from '../../../types/run-new.js';

function updateSideWatch(file: string, options: Options): string {
const { addon } = options;

const traverse = AST.traverse(true);

const ast = traverse(file, {
visitCallExpression(path) {
if (
path.value.callee.name !== 'sideWatch' ||
path.value.arguments.length !== 2
) {
return false;
}

const watching = path.value.arguments[1].properties?.find(
(property: { key: { name: string } }) => {
return property.key.name === 'watching';
},
);

if (!watching) {
return false;
}

const paths = [
...watching.value.elements.map((element: { value: string }) => {
return element.value;
}),
join('..', addon.location, 'src'),
].sort();

watching.value.elements = paths.map((path) => {
return AST.builders.stringLiteral(path);
});

return false;
},
});

return AST.print(ast);
}

export function updateEmberCliBuild(appRoot: string, options: Options): void {
const oldPath = join(appRoot, 'ember-cli-build.js');
const oldFile = readFileSync(oldPath, 'utf8');

const newFile = updateSideWatch(oldFile, options);

writeFileSync(oldPath, newFile, 'utf8');
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { join } from 'node:path';

import type { Options } from '../../types/run-new.js';
import {
updateEmberCliBuild,
updatePackageJson,
updateTypes,
} from './update-docs-and-test-apps/index.js';
Expand All @@ -11,6 +12,7 @@ export function updateDocsApp(options: Options): void {

const appRoot = join(projectRoot, docsApp.location);

updateEmberCliBuild(appRoot, options);
updatePackageJson(appRoot, options);
updateTypes(appRoot, options);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
'use strict';

const sideWatch = require('@embroider/broccoli-side-watch');
const { Webpack } = require('@embroider/webpack');
const EmberApp = require('ember-cli/lib/broccoli/ember-app');

function isProduction() {
return EmberApp.env() === 'production';
}

module.exports = function (defaults) {
const app = new EmberApp(defaults, {
autoImport: {
watchDependencies: [],
},

'ember-cli-babel': {
enableTypeScriptTransform: true,
},

trees: {
app: sideWatch('app', {
watching: [],
}),
},

// Add options here
});

const options = {
packagerOptions: {
cssLoaderOptions: {
modules: {
localIdentName: isProduction()
? '[sha512:hash:base64:5]'
: '[path][name]__[local]',
mode: (resourcePath) => {
// We want to enable the local mode only for our own host app.
// All other addons should be loaded in the global mode.
const hostAppLocation =
'docs-app/node_modules/.embroider/rewritten-app';

return resourcePath.includes(hostAppLocation) ? 'local' : 'global';
},
},
sourceMap: !isProduction(),
},
publicAssetURL: '/',
webpackConfig: {
module: {
rules: [
{
test: /(node_modules\/\.embroider\/rewritten-app\/)(.*\.css)$/i,
use: [
{
loader: 'postcss-loader',
options: {
sourceMap: !isProduction(),
postcssOptions: {
config: './postcss.config.js',
},
},
},
],
},
/*
Uncomment this rule to load asset files, e.g. fonts, icons, etc.
See https://webpack.js.org/guides/asset-modules/ for more information.
*/
// {
// test: /(node_modules\/\.embroider\/rewritten-app\/)(.*\.(ttf|woff))$/,
// type: 'asset/resource',
// },
],
},
},
},
skipBabel: [
{
package: 'qunit',
},
],
splitAtRoutes: [],
staticAddonTestSupportTrees: true,
staticAddonTrees: true,
staticComponents: true,
staticEmberSource: true,
staticHelpers: true,
staticModifiers: true,
};

return require('@embroider/compat').compatBuild(app, Webpack, options);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
'use strict';

const sideWatch = require('@embroider/broccoli-side-watch');
const { Webpack } = require('@embroider/webpack');
const EmberApp = require('ember-cli/lib/broccoli/ember-app');

function isProduction() {
return EmberApp.env() === 'production';
}

module.exports = function (defaults) {
const app = new EmberApp(defaults, {
autoImport: {
watchDependencies: [],
},

'ember-cli-babel': {
enableTypeScriptTransform: true,
},

trees: {
app: sideWatch('app', {
watching: ['../packages/ui/form/src'],
}),
},

// Add options here
});

const options = {
packagerOptions: {
cssLoaderOptions: {
modules: {
localIdentName: isProduction()
? '[sha512:hash:base64:5]'
: '[path][name]__[local]',
mode: (resourcePath) => {
// We want to enable the local mode only for our own host app.
// All other addons should be loaded in the global mode.
const hostAppLocation =
'docs-app/node_modules/.embroider/rewritten-app';

return resourcePath.includes(hostAppLocation) ? 'local' : 'global';
},
},
sourceMap: !isProduction(),
},
publicAssetURL: '/',
webpackConfig: {
module: {
rules: [
{
test: /(node_modules\/\.embroider\/rewritten-app\/)(.*\.css)$/i,
use: [
{
loader: 'postcss-loader',
options: {
sourceMap: !isProduction(),
postcssOptions: {
config: './postcss.config.js',
},
},
},
],
},
/*
Uncomment this rule to load asset files, e.g. fonts, icons, etc.
See https://webpack.js.org/guides/asset-modules/ for more information.
*/
// {
// test: /(node_modules\/\.embroider\/rewritten-app\/)(.*\.(ttf|woff))$/,
// type: 'asset/resource',
// },
],
},
},
},
skipBabel: [
{
package: 'qunit',
},
],
splitAtRoutes: [],
staticAddonTestSupportTrees: true,
staticAddonTrees: true,
staticComponents: true,
staticEmberSource: true,
staticHelpers: true,
staticModifiers: true,
};

return require('@embroider/compat').compatBuild(app, Webpack, options);
};
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './update-ember-cli-build.js';
export * from './update-package-json.js';
export * from './update-types.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';

import { AST } from '@codemod-utils/ast-javascript';

import type { Options } from '../../../types/run-new.js';

function updateSideWatch(file: string, options: Options): string {
const { addon } = options;

const traverse = AST.traverse(true);

const ast = traverse(file, {
visitCallExpression(path) {
if (
path.value.callee.name !== 'sideWatch' ||
path.value.arguments.length !== 2
) {
return false;
}

const watching = path.value.arguments[1].properties?.find(
(property: { key: { name: string } }) => {
return property.key.name === 'watching';
},
);

if (!watching) {
return false;
}

watching.value.elements.push(
AST.builders.stringLiteral(join('..', addon.location, 'src')),
);

return false;
},
});

return AST.print(ast);
}

export function updateEmberCliBuild(appRoot: string, options: Options): void {
const oldPath = join(appRoot, 'ember-cli-build.js');
const oldFile = readFileSync(oldPath, 'utf8');

const newFile = updateSideWatch(oldFile, options);

writeFileSync(oldPath, newFile, 'utf8');
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { join } from 'node:path';

import type { Options } from '../../types/run-new.js';
import {
updateEmberCliBuild,
updatePackageJson,
updateTypes,
} from './update-docs-and-test-apps/index.js';
Expand All @@ -11,6 +12,7 @@ export function updateDocsApp(options: Options): void {

const appRoot = join(projectRoot, docsApp.location);

updateEmberCliBuild(appRoot, options);
updatePackageJson(appRoot, options);
updateTypes(appRoot, options);
}
Loading

0 comments on commit 046b19f

Please sign in to comment.