How to use packageVersion method in storybook-root

Best JavaScript code snippet using storybook-root

package-version-parser-tests.js

Source:package-version-parser-tests.js Github

copy

Full Screen

1var currentTest = null;2Tinytest.add("package-version-parser - validatePackageName", function (test) {3 var badName = function (packageName, messageExpect) {4 test.throws(function () {5 try {6 PackageVersion.validatePackageName(packageName);7 } catch (e) {8 if (! e.versionParserError) {9 test.fail(e.message);10 }11 throw e;12 }13 }, messageExpect);14 };15 PackageVersion.validatePackageName('a');16 PackageVersion.validatePackageName('a-b');17 PackageVersion.validatePackageName('a.b');18 badName("$foo", /can only contain/);19 badName("", /must contain a lowercase/);20 badName("foo$bar", /can only contain/);21 badName("Foo", /can only contain/);22 badName("a b", /can only contain/);23 badName(".foo", /may not begin with a dot/);24 badName("foo.", /may not end with a dot/);25 badName("foo..bar", /not contain two consecutive dots/);26 badName("-x", /not begin with a hyphen/);27 badName("--x", /not begin with a hyphen/);28 badName("0.0", /must contain/);29 badName(":a", /start or end with a colon/);30 badName("a:", /start or end with a colon/);31 // these are ok32 PackageVersion.validatePackageName('x-');33 PackageVersion.validatePackageName('x--y');34 PackageVersion.validatePackageName('x--');35});36Tinytest.add("package-version-parser - parse", function (test) {37 test.isTrue(new PackageVersion("1.2.3") instanceof PackageVersion);38 var throws = function (v, re) {39 test.throws(function () {40 new PackageVersion(v);41 }, re);42 };43 var formatPV = function (pv) {44 pv = JSON.parse(JSON.stringify(pv));45 delete pv._semverParsed;46 return (JSON.stringify(pv)47 .replace(/,(?="prerelease"|"raw")/g, ',\n')48 .replace(/,/g, ', ')49 .replace(/"(\w+)":/g, '$1: ')50 .replace("{", "{\n")51 .replace("}", "\n}"));52 };53 var equal = function (pv1, pv2) {54 test.equal(formatPV(pv1), formatPV(pv2));55 };56 equal(new PackageVersion("1.2.3-rc.5_1+12345"), {57 major: 1, minor: 2, patch: 3,58 prerelease: ["rc", 5], wrapNum: 1, build: ["12345"],59 raw: "1.2.3-rc.5_1+12345", version: "1.2.3-rc.5_1",60 semver: "1.2.3-rc.5+12345"61 });62 equal(PackageVersion.parse("1.2.3-rc.5_1+12345"), {63 major: 1, minor: 2, patch: 3,64 prerelease: ["rc", 5], wrapNum: 1, build: ["12345"],65 raw: "1.2.3-rc.5_1+12345", version: "1.2.3-rc.5_1",66 semver: "1.2.3-rc.5+12345"67 });68 equal(new PackageVersion("1.2.3"), {69 major: 1, minor: 2, patch: 3,70 prerelease: [], wrapNum: 0, build: [],71 raw: "1.2.3", version: "1.2.3", semver: "1.2.3"72 });73 throws("1.2", /must look like semver/);74 throws("1", /must look like semver/);75 equal(new PackageVersion("1.0.0-rc.1"), {76 major: 1, minor: 0, patch: 0,77 prerelease: ["rc", 1], wrapNum: 0, build: [],78 raw: "1.0.0-rc.1", version: "1.0.0-rc.1", semver: "1.0.0-rc.1"79 });80 throws("1.0.0-.", /must look like semver/);81 throws("1.0.0-rc.", /must look like semver/);82 throws("1.0.0-01", /must look like semver/);83 equal(new PackageVersion("1.2.3-1-1"), {84 major: 1, minor: 2, patch: 3,85 prerelease: ["1-1"], wrapNum: 0, build: [],86 raw: "1.2.3-1-1", version: "1.2.3-1-1", semver: "1.2.3-1-1"87 });88 equal(new PackageVersion("1.2.3_4"), {89 major: 1, minor: 2, patch: 3,90 prerelease: [], wrapNum: 4, build: [],91 raw: "1.2.3_4", version: "1.2.3_4", semver: "1.2.3"92 });93 throws("1.2.3_4_5", /have two _/);94 throws("1.2.3_0", /must not have a leading zero/);95 throws("1.2.3_01", /must not have a leading zero/);96 throws("1.2.3_a", /must contain only digits/);97 // (prerelease must go *before* the wrap num)98 throws("1.2.3_a-rc.1", /must contain only digits/);99 equal(new PackageVersion("1.2.3-4_5"), {100 major: 1, minor: 2, patch: 3,101 prerelease: [4], wrapNum: 5, build: [],102 raw: "1.2.3-4_5", version: "1.2.3-4_5", semver: "1.2.3-4"103 });104 equal(new PackageVersion("1.2.3-rc.1_7+8.9-10.c"), {105 major: 1, minor: 2, patch: 3,106 prerelease: ["rc", 1], wrapNum: 7, build: ["8", "9-10", "c"],107 raw: "1.2.3-rc.1_7+8.9-10.c", version: "1.2.3-rc.1_7",108 semver: "1.2.3-rc.1+8.9-10.c"109 });110 throws("1.2.3+4+5", /have two \+/);111 equal(new PackageVersion("1.2.3+x"), {112 major: 1, minor: 2, patch: 3,113 prerelease: [], wrapNum: 0, build: ["x"],114 raw: "1.2.3+x", version: "1.2.3", semver: "1.2.3+x"115 });116 throws("1.2.3+x_1", /must look like semver/);117 equal(new PackageVersion("1.2.3_1+x"), {118 major: 1, minor: 2, patch: 3,119 prerelease: [], wrapNum: 1, build: ["x"],120 raw: "1.2.3_1+x", version: "1.2.3_1", semver: "1.2.3+x"121 });122 throws("v1.0.0", /must look like semver/);123});124Tinytest.add("package-version-parser - constraints - parsePackageConstraint", function (test) {125 test.isTrue(PackageVersion.parsePackageConstraint("foo") instanceof126 PackageVersion.PackageConstraint);127 test.equal(PackageVersion.parsePackageConstraint("foo@1.2.3"),128 { package: "foo", constraintString: "1.2.3",129 versionConstraint: {130 raw: "1.2.3",131 alternatives: [{type: "compatible-with",132 versionString: "1.2.3"}] } });133 test.equal(PackageVersion.parsePackageConstraint("foo"),134 { package: "foo", constraintString: "",135 versionConstraint: {136 raw: "",137 alternatives: [{type: "any-reasonable",138 versionString: null}] } });139 test.equal(PackageVersion.parsePackageConstraint("foo@1.0.0 || =2.0.0"),140 { package: "foo", constraintString: "1.0.0 || =2.0.0",141 versionConstraint: {142 raw: "1.0.0 || =2.0.0",143 alternatives: [{type: "compatible-with",144 versionString: "1.0.0"},145 {type: "exactly",146 versionString: "2.0.0"}] } });147 test.equal(new PackageVersion.PackageConstraint("foo@1.0.0 || =2.0.0"),148 PackageVersion.parsePackageConstraint("foo@1.0.0 || =2.0.0"));149 test.equal(PackageVersion.parsePackageConstraint("foo", null),150 PackageVersion.parsePackageConstraint("foo"));151 test.equal(PackageVersion.parsePackageConstraint("foo", ""),152 PackageVersion.parsePackageConstraint("foo"));153 test.equal(PackageVersion.parsePackageConstraint("foo", "1.0.0"),154 PackageVersion.parsePackageConstraint("foo@1.0.0"));155 test.equal(PackageVersion.parsePackageConstraint("foo", "=1.0.0"),156 PackageVersion.parsePackageConstraint("foo@=1.0.0"));157 test.throws(function () {158 PackageVersion.parsePackageConstraint("", "1.0.0");159 });160 test.throws(function () {161 PackageVersion.parsePackageConstraint("foo@1.0.0", "1.0.0");162 });163 test.throws(function () {164 PackageVersion.parsePackageConstraint("foo@", "1.0.0");165 });166 test.throws(function () {167 PackageVersion.parsePackageConstraint("foo@");168 }, /leave off the @/);169 test.throws(function () {170 PackageVersion.parsePackageConstraint("foo@", "");171 });172 test.throws(function () {173 PackageVersion.parsePackageConstraint("a@b@c");174 });175 test.throws(function () {176 PackageVersion.parsePackageConstraint("foo@||");177 }, /Invalid constraint string: \|\|/);178 test.throws(function () {179 PackageVersion.parsePackageConstraint("foo@=||=");180 }, /Empty string is not a valid version/);181 test.equal(new PackageVersion.PackageConstraint(182 "foo", new PackageVersion.VersionConstraint(null)),183 { package: "foo", constraintString: "",184 versionConstraint: {185 raw: "",186 alternatives: [{type: "any-reasonable",187 versionString: null}] } });188 test.equal(PackageVersion.parsePackageConstraint(189 "foo", PackageVersion.parseVersionConstraint("1.0.0 || =2.0.0")),190 { package: "foo", constraintString: "1.0.0 || =2.0.0",191 versionConstraint: {192 raw: "1.0.0 || =2.0.0",193 alternatives: [{type: "compatible-with",194 versionString: "1.0.0"},195 {type: "exactly",196 versionString: "2.0.0"}] } });197 test.equal(PackageVersion.parseVersionConstraint(null),198 {raw: "", alternatives: [{type: "any-reasonable",199 versionString: null}]});200 test.equal(PackageVersion.parseVersionConstraint(""),201 {raw: "", alternatives: [{type: "any-reasonable",202 versionString: null}]});203 test.equal(PackageVersion.parsePackageConstraint("foo").toString(),204 "foo");205 test.equal(PackageVersion.parsePackageConstraint("foo", null).toString(),206 "foo");207 test.equal(PackageVersion.parsePackageConstraint("foo@1.0.0").toString(),208 "foo@1.0.0");209 test.equal(PackageVersion.parsePackageConstraint(210 "foo@=1.0.0 || 2.0.0").toString(), "foo@=1.0.0 || 2.0.0");211});212var t = function (pConstraintString, expected, descr) {213 var constraintString = pConstraintString.replace(/^.*?(@|$)/, '');214 var versionConstraint = {215 raw: constraintString,216 alternatives: expected.alternatives217 };218 currentTest.equal(219 PackageVersion.parsePackageConstraint(pConstraintString),220 {221 package: expected.package,222 constraintString: constraintString,223 versionConstraint: {224 raw: constraintString,225 alternatives: expected.alternatives226 }227 },228 descr);229};230var FAIL = function (versionString, errorExpect) {231 currentTest.throws(function () {232 PackageVersion.parsePackageConstraint(versionString);233 }, errorExpect);234};235Tinytest.add("package-version-parser - constraints - any-reasonable", function (test) {236 currentTest = test;237 t("foo", { package: "foo", alternatives: [{238 versionString: null, type: "any-reasonable" } ]});239 t("foo-1234", { package: "foo-1234", alternatives: [{240 versionString: null, type: "any-reasonable" } ]});241 FAIL("bad_name");242});243Tinytest.add("package-version-parser - constraints - compatible version, compatible-with", function (test) {244 currentTest = test;245 t("foo@1.2.3", { package: "foo", alternatives: [{246 versionString: "1.2.3", type: "compatible-with" } ]});247 t("foo-1233@1.2.3", { package: "foo-1233", alternatives: [{248 versionString: "1.2.3", type: "compatible-with" } ]});249 t("foo-bar@3.2.1", { package: "foo-bar", alternatives: [{250 versionString: "3.2.1", type: "compatible-with" } ]});251 FAIL("42@0.2.0");252 FAIL("foo@1.2.3.4");253 FAIL("foo@1.4");254 FAIL("foo@1");255 FAIL("foo@");256 FAIL("foo@@");257 FAIL("foo@x.y.z");258 FAIL("foo@<1.2");259 FAIL("foo<1.2");260 FAIL("foo@1.2.3_abc");261 FAIL("foo@1.2.3+1234_1");262 FAIL("foo@1.2.3_1-rc1");263 FAIL("foo-1233@1.2.3_0", /must not have a leading zero/);264 FAIL("foo-1233@1.2.3_a", /must contain only digits/);265 FAIL("foo-1233@1.2.3_", /wrap number must follow/);266 FAIL("foo-1233@1.2.3_0123");267 t("foo@1.2.3_1", { package: "foo", alternatives: [{268 versionString: "1.2.3_1", type: "compatible-with" } ]});269 t("foo-bar@3.2.1-rc0_123", { package: "foo-bar", alternatives: [{270 versionString: "3.2.1-rc0_123", type: "compatible-with" } ]});271 t("foo-1233@1.2.3_5+1234", { package: "foo-1233", alternatives: [{272 versionString: "1.2.3_5+1234", type: "compatible-with" } ]});273 t("foo", { package: "foo", alternatives: [{274 versionString: null, type: "any-reasonable" } ]});275});276Tinytest.add("package-version-parser - constraints - compatible version, exactly", function (test) {277 currentTest = test;278 t("foo@=1.2.3", { package: "foo", alternatives: [279 { versionString: "1.2.3", type: "exactly" } ]});280 t("foo-bar@=3.2.1", { package: "foo-bar", alternatives: [{281 versionString: "3.2.1", type: "exactly" } ]});282 t("foo@=1.2.3_1", { package: "foo", alternatives: [{283 versionString: "1.2.3_1", type: "exactly" } ]});284 t("foo-bar@=3.2.1_34", { package: "foo-bar", alternatives: [{285 versionString: "3.2.1_34", type: "exactly" } ]});286 FAIL("42@=0.2.0");287 FAIL("foo@=1.2.3.4");288 FAIL("foo@=1.4");289 FAIL("foo@=1");290 FAIL("foo@@=");291 FAIL("foo@=@");292 FAIL("foo@=x.y.z");293 FAIL("foo@=<1.2");294 FAIL("foo@<=1.2");295 FAIL("foo<=1.2");296 FAIL("foo@=1.2.3_rc0");297 // We no longer support @>=.298 FAIL("foo@>=1.2.3");299 FAIL("foo-bar@>=3.2.1");300 FAIL("42@>=0.2.0");301 FAIL("foo@>=1.2.3.4");302 FAIL("foo@>=1.4");303 FAIL("foo@>=1");304 FAIL("foo@@>=");305 FAIL("foo@>=@");306 FAIL("foo@>=x.y.z");307 FAIL("foo@=>12.3.11");308});309Tinytest.add("package-version-parser - constraints - or", function (test) {310 currentTest = test;311 t("foo@1.0.0 || 2.0.0 || 3.0.0 || =4.0.0-rc1",312 { package: "foo", alternatives:313 [{ versionString: "1.0.0", type: "compatible-with"},314 { versionString: "2.0.0", type: "compatible-with"},315 { versionString: "3.0.0", type: "compatible-with"},316 { versionString: "4.0.0-rc1", type: "exactly"}]317 });318 t("foo@1.0.0|| 2.0.0||3.0.0 || =4.0.0-rc1",319 { package: "foo", alternatives:320 [{ versionString: "1.0.0", type: "compatible-with"},321 { versionString: "2.0.0", type: "compatible-with"},322 { versionString: "3.0.0", type: "compatible-with"},323 { versionString: "4.0.0-rc1", type: "exactly"}]324 });325 t("foo-bar@=3.2.1 || 1.0.0",326 { package: "foo-bar", alternatives:327 [{ versionString: "3.2.1", type: "exactly"},328 { versionString: "1.0.0", type: "compatible-with"}]329 });330 t("foo@=1.2.3_1 || 1.2.4",331 { package: "foo", alternatives:332 [{ versionString: "1.2.3_1", type: "exactly"},333 { versionString: "1.2.4", type: "compatible-with"}]334 });335 t("foo-bar@=3.2.1_34 || =3.2.1-rc1",336 { package: "foo-bar", alternatives:337 [{ versionString: "3.2.1_34", type: "exactly"},338 { versionString: "3.2.1-rc1", type: "exactly"}]339 });340 FAIL("foo@1.0.0 1.0.0");341 FAIL("foo@1.0.0 | 1.0.0");342 FAIL("foo || bar");343 FAIL("foo@1.0.0-rc|1.0.0");344 // This is the current implementation, but is arguably not great.345 FAIL("foo@1.0.0 "); // trailing space346});347Tinytest.add(348 "package-version-parser - less than, compare, version magnitude",349 function (test) {350 var compare = function (v1, v2, expected) {351 if (expected === '<') {352 test.isTrue(PackageVersion.lessThan(v1, v2));353 test.isTrue(PackageVersion.versionMagnitude(v1) < PackageVersion.versionMagnitude(v2));354 test.isTrue(PackageVersion.compare(v1, v2) < 0);355 } else if (expected === '=') {356 test.isFalse(PackageVersion.lessThan(v1, v2));357 test.isFalse(PackageVersion.lessThan(v2, v1));358 test.isTrue(PackageVersion.versionMagnitude(v1) === PackageVersion.versionMagnitude(v2));359 test.isTrue(PackageVersion.compare(v1, v2) === 0);360 } else if (expected === '>') {361 test.isTrue(PackageVersion.lessThan(v2, v1));362 test.isTrue(PackageVersion.versionMagnitude(v1) > PackageVersion.versionMagnitude(v2));363 test.isTrue(PackageVersion.compare(v1, v2) > 0);364 } else {365 throw new Error("expected should be '<', '=' or '>'");366 }367 };368 compare("1.0.0", "1.2.0", "<");369 compare("1.0.0_50", "1.0.1", "<");370 compare("1.0.0_50", "1.2.0", "<");371 compare("1.0.0_1", "1.0.0_2", "<");372 compare("1.0.0_2", "1.0.0_10", "<"); // verify that we compare _N "wrap numbers" as numbers, not strings373 compare("1.0.0", "1.0.0_2", "<");374 compare("1.99.0_99", "3.0.0_2", "<");375 compare("1.99.0", "2.0.0", "<");376 compare("1.0.0_5", "1.0.0_2", ">");377 compare("1.0.0_99", "1.2.0", "<");378 compare("1.0.0_99", "1.0.1", "<");379 compare("1.0.0_1", "1.0.0_2", "<");380 compare("1.0.0", "1.0.0_2", "<");381 compare("1.99.0_99", "3.0.0_2", "<");382 compare("1.0.0_5", "1.0.0_2", ">");383 compare("1.0.0", "1.0.0", "=");384 compare("1.0.0_5", "1.0.0_5", "=");385 compare("1.2.0", "1.0.0", ">");386 compare("1.0.1", "1.0.0_5", ">");387 // Rule 11 from http://semver.org388 compare("0.99.99", "1.0.0-alpha.1", "<");389 compare("1.0.0-alpha", "1.0.0-alpha.1", "<");390 compare("1.0.0-alpha.1", "1.0.0-alpha.beta", "<");391 compare("1.0.0-alpha.beta", "1.0.0-beta", "<");392 compare("1.0.0-beta", "1.0.0-beta.2", "<");393 compare("1.0.0-beta.2", "1.0.0-beta.11", "<");394 compare("1.0.0-beta.11", "1.0.0-rc.1", "<");395 compare("1.0.0-rc.1", "1.0.0", "<");396 // dashes are allowed in prerelease parts397 compare("1.0.0--alpha", "1.0.0-alpha", "<");398 compare("1.0.0-a-lpha", "1.0.0-alpha", "<");399 // test single character prerelease parts400 compare("1.0.0-r.1", "1.0.0", "<");401 // test the edges of `versionMagnitude`402 compare("1.0.0-zzzzzzzzzzzz", "1.0.0", "<");403 // prerelease parts can contain digits and non-digits404 compare("1.0.0-r1", "1.0.0-rc", "<");405 // Our broken implementation of Rule 11 (see [*] above the406 // declaration of PackageVersion.versionMagnitude). Maybe one day407 // we'll fix it, in which case replace "===" with ">"408 test.isTrue(PackageVersion.versionMagnitude("1.0.0-beta.0") ===409 PackageVersion.versionMagnitude("1.0.0-bear.0"));410 });411Tinytest.add("package-version-parser - Invalid in 0.9.2", function (test) {412 // Note that invalidFirstFormatConstraint assumes that the initial version413 // passed in has been previously checked to be valid in 0.9.3.414 // These are invalid in 0.9.2, but valid in 0.9.3 and above.415 var invalidVersions =416 ["1.0.0_1", "1.0.0 || 2.0.0", "1.0.0-rc1_1",417 "3.4.0-rc1 || =1.0.0"];418 _.each(invalidVersions, function (v) {419 test.isTrue(PackageVersion.invalidFirstFormatConstraint(v));420 });421 // These are all valid in 0.9.2.422 var validVersions =423 ["1.0.0", "2.0.0-rc1", "=2.5.0"];424 _.each(validVersions, function (v) {425 test.isFalse(PackageVersion.invalidFirstFormatConstraint(v));426 });427});428Tinytest.add("package-version-parser - sort", function (test) {429 var versions = ["1.0.0", "1.0.0-rc.0", "1.0.10", "1.0.2"];430 versions.sort(PackageVersion.compare);431 test.equal(versions, ["1.0.0-rc.0", "1.0.0", "1.0.2", "1.0.10"]);...

Full Screen

Full Screen

PackageVersion.js

Source:PackageVersion.js Github

copy

Full Screen

1/**2 * PackageVersion.js3 *4 * @description :: TODO: You might write a short summary of how this model works and what it represents here.5 * @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models6 */7var Promise = require('bluebird');8var dateFormat = require('dateformat');9var _ = require('lodash');10module.exports = {11 attributes: {12 package_name: {13 type: Sequelize.STRING,14 allowNull: false15 },16 version: {17 type: Sequelize.STRING,18 allowNull: false19 },20 title: {21 type: Sequelize.TEXT22 },23 description: {24 type: Sequelize.TEXT,25 allowNull: false26 },27 release_date: {28 type: Sequelize.DATE,29 allowNull: true30 },31 license: {32 type: Sequelize.TEXT,33 allowNull: false34 },35 url: {36 type: Sequelize.TEXT,37 },38 copyright: {39 type: Sequelize.TEXT40 },41 readmemd: {42 type: Sequelize.TEXT,43 allowNull: true44 },45 sourceJSON: {46 type: Sequelize.TEXT,47 allowNull: true48 }49 },50 associations: function() {51 PackageVersion.belongsTo(Package,52 {53 as: 'package',54 foreignKey: {55 allowNull: false,56 name:'package_name',57 as: 'package'58 },59 onDelete: 'CASCADE'60 });61 PackageVersion.hasOne(Package, {as: 'package_latest', foreignKey : 'latest_version_id'});62 PackageVersion.belongsToMany(Package,63 { as: 'dependencies',64 through: Dependency,65 foreignKey: {66 name: 'dependant_version_id',67 as: 'dependencies'68 }69 });70 PackageVersion.belongsTo(Collaborator,71 {72 as: 'maintainer',73 foreignKey: {74 allowNull: true,75 name: 'maintainer_id',76 as: 'maintainer'77 }78 });79 PackageVersion.belongsToMany(Collaborator, {as: 'collaborators', through: 'Collaborations', foreignKey: 'authored_version_id', timestamps: false});80 PackageVersion.hasMany(Topic, {as: 'topics', foreignKey: 'package_version_id'});81 PackageVersion.hasMany(Review, {82 as: 'reviews',83 foreignKey: 'reviewable_id',84 constraints: false,85 scope: {86 reviewable: 'version'87 }88 });89 },90 options: {91 indexes: [92 {93 type: 'UNIQUE',94 fields: ['package_name', 'version']95 }96 ],97 getterMethods: {98 uri: function() {99 return sails.getUrlFor({ target: 'PackageVersion.findByNameVersion' })100 .replace(':name', encodeURIComponent(this.getDataValue('package_name')))101 .replace(':version', encodeURIComponent(this.getDataValue('version')))102 .replace('/api/', '/');103 },104 api_uri: function() {105 return sails.getUrlFor({ target: 'PackageVersion.findByNameVersion' })106 .replace(':name', encodeURIComponent(this.getDataValue('package_name')))107 .replace(':version', encodeURIComponent(this.getDataValue('version')));108 },109 canonicalLink: function() {110 if(!this.package) return null;111 if(!this.package.versions) return null;112 this.package.versions.sort(PackageService.compareVersions('desc', 'version'));113 return sails.getUrlFor({ target: 'PackageVersion.findByNameVersion' })114 .replace(':name', encodeURIComponent(this.getDataValue('package_name')))115 .replace(':version', encodeURIComponent(this.package.versions[0].version))116 .replace('/api/', '/');117 }118 },119 classMethods: {120 getLatestVersion:function(packageName){121 return PackageVersion.findAll({122 where:{package_name:packageName}123 }).then(function (versions) {124 if (versions && versions.length > 0)125 return versions.sort(PackageService.compareVersions('desc', 'version'))[0];126 else return null;127 });128 },129 getAllVersions: function(){130 return PackageVersion.findAll();131 },132 upsertPackageVersion: function(packageVersion, opts) {133 var options = _.defaults(_.clone(opts), { where: {name: packageVersion.package_name} });134 return Package.findOrCreate(options).spread(function(instance, created) {135 var options = _.defaults(_.clone(opts), {136 where: {137 package_name: packageVersion.package_name,138 version: packageVersion.version139 },140 defaults: packageVersion,141 });142 return PackageVersion.findOrCreate(options);143 });144 },145 getPackageVersionFromCondition:function(conditions){146 var packagePromise = PackageVersion.findOne({147 where: conditions,148 include: [149 { model: Collaborator, as: 'maintainer' },150 { model: Package, as: 'package', include: [151 { model: PackageVersion, as: 'versions', attributes:['package_name', 'version'], separate: true },152 { model: Star, as: 'stars', attributes: ['package_name', 'user_id' ] }153 ],154 attributes: { include: [[sequelize.fn('COUNT', sequelize.col('package.stars.user_id')), 'star_count']] },155 },156 { model: Topic, as: 'topics',157 attributes: ['package_version_id', 'name', 'title', 'id'],158 separate: true }159 ]160 })161 var collaboratorsPromise = Collaborator.findAll({162 include: [163 { model: PackageVersion, as: 'authored_packages', required: true, where: conditions }164 ]165 });166 var dependencyPromise = Dependency.findAll({167 include: [168 { model: PackageVersion, as: 'dependant', required: true, attributes: ['package_name', 'version'], where: conditions }169 ],170 });171 var prefix = "rpackages/unarchived/" + conditions.package_name + "/" + conditions.version + "/" + "vignettes/";172 var s3Promise = s3Service.getAllFilesInFolder(prefix, true);173 // s3 can throw an exception `The difference between the request time and the current time is too large.`174 // This can happen when your pc with a running docker installation went into sleep mode175 // Restarting docker resolves this problem.176 return Promise.join(packagePromise, collaboratorsPromise, dependencyPromise, s3Promise,177 function(versionInstance, collaboratorsInstances, dependencyInstances, s3Data) {178 if(versionInstance === null || versionInstance.package === null) return null;179 const versionJSON = versionInstance.toJSON()180 versionJSON.collaborators = collaboratorsInstances.map(function(x) { return x.toJSON(); });181 versionJSON.dependencies = dependencyInstances.map(function(x) { return x.toJSON(); });182 versionJSON.package.versions = versionJSON.package.versions.sort(PackageService.compareVersions('desc', 'version'));183 versionJSON.vignettes = [];184 versionJSON.vignettes = s3Data.list.map(function(item){185 var splited = item.Key.split('/');186 var url = 'https://s3.amazonaws.com/assets.rdocumentation.org/' + item.Key;187 var name = item.Key.substring(prefix.length, item.Key.length);188 if(name.match("(.Rmd)$") !== null)189 url = process.env.BASE_URL + "/packages/" + conditions.package_name190 + "/versions/" + conditions.version + "/vignettes/" + name;191 return {192 'name': name,193 'url': url194 }195 });196 return versionJSON;197 })198 .catch(function(err){199 console.log(err.message);200 });201 },202 createWithDescriptionFile: function(opts) {203 var description = opts.input;204 var type = description.repoType || 'cran';205 var readmemd = description.readme;206 var packageVersion = PackageService.mapDescriptionToPackageVersion(description);207 packageVersion.fields.sourceJSON = JSON.stringify(description);208 packageVersion.fields.readmemd = readmemd;209 packageVersion.fields.license = packageVersion.fields.license || "";210 return sequelize.transaction(function (t) {211 var _package = Repository.findOrCreate({212 where: {name: type},213 transaction: t214 }).spread(function(repoInstance, created){215 return Package.upsert({216 name: packageVersion.package.name,217 type_id: repoInstance.id218 }, {219 transaction: t220 });221 });222 var dependencies = Package.bulkCreate(packageVersion.dependencies.map(function(dependency) {223 return {name: dependency.dependency_name};224 }), {225 transaction: t,226 fields: ['name'],227 ignoreDuplicates: true228 });229 return Promise.join(_package, dependencies,230 function(packageInstance) {231 return PackageVersion.findOrInitialize(232 {233 where: {234 package_name: packageVersion.package.name,235 version: packageVersion.fields.version236 },237 transaction: t238 }).spread(function(packageVersionInstance, initialized) {239 packageVersionInstance.set(packageVersion.fields);240 packageVersionInstance.setPackage(packageVersion.package.name, {save: false});241 return packageVersionInstance.save({transaction: t});242 }).then(function(packageVersionInstance) {243 var dependencies = packageVersion.dependencies.map(function(dependency) {244 return _.merge(dependency, {dependant_version_id: packageVersionInstance.id});245 });246 var dep = Dependency.bulkCreate(dependencies, {247 ignoreDuplicates: true,248 transaction: t249 });250 return Promise.join(dep, Collaborator.replaceAllAuthors(packageVersion.authors, packageVersionInstance, {transaction:t}),251 function(dependencies, authors) {252 return PackageVersion.findAll({253 where: {254 package_name: packageVersion.package.name255 },256 transaction: t257 })258 .then(function(versionInstances) {259 return versionInstances.sort(PackageService.compareVersions('desc', function(version) {260 return version.version261 }));262 })263 .then(function(versionInstances) {264 return Package.update({265 latest_version_id: versionInstances[0].id266 },267 {268 where: { name: packageVersion.package.name },269 transaction: t270 }271 ).then(function() {272 return PackageVersion.update({273 updated_at: null274 }, {275 where: {276 id: { $in: versionInstances.map(function(v) {277 return v.id;278 })}279 },280 transaction: t281 });282 }).then(function(count) {283 return packageVersionInstance;284 });285 });286 });287 });288 });289 });290 },291 getPackagesByDate: function(page, dateExpression) {292 return sequelize.query("SELECT package_name, " + dateExpression + " as rel FROM PackageVersions where release_date < now() group by package_name order by rel Desc Limit :offset,10",293 {replacements: { offset: (page-1)*10 }, type: sequelize.QueryTypes.SELECT })294 .then(function(records) {295 return records.map(function(record) {296 record.rel = dateFormat(record.rel);297 return record;298 });299 });300 },301 getNewestPackages: function(page) {302 return PackageVersion.getPackagesByDate(page, "min(release_date)");303 },304 getLatestUpdates: function(page){305 return PackageVersion.getPackagesByDate(page, "max(release_date)");306 }307 },308 underscored: true309 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { packageVersion } = require('storybook-root');2console.log(packageVersion);3{4}5const { version } = require('../package.json');6module.exports = {7};8{9}

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2storybookRoot.packageVersion();3const storybookRoot = require('storybook-root');4storybookRoot.storybookRoot();5const storybookRoot = require('storybook-root');6storybookRoot.storybookRootDir();7const storybookRoot = require('storybook-root');8storybookRoot.storybookRootPath();9const storybookRoot = require('storybook-root');10storybookRoot.storybookRootPackage();11const storybookRoot = require('storybook-root');12storybookRoot.storybookRootPackageJson();13const storybookRoot = require('storybook-root');14storybookRoot.storybookRootPackageLock();15const storybookRoot = require('storybook-root');16storybookRoot.storybookRootPackageLockJson();17const storybookRoot = require('storybook-root');18storybookRoot.storybookRootPackageVersion();19const storybookRoot = require('storybook-root');20storybookRoot.storybookRootPackageVersion();21const storybookRoot = require('storybook-root');22storybookRoot.storybookRootPackageVersion();23const storybookRoot = require('storybook-root');24storybookRoot.storybookRootPackageVersion();25const storybookRoot = require('storybook-root');26storybookRoot.storybookRootPackageVersion();

Full Screen

Using AI Code Generation

copy

Full Screen

1console.log(require('storybook-root/package.json').version);2console.log(require('storybook/package.json').version);3console.log(require('storybook-root/package.json').version);4console.log(require('storybook/package.json').version);5{6}7console.log(require('storybook-root/package.json').version);8console.log(require('storybook/package.json').version);9console.log(require('storybook-root/package.json').version);10console.log(require('storybook/package.json').version);11{12}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { packageVersion } from 'storybook-root';2console.log(packageVersion());3console.log(packageVersion('react'));4console.log(packageVersion('react', '16.8.0'));5console.log(packageVersion('react', '16.8.0', '16.9.0'));6console.log(packageVersion('react', '16.8.0', '16.9.0', '16.10.0'));7console.log(packageVersion('react', '16.8.0', '16.9.0', '16.10.0', '16.11.0'));8console.log(packageVersion('react', '16.8.0', '16.9.0', '16.10.0', '16.11.0', '16.12.0'));9console.log(packageVersion('react', '16.8.0', '16.9.0', '16.10.0', '16.11.0', '16.12.0', '16.13.0'));10console.log(packageVersion('react', '16.8.0', '16.9.0', '16.10.0', '16.11.0', '16.12.0', '16.13.0', '16.14.0'));11console.log(packageVersion('react', '16.8.0', '16.9.0', '16.10.0', '16.11.0', '16.12.0', '16.13.0', '16.14.0', '16.15.0'));12console.log(packageVersion('react', '16.8.0', '16.9.0', '16.10.0', '16.11.0', '16

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2const version = storybookRoot.packageVersion();3console.log(`storybook-root package version: ${version}`);4const storybookRoot = require('storybook-root');5const version = storybookRoot.packageVersion();6console.log(`storybook-root package version: ${version}`);7const storybookRoot = require('storybook-root');8const version = storybookRoot.packageVersion();9console.log(`storybook-root package version: ${version}`);10const storybookRoot = require('storybook-root');11const version = storybookRoot.packageVersion();12console.log(`storybook-root package version: ${version}`);13const storybookRoot = require('storybook-root');14const version = storybookRoot.packageVersion();15console.log(`storybook-root package version: ${version}`);16const storybookRoot = require('storybook-root');17const version = storybookRoot.packageVersion();18console.log(`storybook-root package version: ${version}`);19const storybookRoot = require('storybook-root');

Full Screen

Using AI Code Generation

copy

Full Screen

1import {packageVersion} from 'storybook-root';2export default { title: 'Package Version' };3export const version = () => {4 const version = packageVersion();5 return `<div>${version}</div>`;6};7import {configure} from '@storybook/html';8import '../test.js';9configure(require.context('../', true, /\.js$/), module);10module.exports = {11 webpackFinal: async (config) => {12 config.module.rules.push({13 {14 options: {15 },16 },17 });18 return config;19 },20};21{22 "scripts": {23 },24 "devDependencies": {

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