Skip to content

Commit

Permalink
chore: Ran update-blueprints-addon
Browse files Browse the repository at this point in the history
  • Loading branch information
ijlee2 committed Aug 20, 2024
1 parent cd72d12 commit c3c5f13
Show file tree
Hide file tree
Showing 10 changed files with 478 additions and 0 deletions.
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);
}
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 c3c5f13

Please sign in to comment.