-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
478 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...repo/src/blueprints/blueprints-addon/src/steps/run-new/update-docs-and-test-apps/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
50 changes: 50 additions & 0 deletions
50
...ts/blueprints-addon/src/steps/run-new/update-docs-and-test-apps/update-ember-cli-build.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
.../src/blueprints/blueprints-addon/tests/fixtures/run-new/input/docs-app/ember-cli-build.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
93 changes: 93 additions & 0 deletions
93
...src/blueprints/blueprints-addon/tests/fixtures/run-new/output/docs-app/ember-cli-build.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
1 change: 1 addition & 0 deletions
1
...ript/output/my-repo/blueprints-addon/src/steps/run-new/update-docs-and-test-apps/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
50 changes: 50 additions & 0 deletions
50
...po/blueprints-addon/src/steps/run-new/update-docs-and-test-apps/update-ember-cli-build.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.