How to use writePackageJson method in storybook-root

Best JavaScript code snippet using storybook-root

test.js

Source:test.js Github

copy

Full Screen

...70 shell.mkdir('tmp')71 shell.cd('tmp')72 shell.exec('git init')73 commit('root-commit')74 writePackageJson('1.0.0')75}76function finishTemp () {77 shell.cd('../')78 shell.rm('-rf', 'tmp')79}80function getPackageVersion () {81 return JSON.parse(fs.readFileSync('package.json', 'utf-8')).version82}83describe('cli', function () {84 beforeEach(initInTempFolder)85 afterEach(finishTemp)86 describe('CHANGELOG.md does not exist', function () {87 it('populates changelog with commits since last tag by default', function () {88 commit('✅ [ADD] first commit')89 shell.exec('git tag -a v1.0.0 -m "my awesome first release"')90 commit('✴️ [FIX] patch release')91 execCli().code.should.equal(0)92 var content = fs.readFileSync('CHANGELOG.md', 'utf-8')93 content.should.match(/patch release/)94 content.should.not.match(/first commit/)95 })96 it('includes all commits if --first-release is true', function () {97 writePackageJson('1.0.1')98 commit('✅ [ADD] first commit')99 commit('✴️ [FIX] patch release')100 execCli('--first-release').code.should.equal(0)101 var content = fs.readFileSync('CHANGELOG.md', 'utf-8')102 content.should.match(/patch release/)103 content.should.match(/first commit/)104 shell.exec('git tag').stdout.should.match(/1\.0\.1/)105 })106 })107 describe('CHANGELOG.md exists', function () {108 it('appends the new release above the last release, removing the old header', function () {109 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')110 commit('✅ [ADD] first commit')111 shell.exec('git tag -a v1.0.0 -m "my awesome first release"')112 commit('✴️ [FIX] patch release')113 execCli().code.should.equal(0)114 var content = fs.readFileSync('CHANGELOG.md', 'utf-8')115 content.should.match(/1\.0\.1/)116 content.should.not.match(/legacy header format/)117 })118 it('commits all staged files', function () {119 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')120 commit('✅ [ADD] first commit')121 shell.exec('git tag -a v1.0.0 -m "my awesome first release"')122 commit('✴️ [FIX] patch release')123 fs.writeFileSync('STUFF.md', 'stuff\n', 'utf-8')124 shell.exec('git add STUFF.md')125 execCli('--commit-all').code.should.equal(0)126 var content = fs.readFileSync('CHANGELOG.md', 'utf-8')127 var status = shell.exec('git status --porcelain') // see http://unix.stackexchange.com/questions/155046/determine-if-git-working-directory-is-clean-from-a-script128 status.should.equal('')129 status.should.not.match(/STUFF.md/)130 content.should.match(/1\.0\.1/)131 content.should.not.match(/legacy header format/)132 })133 })134 describe('with mocked git', function () {135 it('--sign signs the commit and tag', function () {136 // mock git with file that writes args to gitcapture.log137 return mockGit('require("fs").appendFileSync("gitcapture.log", JSON.stringify(process.argv.splice(2)) + "\\n")')138 .then(function (unmock) {139 execCli('--sign').code.should.equal(0)140 var captured = shell.cat('gitcapture.log').stdout.split('\n').map(function (line) {141 return line ? JSON.parse(line) : line142 })143 captured[captured.length - 3].should.deep.equal(['commit', '-S', 'CHANGELOG.md', 'package.json', '-m', '⏩ [PUB] (release) 1.0.1'])144 captured[captured.length - 2].should.deep.equal(['tag', '-s', 'v1.0.1', '-m', '⏩ [PUB] (release) 1.0.1'])145 unmock()146 })147 })148 it('exits with error code if git commit fails', function () {149 // mock git by throwing on attempt to commit150 return mockGit('console.error("commit yourself"); process.exit(128);', 'commit')151 .then(function (unmock) {152 var result = execCli()153 result.code.should.equal(1)154 result.stderr.should.match(/commit yourself/)155 unmock()156 })157 })158 it('exits with error code if git add fails', function () {159 // mock git by throwing on attempt to add160 return mockGit('console.error("addition is hard"); process.exit(128);', 'add')161 .then(function (unmock) {162 var result = execCli()163 result.code.should.equal(1)164 result.stderr.should.match(/addition is hard/)165 unmock()166 })167 })168 it('exits with error code if git tag fails', function () {169 // mock git by throwing on attempt to commit170 return mockGit('console.error("tag, you\'re it"); process.exit(128);', 'tag')171 .then(function (unmock) {172 var result = execCli()173 result.code.should.equal(1)174 result.stderr.should.match(/tag, you're it/)175 unmock()176 })177 })178 it('doesn\'t fail fast on stderr output from git', function () {179 // mock git by throwing on attempt to commit180 return mockGit('console.error("haha, kidding, this is just a warning"); process.exit(0);', 'add')181 .then(function (unmock) {182 writePackageJson('1.0.0')183 var result = execCli()184 result.code.should.equal(0)185 result.stderr.should.match(/haha, kidding, this is just a warning/)186 unmock()187 })188 })189 })190 describe('lifecycle scripts', () => {191 describe('prebump hook', function () {192 it('should allow prebump hook to return an alternate version #', function () {193 writePackageJson('1.0.0', {194 'standard-version': {195 'scripts': {196 'prebump': 'node scripts/prebump'197 }198 }199 })200 writeHook('prebump', false, 'console.log("9.9.9")')201 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')202 commit('✅ [ADD] first commit')203 var result = execCli('--patch')204 result.stdout.should.match(/9\.9\.9/)205 result.code.should.equal(0)206 })207 })208 describe('postbump hook', function () {209 it('should run the postbump hook when provided', function () {210 writePackageJson('1.0.0', {211 'standard-version': {212 'scripts': {213 'postbump': 'node scripts/postbump'214 }215 }216 })217 writePostBumpHook()218 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')219 commit('✅ [ADD] first commit')220 var result = execCli('--patch')221 result.code.should.equal(0)222 result.stderr.should.match(/postbump ran/)223 })224 it('should run the postbump and exit with error when postbump fails', function () {225 writePackageJson('1.0.0', {226 'standard-version': {227 'scripts': {228 'postbump': 'node scripts/postbump'229 }230 }231 })232 writePostBumpHook(true)233 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')234 commit('✅ [ADD] first commit')235 var result = execCli('--patch')236 result.code.should.equal(1)237 result.stderr.should.match(/postbump-failure/)238 })239 })240 describe('precommit hook', function () {241 it('should run the precommit hook when provided', function () {242 writePackageJson('1.0.0', {243 'standard-version': {244 'scripts': {245 'precommit': 'node scripts/precommit'246 }247 }248 })249 writeHook('precommit')250 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')251 commit('✅ [ADD] first commit')252 var result = execCli('--patch')253 result.code.should.equal(0)254 result.stderr.should.match(/precommit ran/)255 })256 it('should run the precommit hook and exit with error when precommit fails', function () {257 writePackageJson('1.0.0', {258 'standard-version': {259 'scripts': {260 'precommit': 'node scripts/precommit'261 }262 }263 })264 writeHook('precommit', true)265 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')266 commit('✅ [ADD] first commit')267 var result = execCli('--patch')268 result.code.should.equal(1)269 result.stderr.should.match(/precommit-failure/)270 })271 it('should allow an alternate commit message to be provided by precommit script', function () {272 writePackageJson('1.0.0', {273 'standard-version': {274 'scripts': {275 'precommit': 'node scripts/precommit'276 }277 }278 })279 writeHook('precommit', false, 'console.log("releasing %s delivers #222")')280 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')281 commit('✅ [ADD] first commit')282 var result = execCli('--patch')283 result.code.should.equal(0)284 shell.exec('git log --oneline -n1').should.match(/delivers #222/)285 })286 })287 })288 describe('pre-release', function () {289 it('works fine without specifying a tag id when prereleasing', function () {290 writePackageJson('1.0.0')291 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')292 commit('✅ [ADD] first commit')293 return execCliAsync('--prerelease')294 .then(function () {295 // it's a feature commit, so it's minor type296 getPackageVersion().should.equal('1.1.0-0')297 })298 })299 it('advises use of --tag prerelease for publishing to npm', function () {300 writePackageJson('1.0.0')301 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')302 commit('✅ [ADD] first commit')303 execCli('--prerelease').stdout.should.include('--tag prerelease')304 })305 })306 describe('manual-release', function () {307 it('throws error when not specifying a release type', function () {308 writePackageJson('1.0.0')309 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')310 commit('✴️ [FIX] first commit')311 execCli('--release-as').code.should.above(0)312 })313 describe('release-types', function () {314 var regularTypes = ['major', 'minor', 'patch']315 regularTypes.forEach(function (type) {316 it('creates a ' + type + ' release', function () {317 var originVer = '1.0.0'318 writePackageJson(originVer)319 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')320 commit('✴️ [FIX] first commit')321 return execCliAsync('--release-as ' + type)322 .then(function () {323 var version = {324 major: semver.major(originVer),325 minor: semver.minor(originVer),326 patch: semver.patch(originVer)327 }328 version[type] += 1329 getPackageVersion().should.equal(version.major + '.' + version.minor + '.' + version.patch)330 })331 })332 })333 // this is for pre-releases334 regularTypes.forEach(function (type) {335 it('creates a pre' + type + ' release', function () {336 var originVer = '1.0.0'337 writePackageJson(originVer)338 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')339 commit('✴️ [FIX] first commit')340 return execCliAsync('--release-as ' + type + ' --prerelease ' + type)341 .then(function () {342 var version = {343 major: semver.major(originVer),344 minor: semver.minor(originVer),345 patch: semver.patch(originVer)346 }347 version[type] += 1348 getPackageVersion().should.equal(version.major + '.' + version.minor + '.' + version.patch + '-' + type + '.0')349 })350 })351 })352 })353 describe('release-as-exact', function () {354 it('releases as v100.0.0', function () {355 var originVer = '1.0.0'356 writePackageJson(originVer)357 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')358 commit('✴️ [FIX] first commit')359 return execCliAsync('--release-as v100.0.0')360 .then(function () {361 getPackageVersion().should.equal('100.0.0')362 })363 })364 it('releases as 200.0.0-amazing', function () {365 var originVer = '1.0.0'366 writePackageJson(originVer)367 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')368 commit('✴️ [FIX] first commit')369 return execCliAsync('--release-as 200.0.0-amazing')370 .then(function () {371 getPackageVersion().should.equal('200.0.0-amazing')372 })373 })374 })375 it('creates a prerelease with a new minor version after two prerelease patches', function () {376 writePackageJson('1.0.0')377 fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')378 commit('✴️ [FIX] first patch')379 return execCliAsync('--release-as patch --prerelease dev')380 .then(function () {381 getPackageVersion().should.equal('1.0.1-dev.0')382 })383 // second384 .then(function () {385 commit('✴️ [FIX] second patch')386 return execCliAsync('--prerelease dev')387 })388 .then(function () {389 getPackageVersion().should.equal('1.0.1-dev.1')390 })391 // third392 .then(function () {393 commit('✅ [ADD] first new feat')394 return execCliAsync('--release-as minor --prerelease dev')395 })396 .then(function () {397 getPackageVersion().should.equal('1.1.0-dev.0')398 })399 .then(function () {400 commit('✴️ [FIX] third patch')401 return execCliAsync('--release-as minor --prerelease dev')402 })403 .then(function () {404 getPackageVersion().should.equal('1.1.0-dev.1')405 })406 .then(function () {407 commit('✴️ [FIX] forth patch')408 return execCliAsync('--prerelease dev')409 })410 .then(function () {411 getPackageVersion().should.equal('1.1.0-dev.2')412 })413 })414 })415 it('handles commit messages longer than 80 characters', function () {416 commit('✅ [ADD] (example) first commit')417 shell.exec('git tag -a v1.0.0 -m "my awesome first release"')418 commit('✴️ [FIX] (scope) this is my fairly long commit message which is testing whether or not we allow for long commit messages')419 execCli().code.should.equal(0)420 var content = fs.readFileSync('CHANGELOG.md', 'utf-8')421 content.should.match(/this is my fairly long commit message which is testing whether or not we allow for long commit messages/)422 })423 it('formats the commit and tag messages appropriately', function () {424 commit('✅ [ADD] (example) first commit')425 shell.exec('git tag -a v1.0.0 -m "my awesome first release"')426 commit('✅ [ADD] new feature!')427 execCli().code.should.equal(0)428 // check last commit message429 shell.exec('git log --oneline -n1').stdout.should.include('[PUB] (release) 1.1.0')430 // check annotated tag message431 shell.exec('git tag -l -n1 v1.1.0').stdout.should.include('[PUB] (release) 1.1.0')432 })433 it('appends line feed at end of package.json', function () {434 execCli().code.should.equal(0)435 var pkgJson = fs.readFileSync('package.json', 'utf-8')436 pkgJson.should.equal(['{', ' "version": "1.0.1"', '}', ''].join('\n'))437 })438 it('does not run git hooks if the --no-verify flag is passed', function () {439 writeGitPreCommitHook()440 commit('✅ [ADD] first commit')441 execCli('--no-verify').code.should.equal(0)442 commit('✅ [ADD] second commit')443 execCli('-n').code.should.equal(0)444 })445 it('does not print output when the --silent flag is passed', function () {446 var result = execCli('--silent')447 result.code.should.equal(0)448 result.stdout.should.equal('')449 result.stderr.should.equal('')450 })451 it('does not display `npm publish` if the package is private', function () {452 writePackageJson('1.0.0', {private: true})453 var result = execCli()454 result.code.should.equal(0)455 result.stdout.should.not.match(/npm publish/)456 })457 it('includes merge commits', function () {458 var branchName = 'new-feature'459 commit('✅ [ADD] first commit')460 shell.exec('git tag -a v1.0.0 -m "my awesome first release"')461 branch(branchName)462 checkout(branchName)463 commit('Implementing new feature')464 checkout('master')465 merge('✅ [ADD] new feature from branch', branchName)466 execCli().code.should.equal(0)467 var content = fs.readFileSync('CHANGELOG.md', 'utf-8')468 content.should.match(/new feature from branch/)469 var pkgJson = fs.readFileSync('package.json', 'utf-8')470 pkgJson.should.equal(['{', ' "version": "1.1.0"', '}', ''].join('\n'))471 })472})473describe('standard-version', function () {474 beforeEach(initInTempFolder)475 afterEach(finishTemp)476 describe('with mocked conventionalChangelog', function () {477 beforeEach(function () {478 mockery.enable({warnOnUnregistered: false, useCleanCache: true})479 mockery.registerMock('conventional-changelog', function () {480 var readable = new stream.Readable({objectMode: true})481 readable._read = function () {482 }483 setImmediate(readable.emit.bind(readable), 'error', new Error('changelog err'))484 return readable485 })486 })487 afterEach(function () {488 mockery.deregisterMock('conventional-changelog')489 mockery.disable()490 })491 it('should exit on changelog error', function (done) {492 commit('✅ [ADD] first commit')493 shell.exec('git tag -a v1.0.0 -m "my awesome first release"')494 commit('✅ [ADD] new feature!')495 require('./index')({silent: true})496 .catch((err) => {497 err.message.should.match(/changelog err/)498 return done()499 })500 })501 })502 it('formats the commit and tag messages appropriately', function (done) {503 commit('✅ [ADD] first commit')504 shell.exec('git tag -a v1.0.0 -m "my awesome first release"')505 commit('✅ [ADD] new feature!')506 require('./index')({silent: true})507 .then(() => {508 // check last commit message509 shell.exec('git log --oneline -n1').stdout.should.include('[PUB] (release) 1.1.0')510 // check annotated tag message511 shell.exec('git tag -l -n1 v1.1.0').stdout.should.include('[PUB] (release) 1.1.0')512 done()513 })514 })515 describe('bower.json support', function () {516 beforeEach(function () {517 writeBowerJson('1.0.0')518 })519 it('bumps version # in bower.json', function (done) {520 commit('✅ [ADD] first commit')521 shell.exec('git tag -a v1.0.0 -m "my awesome first release"')522 commit('✅ [ADD] new feature!')523 require('./index')({silent: true})524 .then(() => {525 JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal('1.1.0')526 getPackageVersion().should.equal('1.1.0')527 return done()528 })529 })530 })531 describe('npm-shrinkwrap.json support', function () {532 beforeEach(function () {533 writeNpmShrinkwrapJson('1.0.0')534 })535 it('bumps version # in npm-shrinkwrap.json', function (done) {536 commit('✅ [ADD] first commit')537 shell.exec('git tag -a v1.0.0 -m "my awesome first release"')538 commit('✅ [ADD] new feature!')539 require('./index')({silent: true})540 .then(() => {541 JSON.parse(fs.readFileSync('npm-shrinkwrap.json', 'utf-8')).version.should.equal('1.1.0')542 getPackageVersion().should.equal('1.1.0')543 return done()544 })545 })546 })547 describe('package-lock.json support', function () {548 beforeEach(function () {549 writePackageLockJson('1.0.0')550 })551 it('bumps version # in package-lock.json', function (done) {552 commit('✅ [ADD] first commit')553 shell.exec('git tag -a v1.0.0 -m "my awesome first release"')554 commit('✅ [ADD] new feature!')555 require('./index')({silent: true})556 .then(() => {557 JSON.parse(fs.readFileSync('package-lock.json', 'utf-8')).version.should.equal('1.1.0')558 getPackageVersion().should.equal('1.1.0')559 return done()560 })561 })562 })563 describe('dry-run', function () {564 it('skips all non-idempotent steps', function (done) {565 commit('✅ [ADD] first commit')566 shell.exec('git tag -a v1.0.0 -m "my awesome first release"')567 commit('✅ [ADD] (api) new feature!')568 execCli('--dry-run').stdout.should.match(/### ✅ Features/)569 shell.exec('git log --oneline -n1').stdout.should.include('(api) new feature!')570 shell.exec('git tag').stdout.should.match(/1\.0\.0/)571 getPackageVersion().should.equal('1.0.0')572 return done()573 })574 })575 describe('skip', () => {576 it('allows bump and changelog generation to be skipped', function () {577 let changelogContent = 'legacy header format<a name="1.0.0">\n'578 writePackageJson('1.0.0')579 fs.writeFileSync('CHANGELOG.md', changelogContent, 'utf-8')580 commit('✅ [ADD] first commit')581 return execCliAsync('--skip.bump true --skip.changelog true')582 .then(function () {583 getPackageVersion().should.equal('1.0.0')584 var content = fs.readFileSync('CHANGELOG.md', 'utf-8')585 content.should.equal(changelogContent)586 })587 })588 it('allows the commit phase to be skipped', function () {589 let changelogContent = 'legacy header format<a name="1.0.0">\n'590 writePackageJson('1.0.0')591 fs.writeFileSync('CHANGELOG.md', changelogContent, 'utf-8')592 commit('✅ [ADD] new feature from branch')593 return execCliAsync('--skip.commit true')594 .then(function () {595 getPackageVersion().should.equal('1.1.0')596 var content = fs.readFileSync('CHANGELOG.md', 'utf-8')597 content.should.match(/new feature from branch/)598 // check last commit message599 shell.exec('git log --oneline -n1').stdout.should.include('✅ [ADD] new feature from branch')600 })601 })602 })...

Full Screen

Full Screen

add.ts

Source:add.ts Github

copy

Full Screen

1import { spawnSync } from "child_process";2import path from "path";3import fs from "fs-extra";4import { findMonoRepo, findPackages } from "@mono-repo/utils";5import { orderPackageKeyValueMap } from "../order-package-key-value-map";6interface AddCommandOptions {7 dev: boolean;8 exact: boolean;9 package: string;10 peer: boolean;11}12export const add = async (options: AddCommandOptions) => {13 const monoRepo = await findMonoRepo();14 const packages = await findPackages(monoRepo, { order: "alphabetical" });15 const cwd = process.cwd();16 const targetPackage = packages.find((p) => p.dir === cwd);17 if (!targetPackage) {18 throw new Error("Not in a package directory.");19 }20 const isScoped = options.package.startsWith("@");21 let isVersionSpecified = false;22 const packageParts = options.package.split("@");23 const packageName = `${isScoped ? "@" : ""}${packageParts[0]}${24 packageParts[1] ?? ""25 }`;26 isVersionSpecified = isScoped27 ? packageParts.length === 328 : packageParts.length === 2;29 const localPackage = packages.find((p) => p.json.name === packageName);30 if (localPackage) {31 let packageVersion = isVersionSpecified32 ? packageParts[packageParts.length - 1]33 : `${options.exact ? "" : "^"}${localPackage.json.version}`;34 const writePackageJson = targetPackage.json;35 if (options.dev) {36 if (!writePackageJson.devDependencies) {37 writePackageJson.devDependencies = {};38 }39 writePackageJson.devDependencies[localPackage.json.name] = packageVersion;40 writePackageJson.devDependencies = orderPackageKeyValueMap(41 writePackageJson.devDependencies42 );43 } else if (options.peer) {44 if (!writePackageJson.peerDependencies) {45 writePackageJson.peerDependencies = {};46 }47 writePackageJson.peerDependencies[48 localPackage.json.name49 ] = packageVersion;50 writePackageJson.peerDependencies = orderPackageKeyValueMap(51 writePackageJson.peerDependencies52 );53 } else {54 if (!writePackageJson.dependencies) {55 writePackageJson.dependencies = {};56 }57 writePackageJson.dependencies[localPackage.json.name] = packageVersion;58 writePackageJson.dependencies = orderPackageKeyValueMap(59 writePackageJson.dependencies60 );61 }62 await fs.writeJSON(63 path.resolve(targetPackage.dir, "package.json"),64 writePackageJson,65 { encoding: "utf8", spaces: 2 }66 );67 spawnSync("yarn", [], {68 cwd,69 encoding: "utf8",70 stdio: "inherit",71 });72 } else {73 const args = [74 "add",75 options.package,76 options.dev ? "--dev" : "",77 options.peer ? "--peer" : "",78 options.exact ? "--exact" : "",79 ].filter((s) => s.length > 0);80 spawnSync("yarn", args, {81 cwd,82 encoding: "utf8",83 stdio: "inherit",84 });85 }...

Full Screen

Full Screen

liferay_theme_config.js

Source:liferay_theme_config.js Github

copy

Full Screen

1const _ = require('lodash');2const fs = require('fs-extra');3const path = require('path');4function getConfig(all, alternatePath) {5 let packageJSON = getPackageJSON(alternatePath);6 return all ? packageJSON : packageJSON.liferayTheme;7}8function removeConfig(settings) {9 let packageJSON = getPackageJSON();10 packageJSON.liferayTheme = _.omit(packageJSON.liferayTheme, settings);11 writePackageJSON(packageJSON);12}13function removeDependencies(dependencies) {14 let packageJSON = getPackageJSON();15 deleteDependencies(packageJSON.dependencies, dependencies);16 deleteDependencies(packageJSON.devDependencies, dependencies);17 writePackageJSON(packageJSON);18}19function setConfig(config) {20 let packageJSON = getPackageJSON();21 if (packageJSON.liferayTheme) {22 if (config.baseTheme) {23 packageJSON.liferayTheme.baseTheme = undefined;24 }25 if (config.themeletDependencies) {26 packageJSON.liferayTheme.themeletDependencies = undefined;27 }28 }29 packageJSON = _.merge(packageJSON, {30 liferayTheme: config,31 });32 writePackageJSON(packageJSON);33}34function setDependencies(dependencies, devDependencies) {35 let packageJSON = getPackageJSON();36 let selector = devDependencies ? 'devDependencies' : 'dependencies';37 if (!packageJSON[selector]) {38 packageJSON[selector] = {};39 }40 _.merge(packageJSON[selector], dependencies);41 writePackageJSON(packageJSON);42}43module.exports = {44 getConfig,45 removeConfig,46 removeDependencies,47 setConfig,48 setDependencies,49};50function deleteDependencies(sourceDependencies, deletedDependencies) {51 _.forEach(sourceDependencies, function(item, index) {52 if (deletedDependencies.indexOf(index) > -1) {53 delete sourceDependencies[index];54 }55 });56}57function getPackageJSON(alternatePath) {58 alternatePath = alternatePath || process.cwd();59 let packageJSONContent = fs.readFileSync(60 path.join(alternatePath, 'package.json'),61 {62 encoding: 'utf8',63 }64 );65 return JSON.parse(packageJSONContent);66}67function writePackageJSON(json) {68 fs.writeFileSync(69 path.join(process.cwd(), 'package.json'),70 JSON.stringify(json, null, '\t')71 );...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const writePackageJson = require('storybook-root-alias').writePackageJson;2const writePackageJson = require('storybook-root-alias').writePackageJson;3const writePackageJson = require('storybook-root-alias').writePackageJson;4const writePackageJson = require('storybook-root-alias').writePackageJson;5const writePackageJson = require('storybook-root-alias').writePackageJson;6const writePackageJson = require('storybook-root-alias').writePackageJson;7const writePackageJson = require('storybook-root-alias').writePackageJson;8const writePackageJson = require('storybook-root-alias').writePackageJson;9const writePackageJson = require('storybook-root-alias').writePackageJson;10const writePackageJson = require('storybook-root-alias').writePackageJson;11const writePackageJson = require('storybook-root-alias').writePackageJson;12const writePackageJson = require('storybook-root-alias').writePackageJson;13const writePackageJson = require('storybook-root-alias').writePackageJson;14const writePackageJson = require('storybook-root-alias').writePackageJson;15const writePackageJson = require('storybook-root-alias').writePackageJson;16const writePackageJson = require('storybook-root-alias').writePackageJson;

Full Screen

Using AI Code Generation

copy

Full Screen

1const { writePackageJson } = require('storybook-root-require');2writePackageJson();3const { getPackageJson } = require('storybook-root-require');4module.exports = {5 webpackFinal: async (config) => {6 const packageJson = getPackageJson();7 const { version } = packageJson;8 config.plugins.push(new webpack.DefinePlugin({9 __VERSION__: JSON.stringify(version),10 }));11 return config;12 },13};14export const parameters = {15 actions: { argTypesRegex: '^on[A-Z].*' },16 options: {17 storySort: {18 },19 },20};21 body {22 font-family: 'Open Sans', sans-serif;23 }24import { addons } from '@storybook/addons';25import { create } from '@storybook/theming/create';26import { getPackageJson } from 'storybook-root-require';27const packageJson = getPackageJson();28const { version } = packageJson;29addons.setConfig({30 theme: create({

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const { writePackageJson } = require('storybook-root');3const packageJsonPath = path.join(__dirname, 'package.json');4writePackageJson(packageJsonPath, 'storybook', 'start-storybook -p 6006 -c .storybook');5{6 "scripts": {7 },8 "dependencies": {9 },10 "devDependencies": {11 }12}

Full Screen

Using AI Code Generation

copy

Full Screen

1const {writePackageJson} = require('@storybook/root');2const fs = require('fs');3const path = require('path');4const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json')));5const newPackageJson = writePackageJson(packageJson, {6 scripts: {7 },8 devDependencies: {9 }10});11fs.writeFileSync(path.join(__dirname, 'package.json'), JSON.stringify(newPackageJson, null, 2));12{13 "scripts": {14 },15 "devDependencies": {16 }17}18module.exports = {19 webpackFinal: async (config) => {20 config.module.rules.push({21 test: /\.(ts|tsx)$/,22 {23 loader: require.resolve('ts-loader'),24 },25 {26 loader: require.resolve('react-docgen-typescript-loader'),27 },28 });29 config.resolve.extensions.push('.ts', '.tsx');30 return config;31 },32};33import React from 'react';34import

Full Screen

Using AI Code Generation

copy

Full Screen

1const { writePackageJson } = require('@storybook/root');2const { join } = require('path');3const fs = require('fs');4const root = join(__dirname, '..');5writePackageJson(root, { version: '1.0.0' }).then(() => {6 console.log('package.json updated');7 const packageJson = require(join(root, 'package.json'));8});9{10 "dependencies": {11 }12}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { writePackageJson } from "storybook-root-alias";2writePackageJson();3{4 "scripts": {5 },6 "dependencies": {7 }8}9{10 "scripts": {11 },12 "dependencies": {13 }14}15import { writePackageJson } from "storybook-root-alias";16writePackageJson();17{

Full Screen

Using AI Code Generation

copy

Full Screen

1const writePackageJson = require('@storybook/root/lib/writePackageJson')2writePackageJson('test', 'test', 'test', 'test', 'test');3const writePackageJson = require('@storybook/root/lib/writePackageJson')4writePackageJson('test', 'test', 'test', 'test', 'test');5const writePackageJson = require('@storybook/root/lib/writePackageJson')6writePackageJson('test', 'test', 'test', 'test', 'test');7const writePackageJson = require('@storybook/root/lib/writePackageJson')8writePackageJson('test', 'test', 'test', 'test', 'test');9const writePackageJson = require('@storybook/root/lib/writePackageJson')10writePackageJson('test', 'test', 'test', 'test', 'test');11const writePackageJson = require('@storybook/root/lib/writePackageJson')12writePackageJson('test', 'test', 'test', 'test', 'test');13const writePackageJson = require('@storybook/root/lib/writePackageJson')14writePackageJson('test', 'test', 'test', 'test', 'test');15const writePackageJson = require('@storybook/root/lib/writePackageJson')16writePackageJson('test', 'test', 'test', 'test', 'test');17const writePackageJson = require('@storybook/root/lib/writePackageJson')18writePackageJson('test', 'test', 'test', 'test', 'test');19const writePackageJson = require('@storybook/root/lib/writePackageJson')20writePackageJson('test', 'test', 'test', 'test', 'test');21const writePackageJson = require('@storybook/root/lib/writePackageJson')22writePackageJson('test', 'test', 'test', 'test', 'test');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { writePackageJson } from 'storybook-root';2writePackageJson();3{4 "scripts": {5 },6 "dependencies": {7 }8}9module.exports = {10};11import React from 'react';12import { addDecorator } from '@storybook/react';13import { ThemeProvider } from 'styled-components';14import { GlobalStyle } from '../src/styles/globalStyle';15import { theme } from '../src/styles/theme';16addDecorator((storyFn) => (17 <ThemeProvider theme={theme}>18 {storyFn()}19));20const path = require('path');21module.exports = {22 resolve: {23 alias: {24 '@': path.resolve(__dirname, '../src/'),25 },26 },27};28import { addons } from '@storybook/addons';29import { create } from '@storybook/theming';30addons.setConfig({31 theme: create({

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful