Skip to content

Commit

Permalink
feat: add support for elements migration (#2)
Browse files Browse the repository at this point in the history
feat/add-elements-migration
  • Loading branch information
joshblack committed Jun 17, 2019
1 parent 9460859 commit 1b9fe43
Show file tree
Hide file tree
Showing 54 changed files with 1,365 additions and 199 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/upgrade/bin/carbon-upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (major < 8) {
process.exit(1);
}

var main = require('../src');
var main = require('../src/cli');

main(process).catch(error => {
console.error(error);
Expand Down
7 changes: 7 additions & 0 deletions packages/upgrade/fixtures/carbon-colors/a.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.selector {
color: $ibm-colors__blue--50;
}

.animated {
transition-timing-function: map-get($easings, productive);
}
4 changes: 3 additions & 1 deletion packages/upgrade/fixtures/carbon-colors/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"dependencies": {
"@carbon/colors": "0.0.1-alpha.27"
"@carbon/colors": "0.0.1-alpha.27",
"@carbon/motion": "0.0.1-alpha.27",
"carbon-components": "9.x"
}
}
8 changes: 6 additions & 2 deletions packages/upgrade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
},
"dependencies": {
"chalk": "^2.4.2",
"commander": "^2.19.0",
"fast-glob": "^2.2.6",
"fs-extra": "^7.0.1",
"inquirer": "^6.2.1"
"inquirer": "^6.2.1",
"jest-diff": "^23.6.0",
"lodash.clonedeep": "^4.5.0",
"semver": "^5.6.0",
"yargs": "^12.0.5"
},
"devDependencies": {
"@commitlint/cli": "^7.3.2",
Expand Down
21 changes: 21 additions & 0 deletions packages/upgrade/src/__mocks__/reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright IBM Corp. 2019, 2019
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

module.exports = {
reporter: {
error: jest.fn(),
header: jest.fn(),
info: jest.fn(),
log: jest.fn(),
setLogLevel: jest.fn(),
stack: jest.fn(),
success: jest.fn(),
verbose: jest.fn(),
},
};
101 changes: 101 additions & 0 deletions packages/upgrade/src/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Copyright IBM Corp. 2019, 2019
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const cli = require('yargs');
const packageJson = require('../package.json');
const { UpgradeError } = require('./error');
const { reporter } = require('./reporter');
const { run, runInDirectory } = require('./runner');

async function main({ argv, cwd }) {
cli.scriptName(packageJson.name).version(packageJson.version);

cli
.option('verbose', {
default: false,
describe: 'display the full output while running a command',
})
.option('dry', {
alias: 'd',
describe:
'view the result of running this command without changing any files',
default: false,
})
.option('ignore', {
alias: 'i',
describe: 'provide a glob pattern for directories you would like ignored',
default: '',
});

cli
.usage('Usage: $0 [options]')
.command('$0', 'run to upgrade your project', {}, async args => {
const { dry, ignore, verbose } = args;
const options = {
cwd: cwd(),
dry,
ignore,
verbose,
};

await runCommand(() => runInDirectory(options), options);
});

cli.command(
'migrate <package> <from> <to>',
'run a specific migration for a package',
{},
async args => {
const { dry, from, ignore, package: packageName, to, verbose } = args;
const options = {
cwd: cwd(),
dry,
ignore,
verbose,
};

await runCommand(() => run(packageName, from, to, options), options);
}
);

cli
.demandCommand()
.recommendCommands()
.strict()
.parse(argv.slice(2)).argv;
}

async function runCommand(makePromise, options) {
reporter.info('Thanks for trying out carbon-upgrade! 🙏');
reporter.info(
'To help prevent any accidental changes, make sure to check in your ' +
'work in version control first and use dry mode (-d flag) to ' +
'preview any updates!'
);

if (options.verbose) {
reporter.setLogLevel('verbose');
}

try {
const start = Date.now();
await makePromise();
console.log(`✨ Done in ${Date.now() - start}ms`);
} catch (error) {
if (error instanceof UpgradeError) {
reporter.error(error.message);
return;
}
reporter.error('Yikes, looks like something really went wrong.');
reporter.error('Please make an issue with the following info:');
console.log(error);
}
}

module.exports = main;
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment node
*/

'use strict';

test('should work', () => {
// ...
});
class UpgradeError extends Error {}

module.exports = {
UpgradeError,
};
50 changes: 0 additions & 50 deletions packages/upgrade/src/index.js

This file was deleted.

26 changes: 0 additions & 26 deletions packages/upgrade/src/migrations/carbon-colors/0.0.1-alpha.28.js

This file was deleted.

35 changes: 35 additions & 0 deletions packages/upgrade/src/migrations/carbon-colors/0.0.1-alpha.31.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright IBM Corp. 2019, 2019
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const { reporter } = require('../../reporter');
const { replace } = require('../../tools/replace');

const TARGET_VERSION = '0.0.1-alpha.31';

module.exports = {
version: TARGET_VERSION,
from: [
{
version: '<=0.0.1-alpha.30',
async migrate(options) {
const changes = [
{
from: /(\$ibm-colors__[a-z]+)(--)([\d]+)/gm,
// Capture group $1 refers to $ibm-colors__abcd
// $2 refers to double dash (--)
// $3 is the grade at the end
to: '$1-$3',
},
];

await replace('**/*.scss', changes, options);
},
},
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright IBM Corp. 2019, 2019
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment node
*/

'use strict';

const { defineInlineTest } = require('../../../tools/testing');

defineInlineTest(
require.resolve('../0.0.1-alpha.31.js'),
'0.0.1-alpha.30',
`
$ibm-colors__blue--50;
$ibm-colors__teal--50;
color: $ibm-colors__blue--50;
color: $ibm-colors__teal--50;
`,
`
$ibm-colors__blue-50;
$ibm-colors__teal-50;
color: $ibm-colors__blue-50;
color: $ibm-colors__teal-50;
`
);
2 changes: 1 addition & 1 deletion packages/upgrade/src/migrations/carbon-colors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'use strict';

const migrations = new Set([require('./0.0.1-alpha.28')]);
const migrations = new Set([require('./0.0.1-alpha.31')]);

module.exports = {
name: '@carbon/colors',
Expand Down
36 changes: 36 additions & 0 deletions packages/upgrade/src/migrations/carbon-elements/0.0.1-alpha.31.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright IBM Corp. 2019, 2019
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const { reporter } = require('../../reporter');
const colors = require('../carbon-colors/0.0.1-alpha.31');
const grid = require('../carbon-grid/0.0.1-alpha.31');
const layout = require('../carbon-layout/0.0.1-alpha.31');
const motion = require('../carbon-motion/0.0.1-alpha.31');

const TARGET_VERSION = '0.0.1-alpha.31';

module.exports = {
version: TARGET_VERSION,
from: [
{
version: '<=0.0.1-alpha.30',
async migrate(options) {
const migrations = [
...colors.from,
...grid.from,
...layout.from,
...motion.from,
].filter(({ version }) => version === '<=0.0.1-alpha.30');
await Promise.all(
migrations.map(migration => migration.migrate(options))
);
},
},
],
};
Loading

0 comments on commit 1b9fe43

Please sign in to comment.